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

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

Introduction

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

Prototype

public String toStringTree(List<String> ruleNames) 

Source Link

Document

Print out a whole tree, not just a node, in LISP format (root child1 ..

Usage

From source file:com.intuit.karate.core.FeatureParser.java

License:Open Source License

private FeatureParser(Feature feature, InputStream is) {
    this.feature = feature;
    CharStream stream;//from www.  j a  v a  2  s . co m
    try {
        stream = CharStreams.fromStream(is, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    KarateLexer lexer = new KarateLexer(stream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    KarateParser parser = new KarateParser(tokens);
    parser.addErrorListener(errorListener);
    RuleContext tree = parser.feature();
    if (logger.isTraceEnabled()) {
        logger.debug(tree.toStringTree(parser));
    }
    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(this, tree);
    if (errorListener.isFail()) {
        String errorMessage = errorListener.getMessage();
        logger.error("not a valid feature file: {} - {}", feature.getResource().getRelativePath(),
                errorMessage);
        throw new RuntimeException(errorMessage);
    }
}