use of org.antlr.v4.tool.ast.GrammarAST in project antlr4 by antlr.
the class ParserFactory method tokenRef.
@Override
public List<SrcOp> tokenRef(GrammarAST ID, GrammarAST labelAST, GrammarAST args) {
MatchToken matchOp = new MatchToken(this, (TerminalAST) ID);
if (labelAST != null) {
String label = labelAST.getText();
RuleFunction rf = getCurrentRuleFunction();
if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
// add Token _X and List<Token> X decls
// adds _X
defineImplicitLabel(ID, matchOp);
TokenListDecl l = getTokenListLabelDecl(label);
rf.addContextDecl(ID.getAltLabel(), l);
} else {
Decl d = getTokenLabelDecl(label);
matchOp.labels.add(d);
rf.addContextDecl(ID.getAltLabel(), d);
}
// Decl d = getTokenLabelDecl(label);
// ((MatchToken)matchOp).labels.add(d);
// getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), d);
// if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
// TokenListDecl l = getTokenListLabelDecl(label);
// getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), l);
// }
}
if (controller.needsImplicitLabel(ID, matchOp))
defineImplicitLabel(ID, matchOp);
AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(matchOp, labelAST);
return list(matchOp, listLabelOp);
}
use of org.antlr.v4.tool.ast.GrammarAST 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);
}
use of org.antlr.v4.tool.ast.GrammarAST in project antlr4 by antlr.
the class AttributeChecks method checkAllAttributeExpressions.
public static void checkAllAttributeExpressions(Grammar g) {
for (ActionAST act : g.namedActions.values()) {
AttributeChecks checker = new AttributeChecks(g, null, null, act, act.token);
checker.examineAction();
}
for (Rule r : g.rules.values()) {
for (ActionAST a : r.namedActions.values()) {
AttributeChecks checker = new AttributeChecks(g, r, null, a, a.token);
checker.examineAction();
}
for (int i = 1; i <= r.numberOfAlts; i++) {
Alternative alt = r.alt[i];
for (ActionAST a : alt.actions) {
AttributeChecks checker = new AttributeChecks(g, r, alt, a, a.token);
checker.examineAction();
}
}
for (GrammarAST e : r.exceptions) {
ActionAST a = (ActionAST) e.getChild(1);
AttributeChecks checker = new AttributeChecks(g, r, null, a, a.token);
checker.examineAction();
}
if (r.finallyAction != null) {
AttributeChecks checker = new AttributeChecks(g, r, null, r.finallyAction, r.finallyAction.token);
checker.examineAction();
}
}
}
use of org.antlr.v4.tool.ast.GrammarAST in project antlr4 by antlr.
the class BasicSemanticChecks method enterLabeledLexerElement.
@Override
protected void enterLabeledLexerElement(GrammarAST tree) {
Token label = ((GrammarAST) tree.getChild(0)).getToken();
g.tool.errMgr.grammarError(ErrorType.V3_LEXER_LABEL, g.fileName, label, label.getText());
}
use of org.antlr.v4.tool.ast.GrammarAST in project antlr4 by antlr.
the class BasicSemanticChecks method checkElementOptions.
/** Check option is appropriate for elem; parent of ID is ELEMENT_OPTIONS */
boolean checkElementOptions(GrammarASTWithOptions elem, GrammarAST ID, GrammarAST valueAST) {
if (checkAssocElementOption && ID != null && "assoc".equals(ID.getText())) {
if (elem.getType() != ANTLRParser.ALT) {
Token optionID = ID.token;
String fileName = optionID.getInputStream().getSourceName();
g.tool.errMgr.grammarError(ErrorType.UNRECOGNIZED_ASSOC_OPTION, fileName, optionID, currentRuleName);
}
}
if (elem instanceof RuleRefAST) {
return checkRuleRefOptions((RuleRefAST) elem, ID, valueAST);
}
if (elem instanceof TerminalAST) {
return checkTokenOptions((TerminalAST) elem, ID, valueAST);
}
if (elem.getType() == ANTLRParser.ACTION) {
return false;
}
if (elem.getType() == ANTLRParser.SEMPRED) {
Token optionID = ID.token;
String fileName = optionID.getInputStream().getSourceName();
if (valueAST != null && !Grammar.semPredOptions.contains(optionID.getText())) {
g.tool.errMgr.grammarError(ErrorType.ILLEGAL_OPTION, fileName, optionID, optionID.getText());
return false;
}
}
return false;
}
Aggregations