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


Java Tool类代码示例

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


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

示例1: testRewriteRuleAndRewriteModeOnSimpleElements

import org.antlr.Tool; //导入依赖的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; //导入依赖的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: testRewriteRuleAndRewriteModeRefRule

import org.antlr.Tool; //导入依赖的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

示例4: testRefToRuleWithNoReturnValue

import org.antlr.Tool; //导入依赖的package包/类
public void testRefToRuleWithNoReturnValue() throws Exception {
	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);

	String grammarStr =
		"grammar P;\n" +
		"a : x=b ;\n" +
		"b : B ;\n" +
		"B : 'b' ;\n";
	Grammar g = new Grammar(grammarStr);

	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	StringTemplate recogST = generator.genRecognizer();
	String code = recogST.toString();
	assertTrue("not expecting label", code.indexOf("x=b();")<0);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:21,代码来源:TestSymbolDefinitions.java

示例5: testBadGrammarOption

import org.antlr.Tool; //导入依赖的package包/类
public void testBadGrammarOption() throws Exception {
	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue); // unique listener per thread
	Tool antlr = newTool();
	Grammar g = new Grammar(antlr,
							"t",
							new StringReader(
								"grammar t;\n"+
								"options {foo=3; language=Java;}\n" +
								"a : 'a';\n"));

	Object expectedArg = "foo";
	int expectedMsgID = ErrorManager.MSG_ILLEGAL_OPTION;
	GrammarSemanticsMessage expectedMessage =
		new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg);
	checkError(equeue, expectedMessage);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:18,代码来源:TestSymbolDefinitions.java

示例6: testEscapedLessThanInAction

import org.antlr.Tool; //导入依赖的package包/类
public void testEscapedLessThanInAction() throws Exception {
	Grammar g = new Grammar();
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	String action = "i<3; '<xmltag>'";
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),0);
	String expecting = action;
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, "<action>");
	actionST.setAttribute("action", rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:18,代码来源:TestAttributes.java

示例7: testIllegalAssignToOwnRulenameAttr

import org.antlr.Tool; //导入依赖的package包/类
public void testIllegalAssignToOwnRulenameAttr() throws Exception {
	String action = "$rule.stop = 0;";
	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar a;\n" +
		"rule\n" +
		"    : 'y' {" + action +"}\n" +
		"    ;");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,
																 "rule",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();

	int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
	Object expectedArg = "rule";
	Object expectedArg2 = "stop";
	GrammarSemanticsMessage expectedMessage =
		new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg, expectedArg2);
	checkError(equeue, expectedMessage);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java

示例8: testRuleLabels

import org.antlr.Tool; //导入依赖的package包/类
public void testRuleLabels() throws Exception {
	String action = "$r.x; $r.start; $r.stop; $r.tree; $a.x; $a.stop;";
	String expecting = "r.x; ((Token)r.start); ((Token)r.stop); ((Object)r.tree); r.x; ((Token)r.stop);";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"parser grammar t;\n"+
			"a returns [int x]\n" +
			"  :\n" +
			"  ;\n"+
			"b : r=a {###"+action+"!!!}\n" +
			"  ;");
	Tool antlr = newTool();
	antlr.setOutputDirectory(null); // write to /dev/null
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // codegen phase sets some vars we need
	StringTemplate codeST = generator.getRecognizerST();
	String code = codeST.toString();
	String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!"));
	assertEquals(expecting, found);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:26,代码来源:TestAttributes.java

示例9: testForwardRefRuleLabels

import org.antlr.Tool; //导入依赖的package包/类
public void testForwardRefRuleLabels() throws Exception {
	String action = "$r.x; $r.start; $r.stop; $r.tree; $a.x; $a.tree;";
	String expecting = "r.x; ((Token)r.start); ((Token)r.stop); ((Object)r.tree); r.x; ((Object)r.tree);";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"parser grammar t;\n"+
			"b : r=a {###"+action+"!!!}\n" +
			"  ;\n" +
			"a returns [int x]\n" +
			"  : ;\n");
	Tool antlr = newTool();
	antlr.setOutputDirectory(null); // write to /dev/null
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // codegen phase sets some vars we need

	StringTemplate codeST = generator.getRecognizerST();
	String code = codeST.toString();
	String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!"));
	assertEquals(expecting, found);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:26,代码来源:TestAttributes.java

示例10: testMissingUnlabeledRuleAttribute

import org.antlr.Tool; //导入依赖的package包/类
public void testMissingUnlabeledRuleAttribute() throws Exception {
	String action = "$a";
	String expecting = action;

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"parser grammar t;\n"+
			"a returns [int x]:\n" +
			"  ;\n"+
			"b : a {"+action+"}\n" +
			"  ;");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator, "b",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();

	int expectedMsgID = ErrorManager.MSG_ISOLATED_RULE_SCOPE;
	Object expectedArg = "a";
	GrammarSemanticsMessage expectedMessage =
		new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg);
	checkError(equeue, expectedMessage);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:26,代码来源:TestAttributes.java

示例11: testUnknownGlobalScope

import org.antlr.Tool; //导入依赖的package包/类
public void testUnknownGlobalScope() throws Exception {
	String action = "$Symbols::names.add($id.text);";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
		"a scope Symbols; : (id=ID ';' {"+action+"} )+\n" +
		"  ;\n" +
		"ID : 'a';\n");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);

	assertEquals("unexpected errors: "+equeue, 2, equeue.errors.size());

	int expectedMsgID = ErrorManager.MSG_UNKNOWN_DYNAMIC_SCOPE;
	Object expectedArg = "Symbols";
	GrammarSemanticsMessage expectedMessage =
		new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg);
	checkError(equeue, expectedMessage);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:26,代码来源:TestAttributes.java

示例12: testAmbiguousTokenRefWithProp

import org.antlr.Tool; //导入依赖的package包/类
public void testAmbiguousTokenRefWithProp() throws Exception {
	String action = "$ID.text;";
	String expecting = "";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
			"a : ID ID {"+action+"};" +
			"ID : 'a';\n");
	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_NONUNIQUE_REF;
	Object expectedArg = "ID";
	GrammarSemanticsMessage expectedMessage =
		new GrammarSemanticsMessage(expectedMsgID, g, null, expectedArg);
	checkError(equeue, expectedMessage);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:23,代码来源:TestAttributes.java

示例13: testFullyQualifiedRefToCurrentRuleParameter

import org.antlr.Tool; //导入依赖的package包/类
public void testFullyQualifiedRefToCurrentRuleParameter() throws Exception {
	String action = "$a.i;";
	String expecting = "i;";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
			"a[int i]: {"+action+"}\n" +
			"  ;\n");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java

示例14: testTokenRefTreeProperty

import org.antlr.Tool; //导入依赖的package包/类
public void testTokenRefTreeProperty() throws Exception {
	String action = "$ID.tree;";
	String expecting = "ID1_tree;";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
			"a : ID {"+action+"} ;" +
			"ID : 'a';\n");
	Tool antlr = newTool();
	antlr.setOutputDirectory(null); // write to /dev/null
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer();

	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java

示例15: testSetFullyQualifiedRefToCurrentRuleRetVal

import org.antlr.Tool; //导入依赖的package包/类
public void testSetFullyQualifiedRefToCurrentRuleRetVal() throws Exception {
	String action = "$a.i = 1;";
	String expecting = "retval.i = 1;";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
		"a returns [int i, int j]: {"+action+"}\n" +
		"  ;\n");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java


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