本文整理汇总了Java中org.antlr.tool.ErrorManager.setErrorListener方法的典型用法代码示例。如果您正苦于以下问题:Java ErrorManager.setErrorListener方法的具体用法?Java ErrorManager.setErrorListener怎么用?Java ErrorManager.setErrorListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.tool.ErrorManager
的用法示例。
在下文中一共展示了ErrorManager.setErrorListener方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRewriteRuleAndRewriteModeOnSimpleElements
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testRewriteRuleAndRewriteModeOnSimpleElements() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
Grammar g = new Grammar(
"tree grammar TP;\n"+
"options {ASTLabelType=CommonTree; output=template; rewrite=true;}\n" +
"a: ^(A B) -> {ick}\n" +
" | y+=INT -> {ick}\n" +
" | x=ID -> {ick}\n" +
" | BLORT -> {ick}\n" +
" ;\n"
);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
assertEquals("unexpected errors: "+equeue, 0, equeue.warnings.size());
}
示例2: testRewriteRuleAndRewriteModeIgnoreActionsPredicates
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testRewriteRuleAndRewriteModeIgnoreActionsPredicates() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
Grammar g = new Grammar(
"tree grammar TP;\n"+
"options {ASTLabelType=CommonTree; output=template; rewrite=true;}\n" +
"a: {action} {action2} x=A -> {ick}\n" +
" | {pred1}? y+=B -> {ick}\n" +
" | C {action} -> {ick}\n" +
" | {pred2}?=> z+=D -> {ick}\n" +
" | (E)=> ^(F G) -> {ick}\n" +
" ;\n"
);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
assertEquals("unexpected errors: "+equeue, 0, equeue.warnings.size());
}
示例3: testRewriteRuleAndRewriteModeNotSimple
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testRewriteRuleAndRewriteModeNotSimple() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
Grammar g = new Grammar(
"tree grammar TP;\n"+
"options {ASTLabelType=CommonTree; output=template; rewrite=true;}\n" +
"a : ID+ -> {ick}\n" +
" | INT INT -> {ick}\n" +
" ;\n"
);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
assertEquals("unexpected errors: "+equeue, 2, equeue.warnings.size());
}
示例4: testRewriteRuleAndRewriteModeRefRule
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testRewriteRuleAndRewriteModeRefRule() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
Grammar g = new Grammar(
"tree grammar TP;\n"+
"options {ASTLabelType=CommonTree; output=template; rewrite=true;}\n" +
"a : b+ -> {ick}\n" +
" | b b A -> {ick}\n" +
" ;\n" +
"b : B ;\n"
);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
assertEquals("unexpected errors: "+equeue, 2, equeue.warnings.size());
}
示例5: testWeirdRuleRef
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testWeirdRuleRef() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
String grammar =
"grammar T;\n" +
"options {output=AST;}\n" +
"a : ID a -> $a | INT ;\n"+
"ID : 'a'..'z'+ ;\n" +
"INT: '0'..'9'+ ;\n" +
"WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";
Grammar g = new Grammar(grammar);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
// $a is ambig; is it previous root or ref to a ref in alt?
assertEquals("unexpected errors: "+equeue, 1, equeue.errors.size());
}
示例6: testUnknownRule
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testUnknownRule() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
String grammar =
"grammar T;\n" +
"options {output=AST;}\n" +
"a : INT -> ugh ;\n" +
"ID : 'a'..'z'+ ;\n" +
"INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";
Grammar g = new Grammar(grammar);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
int expectedMsgID = ErrorManager.MSG_UNDEFINED_RULE_REF;
Object expectedArg = "ugh";
Object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg, expectedArg2);
checkError(equeue, expectedMessage);
}
示例7: testKnownRuleButNotInLHS
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testKnownRuleButNotInLHS() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
String grammar =
"grammar T;\n" +
"options {output=AST;}\n" +
"a : INT -> b ;\n" +
"b : 'b' ;\n" +
"ID : 'a'..'z'+ ;\n" +
"INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";
Grammar g = new Grammar(grammar);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
int expectedMsgID = ErrorManager.MSG_REWRITE_ELEMENT_NOT_PRESENT_ON_LHS;
Object expectedArg = "b";
Object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg, expectedArg2);
checkError(equeue, expectedMessage);
}
示例8: testUnknownToken
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testUnknownToken() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
String grammar =
"grammar T;\n" +
"options {output=AST;}\n" +
"a : INT -> ICK ;\n" +
"ID : 'a'..'z'+ ;\n" +
"INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";
Grammar g = new Grammar(grammar);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
int expectedMsgID = ErrorManager.MSG_UNDEFINED_TOKEN_REF_IN_REWRITE;
Object expectedArg = "ICK";
Object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg, expectedArg2);
checkError(equeue, expectedMessage);
}
示例9: testUnknownLabel
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testUnknownLabel() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
String grammar =
"grammar T;\n" +
"options {output=AST;}\n" +
"a : INT -> $foo ;\n" +
"ID : 'a'..'z'+ ;\n" +
"INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";
Grammar g = new Grammar(grammar);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
int expectedMsgID = ErrorManager.MSG_UNDEFINED_LABEL_REF_IN_REWRITE;
Object expectedArg = "foo";
Object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg, expectedArg2);
checkError(equeue, expectedMessage);
}
示例10: testUnknownCharLiteralToken
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testUnknownCharLiteralToken() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
String grammar =
"grammar T;\n" +
"options {output=AST;}\n" +
"a : INT -> 'a' ;\n" +
"ID : 'a'..'z'+ ;\n" +
"INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";
Grammar g = new Grammar(grammar);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
int expectedMsgID = ErrorManager.MSG_UNDEFINED_TOKEN_REF_IN_REWRITE;
Object expectedArg = "'a'";
Object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg, expectedArg2);
checkError(equeue, expectedMessage);
}
示例11: testUnknownStringLiteralToken
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
public void testUnknownStringLiteralToken() throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
String grammar =
"grammar T;\n" +
"options {output=AST;}\n" +
"a : INT -> 'foo' ;\n" +
"ID : 'a'..'z'+ ;\n" +
"INT : '0'..'9'+;\n" +
"WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";
Grammar g = new Grammar(grammar);
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
int expectedMsgID = ErrorManager.MSG_UNDEFINED_TOKEN_REF_IN_REWRITE;
Object expectedArg = "'foo'";
Object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg, expectedArg2);
checkError(equeue, expectedMessage);
}
示例12: run
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
ErrorManager.resetErrorState();
ErrorManager.setErrorListener(this);
writeMessage("Compile: " + iAntLRSourceFile.getLocationURI().toString());
Tool antLRCompiler;
antLRCompiler = new Tool(new String[] {new File(iAntLRSourceFile.getLocationURI()).getAbsolutePath()});
antLRCompiler.process();
if (ErrorManager.getNumErrors() == 0) {
writeMessage("Compile AntLR grammar was executed.");
MessageDialog.openInformation(shell,
"ParserTools",
"Compile AntLR grammar was executed.");
} else {
writeMessage("Cannot compile AntLT grammar");
}
try {
iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
}
}
示例13: parseImpl
import org.antlr.tool.ErrorManager; //导入方法依赖的package包/类
@Override
protected CompiledModelV3 parseImpl(ParserTaskManager taskManager, ParseContext context, DocumentSnapshot snapshot)
throws InterruptedException, ExecutionException {
Parameters.notNull("snapshot", snapshot);
synchronized (lock) {
if (snapshot.equals(lastSnapshot)) {
if (lastException != null) {
throw new ExecutionException("An unexpected error occurred.", lastException);
}
return new CompiledModelV3(snapshot, lastResult);
}
ANTLRStringStream input = new ANTLRStringStream(snapshot.getText().toString());
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));
try {
ErrorManager.setErrorListener(new ANTLRErrorProvidingParser.ErrorListener(snapshot));
Tool tool = new Tool();
tool.setLibDirectory(new File(snapshot.getVersionedDocument().getFileObject().getPath()).getParent());
GrammarWrapper g = new GrammarWrapper(tool, snapshot);
g.setFileName(""); // work around a bug in Grammar.setName that results in a NPE
ANTLRParser.grammar__return result = parser.grammar_(g);
List<? extends Token> tokenList = tokenStream.getTokens();
CommonToken[] tokens = new CommonToken[tokenList.size()];
tokens = tokenList.toArray(tokens);
CompiledFileModelV3 currentResult = new CompiledFileModelV3(parser, g, result, snapshot.getVersionedDocument().getFileObject(), tokens);
lastSnapshot = snapshot;
lastResult = currentResult;
lastException = null;
return new CompiledModelV3(snapshot, currentResult);
} catch (RecognitionException | RuntimeException | Error ex) {
lastSnapshot = snapshot;
lastResult = null;
lastException = ex;
throw new ExecutionException("An unexpected error occurred.", ex);
} finally {
ErrorManager.setErrorListener(null);
}
}
}