Example usage for org.antlr.v4.tool.ast RuleAST getRuleName

List of usage examples for org.antlr.v4.tool.ast RuleAST getRuleName

Introduction

In this page you can find the example usage for org.antlr.v4.tool.ast RuleAST getRuleName.

Prototype

public String getRuleName() 

Source Link

Usage

From source file:org.opencypher.tools.grammar.Antlr4ToolFacade.java

License:Apache License

public static void assertGeneratesValidParser(String resource) throws Exception {
    Output.Readable buffer = stringBuilder();
    Tool antlr = new Tool();
    Antlr4ToolFacade facade = new Antlr4ToolFacade(antlr, buffer);
    try {/*from   ww w  .  j  a  va 2s.c om*/
        Antlr4.write(Fixture.grammarResource(Antlr4.class, resource), buffer);
    } catch (Throwable e) {
        try {
            facade.reportFailureIn("generating grammar");
        } catch (AssertionError x) {
            throw e;
        }
    }
    antlr.addListener(facade);
    GrammarRootAST ast = antlr.parse(resource, new ANTLRReaderStream(buffer.reader()));
    if (ast.hasErrors) {
        RuleAST lastGood = lastGoodRule(ast);
        if (lastGood == null) {
            facade.reportFailureIn("parsing grammar");
        } else {
            facade.reportFailureIn(
                    "parsing grammar, after " + lastGood.getRuleName() + " on line " + lastGood.getLine());
        }
    }
    antlr.process(antlr.createGrammar(ast), false);
    if (facade.hasErrors()) {
        facade.reportFailureIn("processing grammar");
    }
}