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

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

Introduction

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

Prototype

@Override
    public ParseTree getChild(int i) 

Source Link

Usage

From source file:com.twosigma.beaker.groovy.autocomplete.GroovyNodeCompletion.java

License:Apache License

private ParseTree findLeftSibling(RuleContext ctx) {
    RuleContext p = ctx.getParent();
    if (p != null) {
        for (int i = 0; i < p.getChildCount(); i++) {
            if (p.getChild(i).equals(ctx)) {
                if (i > 0)
                    return p.getChild(i - 1);
                break;
            }/*w ww . j  a  va 2  s.  c  om*/
        }
    }
    return null;
}

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  ww w.  jav  a2  s  . com*/
    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 += "  ";
    }/*from w  w w. ja  v  a 2 s  . c  om*/
    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;
}