#ifndef COMPILER_PARSE_TABLE_H_ #define COMPILER_PARSE_TABLE_H_ #include #include #include #include #include "compiler/lex_table.h" #include "compiler/rules/symbol.h" #include "compiler/rules/metadata.h" #include "compiler/precedence_range.h" #include "compiler/syntax_grammar.h" namespace tree_sitter { typedef uint64_t ParseStateId; typedef enum { ParseActionTypeError, ParseActionTypeReduceExtra, ParseActionTypeShiftExtra, ParseActionTypeShift, ParseActionTypeReduce, ParseActionTypeAccept, } ParseActionType; class ParseAction { ParseAction(ParseActionType type, ParseStateId state_index, rules::Symbol symbol, size_t consumed_symbol_count, PrecedenceRange range, rules::Associativity, const Production *); public: ParseAction(); static ParseAction Accept(); static ParseAction Error(); static ParseAction Shift(ParseStateId state_index, PrecedenceRange precedence); static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count, int precedence, rules::Associativity, const Production &); static ParseAction ShiftExtra(); static ParseAction ReduceExtra(rules::Symbol symbol); bool operator==(const ParseAction &) const; bool operator<(const ParseAction &) const; ParseActionType type; rules::Symbol symbol; ParseStateId state_index; size_t consumed_symbol_count; PrecedenceRange precedence_range; rules::Associativity associativity; const Production *production; }; } // namespace tree_sitter 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) ^ hash()(action.associativity) ^ hash()(action.precedence_range.min) ^ hash()(action.precedence_range.max) ^ hash()(&action.production)); } }; } // namespace std namespace tree_sitter { class ParseState { public: ParseState(); std::map> actions; std::set expected_inputs() const; LexStateId lex_state_id; }; class ParseTable { public: ParseStateId add_state(); ParseAction &set_action(ParseStateId state_id, rules::Symbol symbol, ParseAction action); ParseAction &add_action(ParseStateId state_id, rules::Symbol symbol, ParseAction action); std::vector states; std::set symbols; std::set fragile_productions; }; } // namespace tree_sitter #endif // COMPILER_PARSE_TABLE_H_