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


Java ErrorManager类代码示例

本文整理汇总了Java中org.antlr.tool.ErrorManager的典型用法代码示例。如果您正苦于以下问题:Java ErrorManager类的具体用法?Java ErrorManager怎么用?Java ErrorManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ErrorManager类属于org.antlr.tool包,在下文中一共展示了ErrorManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkError

import org.antlr.tool.ErrorManager; //导入依赖的package包/类
protected void checkError(ErrorQueue equeue,
						  GrammarSemanticsMessage expectedMessage)
	throws Exception
{
	//System.out.println("errors="+equeue);
	Message foundMsg = null;
	for (int i = 0; i < equeue.errors.size(); i++) {
		Message m = (Message)equeue.errors.get(i);
		if (m.msgID==expectedMessage.msgID ) {
			foundMsg = m;
		}
	}
	assertTrue("no error; "+expectedMessage.msgID+" expected", equeue.errors.size()>0);
	assertTrue("too many errors; "+equeue.errors, equeue.errors.size()<=1);
	assertNotNull("couldn't find expected error: "+expectedMessage.msgID, foundMsg);
	assertTrue("error is not a GrammarSemanticsMessage",
			   foundMsg instanceof GrammarSemanticsMessage);
	assertEquals(expectedMessage.arg, foundMsg.arg);
	assertEquals(expectedMessage.arg2, foundMsg.arg2);
	ErrorManager.resetErrorState(); // wack errors for next test
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:22,代码来源:TestRewriteAST.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: addTransition

import org.antlr.tool.ErrorManager; //导入依赖的package包/类
public void addTransition(Transition e) {
	if ( e==null ) {
		throw new IllegalArgumentException("You can't add a null transition");			
	}
	if ( numTransitions>transition.length ) {
		throw new IllegalArgumentException("You can only have "+transition.length+" transitions");
	}
	if ( e!=null ) {
		transition[numTransitions] = e;
		numTransitions++;
		// Set the "back pointer" of the target state so that it
		// knows about the label of the incoming edge.
		Label label = e.label;
		if ( label.isAtom() || label.isSet() ) {
			if ( ((NFAState)e.target).incidentEdgeLabel!=null ) {
				ErrorManager.internalError("Clobbered incident edge");
			}
			((NFAState)e.target).incidentEdgeLabel = e.label;
		}
	}
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:22,代码来源:NFAState.java

示例7: 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

示例8: size

import org.antlr.tool.ErrorManager; //导入依赖的package包/类
public int size() {
     if ( elements.size()!=super.size() ) {
ErrorManager.internalError("OrderedHashSet: elements and set size differs; "+
						   elements.size()+"!="+super.size());
     }
     return elements.size();
 }
 
开发者ID:Sable,项目名称:mclab-core,代码行数:8,代码来源:OrderedHashSet.java

示例9: run

import org.antlr.tool.ErrorManager; //导入依赖的package包/类
public void run() {
	for (int decision=i; decision<=j; decision++) {
		NFAState decisionStartState = grammar.getDecisionNFAStartState(decision);
		if ( decisionStartState.getNumberOfTransitions()>1 ) {
			grammar.createLookaheadDFA(decision);
		}
	}
	// now wait for others to finish
	try {
		barrier.waitForRelease();
	}
	catch(InterruptedException e) {
		ErrorManager.internalError("what the hell? DFA interruptus", e);
	}
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:16,代码来源:NFAConversionThread.java

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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