Search in sources :

Example 1 with TokenDecl

use of org.antlr.v4.codegen.model.decl.TokenDecl in project antlr4 by tunnelvisionlabs.

the class ParserFactory method defineImplicitLabel.

// support
public void defineImplicitLabel(GrammarAST ast, LabeledOp op) {
    Decl d;
    if (ast.getType() == ANTLRParser.SET || ast.getType() == ANTLRParser.WILDCARD) {
        String implLabel = getTarget().getImplicitSetLabel(String.valueOf(ast.token.getTokenIndex()));
        d = getTokenLabelDecl(implLabel);
        ((TokenDecl) d).isImplicit = true;
    } else if (ast.getType() == ANTLRParser.RULE_REF) {
        // a rule reference?
        Rule r = g.getRule(ast.getText());
        String implLabel = getTarget().getImplicitRuleLabel(ast.getText());
        String ctxName = getTarget().getRuleFunctionContextStructName(r);
        d = new RuleContextDecl(this, implLabel, ctxName);
        ((RuleContextDecl) d).isImplicit = true;
    } else {
        String implLabel = getTarget().getImplicitTokenLabel(ast.getText());
        d = getTokenLabelDecl(implLabel);
        ((TokenDecl) d).isImplicit = true;
    }
    op.getLabels().add(d);
    // all labels must be in scope struct in case we exec action out of context
    getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d);
}
Also used : 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) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) InvokeRule(org.antlr.v4.codegen.model.InvokeRule) Rule(org.antlr.v4.tool.Rule) LeftRecursiveRule(org.antlr.v4.tool.LeftRecursiveRule) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl)

Example 2 with TokenDecl

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

the class ParserFactory method defineImplicitLabel.

// support
public void defineImplicitLabel(GrammarAST ast, LabeledOp op) {
    Decl d;
    if (ast.getType() == ANTLRParser.SET || ast.getType() == ANTLRParser.WILDCARD) {
        String implLabel = gen.getTarget().getImplicitSetLabel(String.valueOf(ast.token.getTokenIndex()));
        d = getTokenLabelDecl(implLabel);
        ((TokenDecl) d).isImplicit = true;
    } else if (ast.getType() == ANTLRParser.RULE_REF) {
        // a rule reference?
        Rule r = g.getRule(ast.getText());
        String implLabel = gen.getTarget().getImplicitRuleLabel(ast.getText());
        String ctxName = gen.getTarget().getRuleFunctionContextStructName(r);
        d = new RuleContextDecl(this, implLabel, ctxName);
        ((RuleContextDecl) d).isImplicit = true;
    } else {
        String implLabel = gen.getTarget().getImplicitTokenLabel(ast.getText());
        d = getTokenLabelDecl(implLabel);
        ((TokenDecl) d).isImplicit = true;
    }
    op.getLabels().add(d);
    // all labels must be in scope struct in case we exec action out of context
    getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d);
}
Also used : 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) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) InvokeRule(org.antlr.v4.codegen.model.InvokeRule) Rule(org.antlr.v4.tool.Rule) LeftRecursiveRule(org.antlr.v4.tool.LeftRecursiveRule) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl)

Aggregations

InvokeRule (org.antlr.v4.codegen.model.InvokeRule)2 Decl (org.antlr.v4.codegen.model.decl.Decl)2 RuleContextDecl (org.antlr.v4.codegen.model.decl.RuleContextDecl)2 TokenDecl (org.antlr.v4.codegen.model.decl.TokenDecl)2 TokenListDecl (org.antlr.v4.codegen.model.decl.TokenListDecl)2 LeftRecursiveRule (org.antlr.v4.tool.LeftRecursiveRule)2 Rule (org.antlr.v4.tool.Rule)2