Search in sources :

Example 1 with ContextTokenListGetterDecl

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

the class RuleFunction method getDeclForAltElement.

public List<Decl> getDeclForAltElement(GrammarAST t, String refLabelName, boolean needList, boolean optional) {
    int lfIndex = refLabelName.indexOf(ATNSimulator.RULE_VARIANT_DELIMITER);
    if (lfIndex >= 0) {
        refLabelName = refLabelName.substring(0, lfIndex);
    }
    List<Decl> decls = new ArrayList<Decl>();
    if (t.getType() == RULE_REF) {
        Rule rref = factory.getGrammar().getRule(t.getText());
        String ctxName = factory.getTarget().getRuleFunctionContextStructName(rref);
        if (needList) {
            if (factory.getTarget().supportsOverloadedMethods())
                decls.add(new ContextRuleListGetterDecl(factory, refLabelName, ctxName));
            decls.add(new ContextRuleListIndexedGetterDecl(factory, refLabelName, ctxName));
        } else {
            decls.add(new ContextRuleGetterDecl(factory, refLabelName, ctxName, optional));
        }
    } else {
        if (needList) {
            if (factory.getTarget().supportsOverloadedMethods())
                decls.add(new ContextTokenListGetterDecl(factory, refLabelName));
            decls.add(new ContextTokenListIndexedGetterDecl(factory, refLabelName));
        } else {
            decls.add(new ContextTokenGetterDecl(factory, refLabelName, optional));
        }
    }
    return decls;
}
Also used : ContextTokenListGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListGetterDecl) ContextRuleListGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListGetterDecl) ContextTokenGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenGetterDecl) ContextRuleGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleGetterDecl) ArrayList(java.util.ArrayList) ContextRuleListGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListGetterDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) StructDecl(org.antlr.v4.codegen.model.decl.StructDecl) AttributeDecl(org.antlr.v4.codegen.model.decl.AttributeDecl) AltLabelStructDecl(org.antlr.v4.codegen.model.decl.AltLabelStructDecl) ContextTokenListGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListGetterDecl) ContextRuleListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl) ContextRuleGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleGetterDecl) ContextTokenListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListIndexedGetterDecl) ContextTokenGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenGetterDecl) ContextRuleListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl) Rule(org.antlr.v4.tool.Rule) ContextTokenListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListIndexedGetterDecl)

Example 2 with ContextTokenListGetterDecl

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

the class RuleFunction method getDeclForAltElement.

public List<Decl> getDeclForAltElement(GrammarAST t, String refLabelName, boolean needList, boolean optional) {
    List<Decl> decls = new ArrayList<Decl>();
    if (t.getType() == RULE_REF) {
        Rule rref = factory.getGrammar().getRule(t.getText());
        String ctxName = factory.getGenerator().getTarget().getRuleFunctionContextStructName(rref);
        if (needList) {
            if (factory.getGenerator().getTarget().supportsOverloadedMethods())
                decls.add(new ContextRuleListGetterDecl(factory, refLabelName, ctxName));
            decls.add(new ContextRuleListIndexedGetterDecl(factory, refLabelName, ctxName));
        } else {
            decls.add(new ContextRuleGetterDecl(factory, refLabelName, ctxName, optional));
        }
    } else {
        if (needList) {
            if (factory.getGenerator().getTarget().supportsOverloadedMethods())
                decls.add(new ContextTokenListGetterDecl(factory, refLabelName));
            decls.add(new ContextTokenListIndexedGetterDecl(factory, refLabelName));
        } else {
            decls.add(new ContextTokenGetterDecl(factory, refLabelName, optional));
        }
    }
    return decls;
}
Also used : ContextTokenListGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListGetterDecl) ContextRuleListGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListGetterDecl) ContextTokenGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenGetterDecl) ContextRuleGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleGetterDecl) ArrayList(java.util.ArrayList) ContextRuleListGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListGetterDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) StructDecl(org.antlr.v4.codegen.model.decl.StructDecl) AttributeDecl(org.antlr.v4.codegen.model.decl.AttributeDecl) AltLabelStructDecl(org.antlr.v4.codegen.model.decl.AltLabelStructDecl) ContextTokenListGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListGetterDecl) ContextRuleListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl) ContextRuleGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleGetterDecl) ContextTokenListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListIndexedGetterDecl) ContextTokenGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenGetterDecl) ContextRuleListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl) Rule(org.antlr.v4.tool.Rule) ContextTokenListIndexedGetterDecl(org.antlr.v4.codegen.model.decl.ContextTokenListIndexedGetterDecl)

Aggregations

ArrayList (java.util.ArrayList)2 AltLabelStructDecl (org.antlr.v4.codegen.model.decl.AltLabelStructDecl)2 AttributeDecl (org.antlr.v4.codegen.model.decl.AttributeDecl)2 ContextRuleGetterDecl (org.antlr.v4.codegen.model.decl.ContextRuleGetterDecl)2 ContextRuleListGetterDecl (org.antlr.v4.codegen.model.decl.ContextRuleListGetterDecl)2 ContextRuleListIndexedGetterDecl (org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl)2 ContextTokenGetterDecl (org.antlr.v4.codegen.model.decl.ContextTokenGetterDecl)2 ContextTokenListGetterDecl (org.antlr.v4.codegen.model.decl.ContextTokenListGetterDecl)2 ContextTokenListIndexedGetterDecl (org.antlr.v4.codegen.model.decl.ContextTokenListIndexedGetterDecl)2 Decl (org.antlr.v4.codegen.model.decl.Decl)2 StructDecl (org.antlr.v4.codegen.model.decl.StructDecl)2 Rule (org.antlr.v4.tool.Rule)2