use of org.antlr.v4.tool.ast.GrammarAST in project antlr4 by antlr.
the class SymbolChecks method checkForLabelConflict.
public void checkForLabelConflict(Rule r, GrammarAST labelID) {
String name = labelID.getText();
if (nameToRuleMap.containsKey(name)) {
ErrorType etype = ErrorType.LABEL_CONFLICTS_WITH_RULE;
errMgr.grammarError(etype, g.fileName, labelID.token, name, r.name);
}
if (tokenIDs.contains(name)) {
ErrorType etype = ErrorType.LABEL_CONFLICTS_WITH_TOKEN;
errMgr.grammarError(etype, g.fileName, labelID.token, name, r.name);
}
if (r.args != null && r.args.get(name) != null) {
ErrorType etype = ErrorType.LABEL_CONFLICTS_WITH_ARG;
errMgr.grammarError(etype, g.fileName, labelID.token, name, r.name);
}
if (r.retvals != null && r.retvals.get(name) != null) {
ErrorType etype = ErrorType.LABEL_CONFLICTS_WITH_RETVAL;
errMgr.grammarError(etype, g.fileName, labelID.token, name, r.name);
}
if (r.locals != null && r.locals.get(name) != null) {
ErrorType etype = ErrorType.LABEL_CONFLICTS_WITH_LOCAL;
errMgr.grammarError(etype, g.fileName, labelID.token, name, r.name);
}
}
use of org.antlr.v4.tool.ast.GrammarAST 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.ast.GrammarAST in project antlr4 by antlr.
the class ParserFactory method getComplexEBNFBlock.
@Override
public Choice getComplexEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
int ebnf = 0;
if (ebnfRoot != null)
ebnf = ebnfRoot.getType();
Choice c = null;
switch(ebnf) {
case ANTLRParser.OPTIONAL:
c = new OptionalBlock(this, ebnfRoot, alts);
break;
case ANTLRParser.CLOSURE:
c = new StarBlock(this, ebnfRoot, alts);
break;
case ANTLRParser.POSITIVE_CLOSURE:
c = new PlusBlock(this, ebnfRoot, alts);
break;
}
return c;
}
use of org.antlr.v4.tool.ast.GrammarAST in project antlr4 by antlr.
the class ParserFactory method getAddToListOpIfListLabelPresent.
public AddToLabelList getAddToListOpIfListLabelPresent(LabeledOp op, GrammarAST label) {
AddToLabelList labelOp = null;
if (label != null && label.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
String listLabel = gen.getTarget().getListLabel(label.getText());
labelOp = new AddToLabelList(this, listLabel, op.getLabels().get(0));
}
return labelOp;
}
use of org.antlr.v4.tool.ast.GrammarAST in project antlr4 by antlr.
the class ParserFactory method needsImplicitLabel.
@Override
public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) {
Alternative currentOuterMostAlt = getCurrentOuterMostAlt();
boolean actionRefsAsToken = currentOuterMostAlt.tokenRefsInActions.containsKey(ID.getText());
boolean actionRefsAsRule = currentOuterMostAlt.ruleRefsInActions.containsKey(ID.getText());
return op.getLabels().isEmpty() && (actionRefsAsToken || actionRefsAsRule);
}
Aggregations