/**
* 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();
}
Elide.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:elide
作者:
评论列表
文章目录