Example usage for org.antlr.v4.runtime RuleContext getRuleIndex

List of usage examples for org.antlr.v4.runtime RuleContext getRuleIndex

Introduction

In this page you can find the example usage for org.antlr.v4.runtime RuleContext getRuleIndex.

Prototype

public int getRuleIndex() 

Source Link

Usage

From source file:tnsnamesInterfaceListener.java

License:Open Source License

@Override
public void enterBeq_beq(tnsnamesParser.Beq_beqContext ctx) {
    RuleContext parentCtx = ctx.getParent();
    String parentRule = this.ruleNames[parentCtx.getRuleIndex()];

    // Check for redefinitions. BEQ.
    if (parentRule == "beq_parameter") {
        checkForRedefinition("PROTOCOL", firstBEQ_ProtocolLine, this.lineNumber);
    }/*from   w  w w .  ja va2s. co  m*/

    // Check for redefinitions. ARGS.
    if (parentRule == "bad_address") {
        checkForRedefinition("PROTOCOL", firstBAD_ProtocolLine, this.lineNumber);
    }
}

From source file:tnsnamesInterfaceListener.java

License:Open Source License

@Override
public void enterAl_load_balance(tnsnamesParser.Al_load_balanceContext ctx) {
    // Who is my parent? We need this to prevent errors when, for example,
    // an ADDRESS_LIST FAIL_OVER parameter is flagged as redefining a parent
    // DESCRIPTION FAIL_OVER parameter, which is not actually the case.
    RuleContext parentCtx = ctx.getParent();

    // We get the rule name, from the grammar, for the parent of this 
    // rule. In lower case as we are dealing with parser rules.
    String parentRule = this.ruleNames[parentCtx.getRuleIndex()];

    // Check for redefinitions, DESCRIPTION_LIST.
    if (parentRule == "dl_parameter") {
        checkForRedefinition("LOAD_BALANCE", firstDL_LoadBalanceLine, this.lineNumber);
    }//from  w ww  .  j av a2s  .  c  o  m

    // Check for redefinitions, DESCRIPTION.
    if (parentRule == "d_parameter") {
        checkForRedefinition("LOAD_BALANCE", firstLoadBalanceLine, this.lineNumber);
    }

    // Check for redefinitions, ADDRESS_LIST.
    if (parentRule == "al_parameter") {
        checkForRedefinition("LOAD_BALANCE", firstAL_LoadBalanceLine, this.lineNumber);
    }
}

From source file:tnsnamesInterfaceListener.java

License:Open Source License

@Override
public void enterAl_failover(tnsnamesParser.Al_failoverContext ctx) {
    // Who is my parent? We need this top prevent errors when, for example,
    // an ADDRESS_LIST FAIL_OVER parameter is flagged as redefining a parent
    // DESCRIPTION FAIL_OVER parameter, which is not actually the case.
    RuleContext parentCtx = ctx.getParent();

    // We get the rule name, from the grammar, for the parent of this 
    // rule. In lower case as we are dealing with parser rules.
    String parentRule = this.ruleNames[parentCtx.getRuleIndex()];

    // Check for redefinitions, DESCRIPTION_LIST.
    if (parentRule == "dl_parameter") {
        checkForRedefinition("FAILOVER", firstDL_FailOverLine, this.lineNumber);
    }/*from  w  w  w  .  j  ava  2 s .c om*/

    // Check for redefinitions, DESCRIPTION.
    if (parentRule == "d_parameter") {
        checkForRedefinition("FAILOVER", firstFailOverLine, this.lineNumber);
    }

    // Check for redefinitions, ADDRESS_LIST.
    if (parentRule == "al_parameter") {
        checkForRedefinition("FAILOVER", firstAL_FailOverLine, this.lineNumber);
    }
}

From source file:tnsnamesInterfaceListener.java

License:Open Source License

@Override
public void enterD_recv_buf(tnsnamesParser.D_recv_bufContext ctx) {
    // Who is my parent rule?
    RuleContext parentCtx = ctx.getParent();
    String parentRule = this.ruleNames[parentCtx.getRuleIndex()];

    // Check for redefinitions, DESCRIPTION.
    if (parentRule == "d_parameter") {
        checkForRedefinition("RECV_BUF_SIZE", firstRecvBufLine, this.lineNumber);
    }//from  ww w. j a v a  2 s . c  o  m

    // Check for redefinitions, DESCRIPTION.
    if (parentRule == "a_parameter") {
        checkForRedefinition("RECV_BUF_SIZE", firstA_RecvBufLine, this.lineNumber);
    }
}

From source file:tnsnamesInterfaceListener.java

License:Open Source License

@Override
public void enterD_send_buf(tnsnamesParser.D_send_bufContext ctx) {
    // Who is my parent rule?
    RuleContext parentCtx = ctx.getParent();
    String parentRule = this.ruleNames[parentCtx.getRuleIndex()];

    // Check for redefinitions, DESCRIPTION.
    if (parentRule == "d_parameter") {
        checkForRedefinition("SEND_BUF_SIZE", firstSendBufLine, this.lineNumber);
    }//from w  w w.  j av  a  2  s  . com

    // Check for redefinitions, DESCRIPTION.
    if (parentRule == "a_parameter") {
        checkForRedefinition("SEND_BUF_SIZE", firstA_SendBufLine, this.lineNumber);
    }
}

