Elide.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:elide 作者:
/**
 * Compile request to AST.
 *
 * @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();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号