Search in sources :

Example 1 with TokenListDecl

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);
}
Also used : TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) MatchToken(org.antlr.v4.codegen.model.MatchToken) RuleFunction(org.antlr.v4.codegen.model.RuleFunction) LeftRecursiveRuleFunction(org.antlr.v4.codegen.model.LeftRecursiveRuleFunction) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl) AddToLabelList(org.antlr.v4.codegen.model.AddToLabelList)

Example 2 with TokenListDecl

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;
}
Also used : Choice(org.antlr.v4.codegen.model.Choice) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl) DecisionState(org.antlr.v4.runtime.atn.DecisionState)

Example 3 with TokenListDecl

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);
}
Also used : MatchSet(org.antlr.v4.codegen.model.MatchSet) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) RuleFunction(org.antlr.v4.codegen.model.RuleFunction) LeftRecursiveRuleFunction(org.antlr.v4.codegen.model.LeftRecursiveRuleFunction) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl) MatchNotSet(org.antlr.v4.codegen.model.MatchNotSet) AddToLabelList(org.antlr.v4.codegen.model.AddToLabelList)

Example 4 with TokenListDecl

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);
}
Also used : Wildcard(org.antlr.v4.codegen.model.Wildcard) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl) AddToLabelList(org.antlr.v4.codegen.model.AddToLabelList)

Aggregations

Decl (org.antlr.v4.codegen.model.decl.Decl)4 RuleContextDecl (org.antlr.v4.codegen.model.decl.RuleContextDecl)4 TokenDecl (org.antlr.v4.codegen.model.decl.TokenDecl)4 TokenListDecl (org.antlr.v4.codegen.model.decl.TokenListDecl)4 AddToLabelList (org.antlr.v4.codegen.model.AddToLabelList)3 LeftRecursiveRuleFunction (org.antlr.v4.codegen.model.LeftRecursiveRuleFunction)2 RuleFunction (org.antlr.v4.codegen.model.RuleFunction)2 Choice (org.antlr.v4.codegen.model.Choice)1 MatchNotSet (org.antlr.v4.codegen.model.MatchNotSet)1 MatchSet (org.antlr.v4.codegen.model.MatchSet)1 MatchToken (org.antlr.v4.codegen.model.MatchToken)1 Wildcard (org.antlr.v4.codegen.model.Wildcard)1 DecisionState (org.antlr.v4.runtime.atn.DecisionState)1