#ifndef COMPILER_LEX_TABLE_H_ #define COMPILER_LEX_TABLE_H_ #include #include #include #include #include "compiler/rules/symbol.h" #include "compiler/rules/character_set.h" namespace tree_sitter { typedef enum { LexActionTypeError, LexActionTypeAccept, LexActionTypeAdvance } LexActionType; class LexAction { LexAction(LexActionType type, size_t state_index, rules::Symbol symbol, std::set precedence_values); public: LexAction(); static LexAction Accept(rules::Symbol symbol, int precedence); static LexAction Error(); static LexAction Advance(size_t state_index, std::set precedence_values); bool operator==(const LexAction &action) const; LexActionType type; rules::Symbol symbol; size_t state_index; std::set precedence_values; }; 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; LexAction default_action; std::set expected_inputs() const; bool is_token_start; }; typedef int64_t LexStateId; class LexTable { public: static const LexStateId ERROR_STATE_ID; LexStateId add_state(); LexState & state(LexStateId state_id); std::vector states; LexState error_state; }; } #endif // COMPILER_LEX_TABLE_H_