public static ParserInterpreterData buildFromSnapshot(DocumentSnapshot snapshot) {
LexerInterpreterData lexerInterpreterData = LexerInterpreterData.buildFromSnapshot(snapshot);
if (lexerInterpreterData == null) {
return null;
}
List<SyntaxError> syntaxErrors = new ArrayList<>();
Tool tool = new CustomTool(snapshot);
tool.errMgr = new CustomErrorManager(tool);
tool.addListener(new ErrorListener(snapshot, tool, syntaxErrors));
tool.libDirectory = new File(snapshot.getVersionedDocument().getFileObject().getPath()).getParent();
ANTLRStringStream stream = new ANTLRStringStream(snapshot.getText());
stream.name = snapshot.getVersionedDocument().getFileObject().getNameExt();
GrammarRootAST ast = tool.parse(stream.name, stream);
Grammar grammar = tool.createGrammar(ast);
if (grammar instanceof LexerGrammar) {
return null;
}
tool.process(grammar, false);
ParserInterpreterData data = new ParserInterpreterData();
// start by filling in the lexer data
data.lexerInterpreterData = lexerInterpreterData;
// then fill in the parser data
data.grammarFileName = grammar.fileName;
data.serializedAtn = ATNSerializer.getSerializedAsString(grammar.atn, Arrays.asList(grammar.getRuleNames()));
data.vocabulary = grammar.getVocabulary();
data.ruleNames = new ArrayList<>(grammar.rules.keySet());
return data;
}
ParserInterpreterData.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:goworks
作者:
评论列表
文章目录