use of org.antlr.v4.tool.Rule in project antlr4 by antlr.
the class UseDefAnalyzer method trackTokenRuleRefsInActions.
// side-effect: updates Alternative with refs in actions
public static void trackTokenRuleRefsInActions(Grammar g) {
for (Rule r : g.rules.values()) {
for (int i = 1; i <= r.numberOfAlts; i++) {
Alternative alt = r.alt[i];
for (ActionAST a : alt.actions) {
ActionSniffer sniffer = new ActionSniffer(g, r, alt, a, a.token);
sniffer.examineAction();
}
}
}
}
use of org.antlr.v4.tool.Rule in project antlr4 by antlr.
the class UseDefAnalyzer method getRuleDependencies.
public static Map<Rule, Set<Rule>> getRuleDependencies(Grammar g, Collection<Rule> rules) {
Map<Rule, Set<Rule>> dependencies = new HashMap<Rule, Set<Rule>>();
for (Rule r : rules) {
List<GrammarAST> tokenRefs = r.ast.getNodesWithType(ANTLRParser.TOKEN_REF);
for (GrammarAST tref : tokenRefs) {
Set<Rule> calls = dependencies.get(r);
if (calls == null) {
calls = new HashSet<Rule>();
dependencies.put(r, calls);
}
calls.add(g.getRule(tref.getText()));
}
}
return dependencies;
}
use of org.antlr.v4.tool.Rule in project antlr4 by antlr.
the class OutputModelController method buildLexerOutputModel.
public OutputModelObject buildLexerOutputModel(boolean header) {
CodeGenerator gen = delegate.getGenerator();
LexerFile file = lexerFile(gen.getRecognizerFileName(header));
setRoot(file);
file.lexer = lexer(file);
Grammar g = delegate.getGrammar();
for (Rule r : g.rules.values()) {
buildLexerRuleActions(file.lexer, r);
}
return file;
}
use of org.antlr.v4.tool.Rule in project antlr4 by antlr.
the class OutputModelController method buildParserOutputModel.
/** Build a file with a parser containing rule functions. Use the
* controller as factory in SourceGenTriggers so it triggers codegen
* extensions too, not just the factory functions in this factory.
*/
public OutputModelObject buildParserOutputModel(boolean header) {
CodeGenerator gen = delegate.getGenerator();
ParserFile file = parserFile(gen.getRecognizerFileName(header));
setRoot(file);
file.parser = parser(file);
Grammar g = delegate.getGrammar();
for (Rule r : g.rules.values()) {
buildRuleFunction(file.parser, r);
}
return file;
}
use of org.antlr.v4.tool.Rule in project antlr4 by antlr.
the class ParserFactory method ruleRef.
@Override
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
InvokeRule invokeOp = new InvokeRule(this, ID, label);
// If no manual label and action refs as token/rule not label, we need to define implicit label
if (controller.needsImplicitLabel(ID, invokeOp))
defineImplicitLabel(ID, invokeOp);
AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(invokeOp, label);
return list(invokeOp, listLabelOp);
}
Aggregations