本文整理汇总了C#中Antlr3.Codegen.CodeGenerator.GenRecognizer方法的典型用法代码示例。如果您正苦于以下问题:C# Antlr3.Codegen.CodeGenerator.GenRecognizer方法的具体用法?C# Antlr3.Codegen.CodeGenerator.GenRecognizer怎么用?C# Antlr3.Codegen.CodeGenerator.GenRecognizer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Codegen.CodeGenerator
的用法示例。
在下文中一共展示了Antlr3.Codegen.CodeGenerator.GenRecognizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMessageStringificationIsConsistent
public void TestMessageStringificationIsConsistent()
{
string action = "$other.tree = null;";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar a;\n" +
"options { output = AST;}" +
"otherrule\n" +
" : 'y' ;" +
"rule\n" +
" : other=otherrule {" + action + "}\n" +
" ;" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
ActionTranslator translator = new ActionTranslator( generator,
"rule",
new CommonToken( ANTLRParser.ACTION, action ), 1 );
string rawTranslation =
translator.Translate();
int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
object expectedArg = "other";
object expectedArg2 = "tree";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
string expectedMessageString = expectedMessage.ToString();
Assert.AreEqual( expectedMessageString, expectedMessage.ToString() );
}
示例2: TestUnqualifiedRuleScopeAccessInsideRule
public void TestUnqualifiedRuleScopeAccessInsideRule()
{
string action = "$n;";
string expecting = action;
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"a\n" +
"scope {\n" +
" int n;\n" +
"} : {" + action + "}\n" +
" ;\n" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
int expectedMsgID = ErrorManager.MSG_ISOLATED_RULE_ATTRIBUTE;
object expectedArg = "n";
object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg,
expectedArg2 );
checkError( equeue, expectedMessage );
}
示例3: TestCannotHaveSpaceBeforeDot
public void TestCannotHaveSpaceBeforeDot()
{
string action = "%x .y = z;";
//String expecting = null;
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"options {\n" +
" output=template;\n" +
"}\n" +
"\n" +
"a : ID {" + action + "}\n" +
" ;\n" +
"\n" +
"ID : 'a';\n" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
int expectedMsgID = ErrorManager.MSG_INVALID_TEMPLATE_ACTION;
object expectedArg = "%x";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
checkError( equeue, expectedMessage );
}
示例4: TestSetAttrOfExprInMembers
public void TestSetAttrOfExprInMembers()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"options {\n" +
" output=template;\n" +
"}\n" +
"@members {\n" +
"%code.instr = o;" + // must not get null ptr!
"}\n" +
"a : ID\n" +
" ;\n" +
"\n" +
"ID : 'a';\n" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
assertNoErrors( equeue );
}
示例5: TestRewriteRuleAndRewriteModeRefRule
public void TestRewriteRuleAndRewriteModeRefRule()
{
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"
);
AntlrTool antlr = newTool();
antlr.SetOutputDirectory( null ); // write to /dev/null
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer();
Assert.AreEqual(0, equeue.warnings.Count, "unexpected errors: " + equeue);
}
示例6: TestNoWildcardAsRootError
public void TestNoWildcardAsRootError()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
string treeGrammar =
"tree grammar TP;\n" +
"options {output=AST;}\n" +
"a : ^(. INT) \n" +
" ;\n";
Grammar g = new Grammar( treeGrammar );
AntlrTool antlr = newTool();
antlr.SetOutputDirectory( null ); // write to /dev/null
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer();
assertEquals( "unexpected errors: " + equeue, 1, equeue.errors.Count );
int expectedMsgID = ErrorManager.MSG_WILDCARD_AS_ROOT;
object expectedArg = null;
RecognitionException expectedExc = null;
GrammarSyntaxMessage expectedMessage =
new GrammarSyntaxMessage( expectedMsgID, g, null, expectedArg, expectedExc );
checkError( equeue, expectedMessage );
}
示例7: TestWeirdRuleRef
public void TestWeirdRuleRef()
{
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 );
AntlrTool antlr = newTool();
antlr.SetOutputDirectory( null ); // write to /dev/null
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer();
// $a is ambig; is it previous root or ref to a ref in alt?
Assert.AreEqual(1, equeue.errors.Count, "unexpected errors: " + equeue);
}
示例8: TestFullyQualifiedRefToCurrentRuleParameter
public void TestFullyQualifiedRefToCurrentRuleParameter()
{
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" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
ActionTranslator translator = new ActionTranslator( generator, "a",
new CommonToken( ANTLRParser.ACTION, action ), 1 );
string found = translator.Translate();
Assert.AreEqual(expecting, found);
Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
}
示例9: TestCharListLabelInLexer
public void TestCharListLabelInLexer()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"lexer grammar t;\n" +
"R : x+='z' ;\n" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
}
示例10: TestBracketArgParsing
public void TestBracketArgParsing()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
// now check in actual grammar.
Grammar g = new Grammar(
"parser grammar t;\n" +
"a[String[\\] ick, int i]\n" +
" : A \n" +
" ;" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
Rule r = g.GetRule( "a" );
AttributeScope parameters = r.ParameterScope;
var attrs = parameters.Attributes;
Assert.AreEqual("String[] ick", attrs.ElementAt(0).Decl.ToString(), "attribute mismatch");
Assert.AreEqual("ick", attrs.ElementAt(0).Name, "parameter name mismatch");
Assert.AreEqual("String[]", attrs.ElementAt(0).Type, "declarator mismatch");
Assert.AreEqual("int i", attrs.ElementAt(1).Decl.ToString(), "attribute mismatch");
Assert.AreEqual("i", attrs.ElementAt(1).Name, "parameter name mismatch");
Assert.AreEqual("int", attrs.ElementAt(1).Type, "declarator mismatch");
Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
}
示例11: TestAssignToTreeNodeAttribute
public void TestAssignToTreeNodeAttribute()
{
//string action = "$tree.scope = localScope;";
string expecting = "((Object)retval.tree).scope = localScope;";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar a;\n" +
"options { output=AST; }" +
"rule\n" +
"@init {\n" +
" Scope localScope=null;\n" +
"}\n" +
"@after {\n" +
" ###$tree.scope = localScope;!!!\n" +
"}\n" +
" : 'a' -> ^('a')\n" +
";" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
StringTemplate codeST = generator.RecognizerST;
string code = codeST.Render();
string found = code.Substring(code.IndexOf("###") + 3, code.IndexOf("!!!") - code.IndexOf("###") - 3);
Assert.AreEqual(expecting, found);
}
示例12: TestAssignToOwnRulenameAttr
public void TestAssignToOwnRulenameAttr()
{
string action = "$rule.tree = null;";
string expecting = "retval.tree = null;";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar a;\n" +
"rule\n" +
" : 'y' {" + action + "}\n" +
" ;" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
ActionTranslator translator = new ActionTranslator( generator,
"rule",
new CommonToken( ANTLRParser.ACTION, action ), 1 );
string found = translator.Translate();
Assert.AreEqual(expecting, found);
Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
}
示例13: TestArguments
public void TestArguments()
{
string action = "$i; $i.x; $u; $u.x";
string expecting = "i; i.x; u; u.x";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"parser grammar t;\n" +
"a[User u, int i]\n" +
" : {" + action + "}\n" +
" ;" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // forces load of templates
ActionTranslator translator = new ActionTranslator( generator, "a",
new CommonToken( ANTLRParser.ACTION, action ), 1 );
string found = translator.Translate();
Assert.AreEqual(expecting, found);
Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
}
示例14: TestArgsWithInitValues
public void TestArgsWithInitValues()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"a : r[32,34] ;" +
"r[int x, int y=3] : 'a';\n" );
AntlrTool antlr = newTool();
antlr.SetOutputDirectory( null ); // write to /dev/null
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer();
int expectedMsgID = ErrorManager.MSG_ARG_INIT_VALUES_ILLEGAL;
object expectedArg = "y";
object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
示例15: TestArgsWhenNoneDefined
public void TestArgsWhenNoneDefined()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"a : r[32,34] ;" +
"r : 'a';\n" );
AntlrTool antlr = newTool();
antlr.SetOutputDirectory( null ); // write to /dev/null
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer();
int expectedMsgID = ErrorManager.MSG_RULE_HAS_NO_ARGS;
object expectedArg = "r";
object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}