use of org.antlr.v4.codegen.model.decl.TokenListDecl 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.codegen.model.decl.TokenListDecl in project antlr4 by antlr.
the class ParserFactory method getChoiceBlock.
@Override
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts, GrammarAST labelAST) {
int decision = ((DecisionState) blkAST.atnState).decision;
Choice c;
if (!g.tool.force_atn && AnalysisPipeline.disjoint(g.decisionLOOK.get(decision))) {
c = getLL1ChoiceBlock(blkAST, alts);
} else {
c = getComplexChoiceBlock(blkAST, alts);
}
if (labelAST != null) {
// for x=(...), define x or x_list
String label = labelAST.getText();
Decl d = getTokenLabelDecl(label);
c.label = d;
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), d);
if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
String listLabel = gen.getTarget().getListLabel(label);
TokenListDecl l = new TokenListDecl(this, listLabel);
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), l);
}
}
return c;
}
use of org.antlr.v4.codegen.model.decl.TokenListDecl in project antlr4 by antlr.
the class ParserFactory method set.
@Override
public List<SrcOp> set(GrammarAST setAST, GrammarAST labelAST, boolean invert) {
MatchSet matchOp;
if (invert)
matchOp = new MatchNotSet(this, setAST);
else
matchOp = new MatchSet(this, setAST);
if (labelAST != null) {
String label = labelAST.getText();
RuleFunction rf = getCurrentRuleFunction();
if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
defineImplicitLabel(setAST, matchOp);
TokenListDecl l = getTokenListLabelDecl(label);
rf.addContextDecl(setAST.getAltLabel(), l);
} else {
Decl d = getTokenLabelDecl(label);
matchOp.labels.add(d);
rf.addContextDecl(setAST.getAltLabel(), d);
}
}
if (controller.needsImplicitLabel(setAST, matchOp))
defineImplicitLabel(setAST, matchOp);
AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(matchOp, labelAST);
return list(matchOp, listLabelOp);
}
use of org.antlr.v4.codegen.model.decl.TokenListDecl in project antlr4 by antlr.
the class ParserFactory method wildcard.
@Override
public List<SrcOp> wildcard(GrammarAST ast, GrammarAST labelAST) {
Wildcard wild = new Wildcard(this, ast);
// TODO: dup with tokenRef
if (labelAST != null) {
String label = labelAST.getText();
Decl d = getTokenLabelDecl(label);
wild.labels.add(d);
getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d);
if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
TokenListDecl l = getTokenListLabelDecl(label);
getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), l);
}
}
if (controller.needsImplicitLabel(ast, wild))
defineImplicitLabel(ast, wild);
AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(wild, labelAST);
return list(wild, listLabelOp);
}
Aggregations