/**
* Parse the given Thrift {@code text}, using the given {@code location}
* to anchor parsed elements withing the file.
* @param location the {@link Location} of the data being parsed.
* @param text the text to be parsed.
* @param reporter an {@link ErrorReporter} to collect warnings.
* @return a representation of the parsed Thrift data.
*/
public static ThriftFileElement parse(Location location, String text, ErrorReporter reporter) {
ANTLRInputStream charStream = new ANTLRInputStream(text);
AntlrThriftLexer lexer = new AntlrThriftLexer(charStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
AntlrThriftParser antlrParser = new AntlrThriftParser(tokenStream);
ThriftListener thriftListener = new ThriftListener(tokenStream, reporter, location);
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(thriftListener, antlrParser.document());
if (reporter.hasError()) {
String errorReports = Joiner.on('\n').join(reporter.formattedReports());
String message = String.format(Locale.US, "Syntax errors in %s:\n%s", location, errorReports);
throw new IllegalStateException(message);
}
return thriftListener.buildFileElement();
}
ThriftParser.java 文件源码
java
阅读 18
收藏 0
点赞 0
评论 0
项目:thrifty
作者:
评论列表
文章目录