Example usage for org.antlr.v4.runtime.misc ParseCancellationException ParseCancellationException

List of usage examples for org.antlr.v4.runtime.misc ParseCancellationException ParseCancellationException

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.misc ParseCancellationException ParseCancellationException.

Prototype

public ParseCancellationException(String message, Throwable cause) 

Source Link

Usage

From source file:com.yahoo.elide.core.EntityPermissions.java

License:Apache License

private ParseTree parseExpression(String expression) {
    ANTLRInputStream is = new ANTLRInputStream(expression);
    ExpressionLexer lexer = new ExpressionLexer(is);
    lexer.removeErrorListeners();//from w w  w  . j a  va 2 s  .co  m
    lexer.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                int charPositionInLine, String msg, RecognitionException e) {
            throw new ParseCancellationException(msg, e);
        }
    });
    ExpressionParser parser = new ExpressionParser(new CommonTokenStream(lexer));
    lexer.reset();
    return parser.start();
}

From source file:com.yahoo.elide.Elide.java

License:Apache License

/**
 * Compile request to AST.//from  ww w.  j ava2  s  . c om
 *
 * @param path request
 * @return AST parse tree
 */
public static ParseTree parse(String path) {
    String normalizedPath = Paths.get(path).normalize().toString().replace(File.separatorChar, '/');
    if (normalizedPath.startsWith("/")) {
        normalizedPath = normalizedPath.substring(1);
    }
    ANTLRInputStream is = new ANTLRInputStream(normalizedPath);
    CoreLexer lexer = new CoreLexer(is);
    lexer.removeErrorListeners();
    lexer.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                int charPositionInLine, String msg, RecognitionException e) {
            throw new ParseCancellationException(msg, e);
        }
    });
    CoreParser parser = new CoreParser(new CommonTokenStream(lexer));
    parser.setErrorHandler(new BailErrorStrategy());
    return parser.start();
}

From source file:org.linqs.psl.parser.ModelLoader.java

License:Apache License

/**
 * Get a parser over the given input.//from  w  ww .  j av a  2s .  c o m
 */
private static PSLParser getParser(Reader input) throws IOException {
    PSLLexer lexer = new PSLLexer(new ANTLRInputStream(input));

    // We need to add a error listener to the lexer so we halt on lex errors.
    lexer.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                int charPositionInLine, String msg, RecognitionException ex) throws ParseCancellationException {
            throw new ParseCancellationException("line " + line + ":" + charPositionInLine + " " + msg, ex);
        }
    });
    CommonTokenStream tokens = new CommonTokenStream(lexer);

    PSLParser parser = new PSLParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());

    return parser;
}