本文整理汇总了Java中org.antlr.tool.ErrorManager.error方法的典型用法代码示例。如果您正苦于以下问题:Java ErrorManager.error方法的具体用法?Java ErrorManager.error怎么用?Java ErrorManager.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.tool.ErrorManager
的用法示例。
在下文中一共展示了ErrorManager.error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importGrammar
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
@Override
public void importGrammar(GrammarAST grammarNameAST, String label) {
if (tool == null) {
return;
}
String grammarName = grammarNameAST.getText();
//System.out.println("import "+gfile.getName());
String gname = grammarName + GRAMMAR_FILE_EXTENSION;
try {
String fullName = tool.getLibraryFile(gname);
File file = new File(fullName);
if (!file.exists()) {
return;
}
FileObject fileObject = FileUtil.toFileObject(file);
if (!fileObject.isValid() || fileObject.isFolder()) {
return;
}
String text = fileObject.asText();
// the IDE always renders newlines as \n, so we have to convert line endings
// before parsing if we want the seek operation to be accurate
text = text.replace("\r\n", "\n");
ANTLRStringStream input = new ANTLRStringStream(text);
ANTLRErrorProvidingLexer lexer = new ANTLRErrorProvidingLexer(input);
ANTLRParserTokenStream tokenStream = new ANTLRParserTokenStream(lexer);
ANTLRErrorProvidingParser parser = new ANTLRErrorProvidingParser(tokenStream, snapshot);
lexer.setParser(parser);
tokenStream.setParser(parser);
parser.setTreeAdaptor(new ANTLRErrorProvidingParser.grammar_Adaptor(parser));
List<? extends Token> tokenList = tokenStream.getTokens();
CommonToken[] tokens = new CommonToken[tokenList.size()];
tokens = tokenList.toArray(tokens);
try {
GrammarWrapper g = new GrammarWrapper(this.tool, fullName, this.composite, this.snapshot);
g.setFileName(fullName); // work around a bug in Grammar.setName that results in a NPE
ANTLRParser.grammar__return result = parser.grammar_(g);
imported.add(new CompiledFileModelV3(parser, g, result, fileObject, tokens));
} catch (RecognitionException | RuntimeException | Error ex) {
Exceptions.printStackTrace(ex);
}
}
catch (IOException ioe) {
ErrorManager.error(ErrorManager.MSG_CANNOT_OPEN_FILE,
gname,
ioe);
}
}