当前位置: 首页>>代码示例>>Java>>正文


Java ErrorManager.setErrorListener方法代码示例

本文整理汇总了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());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:21,代码来源:TestRewriteTemplates.java

示例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());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:22,代码来源:TestRewriteTemplates.java

示例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());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:19,代码来源:TestRewriteTemplates.java

示例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());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:20,代码来源:TestRewriteTemplates.java

示例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());		
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:22,代码来源:TestRewriteAST.java

示例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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:28,代码来源:TestRewriteAST.java

示例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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:29,代码来源:TestRewriteAST.java

示例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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:28,代码来源:TestRewriteAST.java

示例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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:28,代码来源:TestRewriteAST.java

示例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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:28,代码来源:TestRewriteAST.java

示例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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:28,代码来源:TestRewriteAST.java

示例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) {

	}
}
 
开发者ID:asupdev,项目名称:asup,代码行数:32,代码来源:CompileAntLR.java

示例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);
        }
    }

}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:52,代码来源:CompiledModelParserV3.java


注:本文中的org.antlr.tool.ErrorManager.setErrorListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。