Put definition of EOF symbol back in parse table builder (not in parser.h)
This commit is contained in:
parent
e58a6d8ba7
commit
4541332c2b
4 changed files with 265 additions and 245 deletions
|
|
@ -14,9 +14,10 @@ namespace tree_sitter {
|
|||
using rules::CharacterSet;
|
||||
|
||||
namespace build_tables {
|
||||
static int NOT_FOUND = -2;
|
||||
static Symbol START("start", rules::SymbolTypeAuxiliary);
|
||||
static Symbol END_OF_INPUT("end", rules::SymbolTypeAuxiliary);
|
||||
const int NOT_FOUND = -2;
|
||||
const Symbol START("start", rules::SymbolTypeAuxiliary);
|
||||
const Symbol END_OF_INPUT("end", rules::SymbolTypeAuxiliary);
|
||||
const LexItem EOF_ITEM(END_OF_INPUT, make_shared<CharacterSet>(std::set<rules::CharacterRange>{ '\0' }));
|
||||
|
||||
class TableBuilder {
|
||||
const PreparedGrammar grammar;
|
||||
|
|
@ -79,6 +80,8 @@ namespace tree_sitter {
|
|||
for (auto &symbol : state.expected_inputs()) {
|
||||
if (lex_grammar.has_definition(symbol))
|
||||
item_set.insert(LexItem(symbol, lex_grammar.rule(symbol)));
|
||||
else if (symbol == END_OF_INPUT)
|
||||
item_set.insert(EOF_ITEM);
|
||||
}
|
||||
|
||||
state.lex_state_id = add_lex_state(item_set);
|
||||
|
|
@ -112,6 +115,7 @@ namespace tree_sitter {
|
|||
LexItemSet error_item_set;
|
||||
for (auto &pair : lex_grammar.rules)
|
||||
error_item_set.insert(LexItem(pair.first, pair.second));
|
||||
error_item_set.insert(EOF_ITEM);
|
||||
add_advance_actions(error_item_set, LexTable::ERROR_STATE_ID);
|
||||
add_accept_token_actions(error_item_set, LexTable::ERROR_STATE_ID);
|
||||
}
|
||||
|
|
@ -138,7 +142,7 @@ namespace tree_sitter {
|
|||
lex_grammar(lex_grammar) {};
|
||||
|
||||
pair<ParseTable, LexTable> build() {
|
||||
auto item = ParseItem(START, make_shared<Symbol>(grammar.start_rule_name), {}, END_OF_INPUT);
|
||||
ParseItem item(START, make_shared<Symbol>(grammar.start_rule_name), {}, END_OF_INPUT);
|
||||
ParseItemSet item_set = item_set_closure(ParseItemSet({ item }), grammar);
|
||||
add_parse_state(item_set);
|
||||
add_error_lex_state();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue