Remove auxiliary rules from syntax tree
This commit is contained in:
parent
c3b65d22bf
commit
7d297f2f9e
15 changed files with 1107 additions and 724 deletions
|
|
@ -60,13 +60,21 @@ namespace tree_sitter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static vector<bool> reduce_flags(const vector<rules::Symbol> &child_symbols) {
|
||||
vector<bool> result;
|
||||
for (auto symbol : child_symbols) {
|
||||
result.push_back(symbol.is_auxiliary);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void add_reduce_actions(const ParseItemSet &item_set, size_t state_index) {
|
||||
for (ParseItem item : item_set) {
|
||||
if (item.is_done()) {
|
||||
ParseAction action = (item.lhs.name == START) ?
|
||||
ParseAction::Accept() :
|
||||
ParseAction::Reduce(item.lhs, item.consumed_sym_count);
|
||||
ParseAction::Reduce(item.lhs, reduce_flags(item.consumed_symbols));
|
||||
parse_table.add_action(state_index, item.lookahead_sym, action);
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +124,7 @@ namespace tree_sitter {
|
|||
lex_grammar(lex_grammar) {};
|
||||
|
||||
pair<ParseTable, LexTable> build() {
|
||||
auto item = ParseItem(START, rules::sym(grammar.start_rule_name), 0, END_OF_INPUT);
|
||||
auto item = ParseItem(START, rules::sym(grammar.start_rule_name), {}, END_OF_INPUT);
|
||||
ParseItemSet item_set = item_set_closure(ParseItemSet({ item }), grammar);
|
||||
add_parse_state(item_set);
|
||||
return pair<ParseTable, LexTable>(parse_table, lex_table);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue