#ifndef __TreeSitter__lex_table__ #define __TreeSitter__lex_table__ #include #include #include #include #include "symbol.h" #include "character_set.h" namespace tree_sitter { typedef enum { LexActionTypeAccept, LexActionTypeError, LexActionTypeAdvance } LexActionType; class LexAction { LexAction(LexActionType type, size_t state_index, rules::Symbol symbol); public: static LexAction Accept(rules::Symbol symbol); static LexAction Error(); static LexAction Advance(size_t state_index); bool operator==(const LexAction &action) const; bool operator<(const LexAction &action) const; LexActionType type; rules::Symbol symbol; size_t state_index; }; std::ostream& operator<<(std::ostream &stream, const LexAction &item); } namespace std { template<> struct hash { size_t operator()(const tree_sitter::LexAction &action) const { return (hash()(action.type) ^ hash()(action.symbol) ^ hash()(action.state_index)); } }; } namespace tree_sitter { class LexState { public: std::map> actions; std::set default_actions; std::set expected_inputs() const; }; class LexTable { public: size_t add_state(); void add_action(size_t state_index, rules::CharacterSet rule, LexAction action); void add_default_action(size_t state_index, LexAction action); std::vector states; }; } #endif