Search in sources :

Example 6 with SrcOp

use of org.antlr.v4.codegen.model.SrcOp 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)

Example 7 with SrcOp

use of org.antlr.v4.codegen.model.SrcOp in project antlr4 by antlr.

the class DefaultOutputModelFactory method rulePostamble.

@Override
public List<SrcOp> rulePostamble(RuleFunction function, Rule r) {
    if (r.namedActions.containsKey("after") || r.namedActions.containsKey("finally")) {
        // See OutputModelController.buildLeftRecursiveRuleFunction
        // and Parser.exitRule for other places which set stop.
        CodeGenerator gen = getGenerator();
        STGroup codegenTemplates = gen.getTemplates();
        ST setStopTokenAST = codegenTemplates.getInstanceOf("recRuleSetStopToken");
        Action setStopTokenAction = new Action(this, function.ruleCtx, setStopTokenAST);
        List<SrcOp> ops = new ArrayList<SrcOp>(1);
        ops.add(setStopTokenAction);
        return ops;
    }
    return super.rulePostamble(function, r);
}
Also used : ST(org.stringtemplate.v4.ST) Action(org.antlr.v4.codegen.model.Action) SrcOp(org.antlr.v4.codegen.model.SrcOp) STGroup(org.stringtemplate.v4.STGroup) ArrayList(java.util.ArrayList)

Aggregations

AddToLabelList (org.antlr.v4.codegen.model.AddToLabelList)4 Decl (org.antlr.v4.codegen.model.decl.Decl)4 RuleContextDecl (org.antlr.v4.codegen.model.decl.RuleContextDecl)3 TokenDecl (org.antlr.v4.codegen.model.decl.TokenDecl)3 TokenListDecl (org.antlr.v4.codegen.model.decl.TokenListDecl)3 ArrayList (java.util.ArrayList)2 Action (org.antlr.v4.codegen.model.Action)2 LeftRecursiveRuleFunction (org.antlr.v4.codegen.model.LeftRecursiveRuleFunction)2 RuleFunction (org.antlr.v4.codegen.model.RuleFunction)2 SrcOp (org.antlr.v4.codegen.model.SrcOp)2 ST (org.stringtemplate.v4.ST)2 STGroup (org.stringtemplate.v4.STGroup)2 LeftRecursiveRuleAltInfo (org.antlr.v4.analysis.LeftRecursiveRuleAltInfo)1 AltBlock (org.antlr.v4.codegen.model.AltBlock)1 Choice (org.antlr.v4.codegen.model.Choice)1 CodeBlockForAlt (org.antlr.v4.codegen.model.CodeBlockForAlt)1 CodeBlockForOuterMostAlt (org.antlr.v4.codegen.model.CodeBlockForOuterMostAlt)1 InvokeRule (org.antlr.v4.codegen.model.InvokeRule)1 MatchNotSet (org.antlr.v4.codegen.model.MatchNotSet)1 MatchSet (org.antlr.v4.codegen.model.MatchSet)1