#ifndef COMPILER_PARSE_TABLE_H_ #define COMPILER_PARSE_TABLE_H_ #include #include #include #include #include "compiler/lex_table.h" #include "compiler/rules/symbol.h" namespace tree_sitter { typedef enum { ParseActionTypeError, ParseActionTypeAccept, ParseActionTypeShift, ParseActionTypeReduce, } ParseActionType; class ParseAction { ParseAction(ParseActionType type, size_t state_index, rules::Symbol symbol, size_t consumed_symbol_count); public: static ParseAction Accept(); static ParseAction Error(); static ParseAction Shift(size_t state_index); static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count); bool operator==(const ParseAction &action) const; ParseActionType type; rules::Symbol symbol; size_t state_index; size_t consumed_symbol_count; }; std::ostream& operator<<(std::ostream &stream, const ParseAction &item); } namespace std { template<> struct hash { size_t operator()(const tree_sitter::ParseAction &action) const { return ( hash()(action.type) ^ hash()(action.symbol) ^ hash()(action.state_index) ^ hash()(action.consumed_symbol_count)); } }; } namespace tree_sitter { class ParseState { public: ParseState(); std::map actions; std::set expected_inputs() const; LexStateId lex_state_id; }; typedef uint64_t ParseStateId; std::ostream& operator<<(std::ostream &stream, const ParseState &state); class ParseTable { public: uint64_t add_state(); void add_action(ParseStateId state_id, rules::Symbol symbol, ParseAction action); std::vector states; std::set symbols; }; } #endif // COMPILER_PARSE_TABLE_H_