Handle inline ubiquitous that are used elsewhere in the grammar

This commit is contained in:
Max Brunsfeld 2015-10-26 17:19:37 -07:00
parent b7e0cb1fc6
commit b61b27f22f
2 changed files with 26 additions and 0 deletions

View file

@ -154,6 +154,19 @@ tuple<InitialSyntaxGrammar, LexicalGrammar, const GrammarError *> extract_tokens
* lexical grammar's separator rules.
*/
for (const rule_ptr &rule : grammar.ubiquitous_tokens) {
int i = 0;
bool used_elsewhere_in_grammar = false;
for (const Variable &variable : lexical_grammar.variables) {
if (variable.rule->operator==(*rule)) {
syntax_grammar.ubiquitous_tokens.insert(Symbol(i, true));
used_elsewhere_in_grammar = true;
}
i++;
}
if (used_elsewhere_in_grammar)
continue;
if (is_token(rule)) {
lexical_grammar.separators.push_back(rule);
continue;