From source file:tnsnamesInterfaceListener.java

License:Open Source License

@Override
public void enterAl_source_route(tnsnamesParser.Al_source_routeContext ctx) {
    // Who is my parent?
    RuleContext parentCtx = ctx.getParent();

    // We get the rule name, from the grammar, for the parent of this 
    // rule. In lower case as we are dealing with parser rules.
    String parentRule = this.ruleNames[parentCtx.getRuleIndex()];

    // Check for redefinitions, DESCRIPTION_LIST.
    if (parentRule == "dl_parameter") {
        checkForRedefinition("SOURCE_ROUTE", firstDL_SourceRouteLine, this.lineNumber);
    }//  w ww  .j  a v a 2  s.  com

    // Check for redefinitions, DESCRIPTION.
    if (parentRule == "d_parameter") {
        checkForRedefinition("SOURCE_ROUTE", firstSourceRouteLine, this.lineNumber);
    }

    // Check for redefinitions, ADDRESS_LIST.
    if (parentRule == "al_parameter") {
        checkForRedefinition("SOURCE_ROUTE", firstAL_SourceRouteLine, this.lineNumber);
    }
}

From source file:compile.compilersource.ASTPrinter.java

public static String explore(RuleContext context, int indentation) {
    System.out.println(MessageFormat.format("explore context nullcheck: {0}", context == null));

    String output = "";
    String RuleName = myGrammarParser.ruleNames[context.getRuleIndex()];
    for (int c = 0; c < indentation; c++) {
        System.out.print("  ");
        output += "  ";
    }/*from  w w w.j  a v a  2  s  . c  o m*/
    System.out.println(RuleName);
    output += RuleName;
    for (int c = 0; c < context.getChildCount(); c++) {
        ParseTree element = context.getChild(c);
        if (element instanceof RuleContext) {
            output += explore((RuleContext) element, indentation + 1);
        }
    }
    return output;
}

From source file:compile.compilersource.CompilerHelper.java

public static String explore(RuleContext context, int indentation) {
    String output = "";
    String RuleName = myGrammarParser.ruleNames[context.getRuleIndex()];
    for (int c = 0; c < indentation; c++) {
        System.out.print("  ");
        output += "  ";
    }//w  w w  .ja  va  2 s.  c o  m
    System.out.println(RuleName);
    output += RuleName + "\n";
    for (int c = 0; c < context.getChildCount(); c++) {
        ParseTree element = context.getChild(c);
        if (element instanceof RuleContext) {
            output += explore((RuleContext) element, indentation + 1);
        }
    }
    return output;
}

From source file:org.tvl.goworks.editor.go.completion.GoCompletionQuery.java

License:Open Source License

public static RuleContext getTopContext(Parser parser, RuleContext context, IntervalSet values,
        boolean checkTop) {
    if (checkTop && context instanceof ParserRuleContext) {
        if (values.contains(context.getRuleIndex())) {
            return context;
        }/*from www. j  a v a  2s. co  m*/
    }

    if (context.isEmpty()) {
        return null;
    }

    if (values.contains(parser.getATN().states.get(context.invokingState).ruleIndex)) {
        return context.parent;
    }

    return getTopContext(parser, context.parent, values, false);
}

From source file:org.tvl.goworks.editor.go.parser.CodeModelBuilderListener.java

License:Open Source License

@Override
@RuleDependencies({//from  w  w w . ja  v a  2s . co  m
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_typeLiteral, version = 0, dependents = Dependents.PARENTS),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_arrayType, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_structType, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_pointerType, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_functionType, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_interfaceType, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_sliceType, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_mapType, version = 0, dependents = Dependents.SELF),
        @RuleDependency(recognizer = GoParser.class, rule = GoParser.RULE_channelType, version = 0, dependents = Dependents.SELF), })
public void exitTypeLiteral(TypeLiteralContext ctx) {
    @NonNull
    TypeModelImpl result = _unknownType;
    if (ctx.getChildCount() > 0) {
        ParseTree child = ctx.getChild(0);
        if (child instanceof RuleNode) {
            RuleContext ruleContext = ((RuleNode) child).getRuleContext();
            switch (ruleContext.getRuleIndex()) {
            case GoParser.RULE_arrayType:
            case GoParser.RULE_structType:
            case GoParser.RULE_pointerType:
            case GoParser.RULE_functionType:
            case GoParser.RULE_interfaceType:
            case GoParser.RULE_sliceType:
            case GoParser.RULE_mapType:
            case GoParser.RULE_channelType:
                result = popTypeModel((ParserRuleContext) ruleContext);
                break;

            default:
                break;
            }
        }
    }

    _typeModelStack.push(result);
}