use of org.antlr.works.grammar.element.ElementAction in project antlrworks by antlr.
the class EditorRules method findTokensToIgnore.
public static void findTokensToIgnore(List<ElementRule> rules, boolean reset) {
for (ElementRule rule : rules) {
if (reset)
rule.ignored = false;
List<ElementAction> actions = rule.getActions();
if (actions == null || actions.isEmpty())
continue;
for (ElementAction action : actions) {
List<ATEToken> tokens = action.getTokens();
for (int t = 0; t < tokens.size(); t++) {
ATEToken token = tokens.get(t);
/* the 'channel' token can be either an ID or a reference if a rule in the grammar has the name
'channel' */
if ((token.type == ATESyntaxLexer.TOKEN_ID || token.type == GrammarSyntaxLexer.TOKEN_REFERENCE) && token.getAttribute().equals("channel") && t + 3 < tokens.size()) {
ATEToken t1 = tokens.get(t + 1);
ATEToken t2 = tokens.get(t + 2);
if (t1.type != ATESyntaxLexer.TOKEN_CHAR || !t1.getAttribute().equals("="))
continue;
if (t2.type != ATESyntaxLexer.TOKEN_ID || !t2.getAttribute().equals("HIDDEN"))
continue;
rule.ignored = true;
break;
}
if (token.type == GrammarSyntaxLexer.TOKEN_ID && token.getAttribute().equals("skip")) {
// Take skip() into account only if it is the only token in the block
if (tokens.size() == 5 && t == 1) {
rule.ignored = true;
break;
}
}
}
}
}
}
Aggregations