Remove inheritance link btwn PreparedGrammar and Grammar
This commit is contained in:
parent
11acc7d087
commit
e105f5cebc
11 changed files with 70 additions and 53 deletions
|
|
@ -51,7 +51,7 @@ namespace tree_sitter {
|
|||
};
|
||||
|
||||
PreparedGrammar expand_repeats(const PreparedGrammar &grammar) {
|
||||
vector<pair<string, rules::rule_ptr>> rules, aux_rules(grammar.aux_rules);
|
||||
vector<pair<string, rules::rule_ptr>> rules, aux_rules(grammar.aux_rules());
|
||||
|
||||
for (auto &pair : grammar.rules()) {
|
||||
ExpandRepeats expander(pair.first, aux_rules.size());
|
||||
|
|
@ -59,7 +59,8 @@ namespace tree_sitter {
|
|||
aux_rules.insert(aux_rules.end(), expander.aux_rules.begin(), expander.aux_rules.end());
|
||||
}
|
||||
|
||||
return PreparedGrammar(rules, aux_rules, grammar.options);
|
||||
return PreparedGrammar(rules, aux_rules).
|
||||
ubiquitous_tokens(grammar.ubiquitous_tokens());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,14 +55,16 @@ namespace tree_sitter {
|
|||
rules.push_back({ pair.first, rule });
|
||||
}
|
||||
|
||||
for (auto &pair : grammar.aux_rules) {
|
||||
for (auto &pair : grammar.aux_rules()) {
|
||||
auto rule = expander.apply(pair.second);
|
||||
if (expander.error)
|
||||
return { PreparedGrammar(), expander.error };
|
||||
aux_rules.push_back({ pair.first, rule });
|
||||
}
|
||||
|
||||
return { PreparedGrammar(rules, aux_rules, grammar.options), nullptr };
|
||||
return {
|
||||
PreparedGrammar(rules, aux_rules).ubiquitous_tokens(grammar.ubiquitous_tokens()),
|
||||
nullptr };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ namespace tree_sitter {
|
|||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < input_grammar.aux_rules.size(); i++) {
|
||||
auto pair = input_grammar.aux_rules[i];
|
||||
for (size_t i = 0; i < input_grammar.aux_rules().size(); i++) {
|
||||
auto pair = input_grammar.aux_rules()[i];
|
||||
if (IsToken().apply(pair.second)) {
|
||||
aux_tokens.push_back(pair);
|
||||
symbol_replacements.insert({
|
||||
|
|
@ -133,14 +133,11 @@ namespace tree_sitter {
|
|||
pair.second = inliner.apply(pair.second);
|
||||
for (auto &pair : aux_rules)
|
||||
pair.second = inliner.apply(pair.second);
|
||||
for (auto &symbol : input_grammar.options.ubiquitous_tokens)
|
||||
for (auto &symbol : input_grammar.ubiquitous_tokens())
|
||||
ubiquitous_tokens.push_back(inliner.replace_symbol(symbol));
|
||||
|
||||
PreparedGrammarOptions parse_options(input_grammar.options);
|
||||
parse_options.ubiquitous_tokens = ubiquitous_tokens;
|
||||
|
||||
return {
|
||||
PreparedGrammar(rules, aux_rules, parse_options),
|
||||
PreparedGrammar(rules, aux_rules).ubiquitous_tokens(ubiquitous_tokens),
|
||||
PreparedGrammar(tokens, aux_tokens)
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
return {
|
||||
PreparedGrammar(rules, {}, PreparedGrammarOptions({ ubiquitous_tokens })),
|
||||
PreparedGrammar(rules, {}).ubiquitous_tokens(ubiquitous_tokens),
|
||||
nullptr
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue