本文整理汇总了C#中Antlr3.Tool.GrammarSemanticsMessage类的典型用法代码示例。如果您正苦于以下问题:C# GrammarSemanticsMessage类的具体用法?C# GrammarSemanticsMessage怎么用?C# GrammarSemanticsMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GrammarSemanticsMessage类属于Antlr3.Tool命名空间,在下文中一共展示了GrammarSemanticsMessage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestBadGrammarOption
public void TestBadGrammarOption()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue ); // unique listener per thread
AntlrTool antlr = newTool();
Grammar g = new Grammar( antlr,
"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 );
checkGrammarSemanticsError( equeue, expectedMessage );
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:16,代码来源:TestSymbolDefinitions.cs
示例2: TestNonDynamicAttributeOutsideRule
public void TestNonDynamicAttributeOutsideRule()
{
string action = "[TestMethod] public void foo() { $x; }";
string expecting = action;
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"parser grammar t;\n" +
"@members {'+action+'}\n" +
"a : ;\n" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
ActionTranslator translator = new ActionTranslator( generator,
null,
new CommonToken( ANTLRParser.ACTION, action ), 0 );
string rawTranslation =
translator.Translate();
StringTemplateGroup templates =
new StringTemplateGroup( ".", typeof( AngleBracketTemplateLexer ) );
StringTemplate actionST = new StringTemplate( templates, rawTranslation );
string found = actionST.ToString();
assertEquals( expecting, found );
int expectedMsgID = ErrorManager.MSG_ATTRIBUTE_REF_NOT_IN_RULE;
object expectedArg = "x";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
checkError( equeue, expectedMessage );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:30,代码来源:TestAttributes.cs
示例3: GrammarWarning
public static void GrammarWarning( int msgID,
Grammar g,
IToken token,
Object arg,
Object arg2 )
{
GetErrorState().warnings++;
Message msg = new GrammarSemanticsMessage( msgID, g, token, arg, arg2 );
GetErrorState().warningMsgIDs.Add( msgID );
GetErrorListener().Warning( msg );
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:11,代码来源:ErrorManager.cs
示例4: checkError
//throws Exception
protected void checkError( ErrorQueue equeue,
GrammarSemanticsMessage expectedMessage )
{
/*
System.out.println(equeue.infos);
System.out.println(equeue.warnings);
System.out.println(equeue.errors);
*/
Message foundMsg = null;
for ( int i = 0; i < equeue.errors.Count; i++ )
{
Message m = (Message)equeue.errors[i];
if ( m.msgID == expectedMessage.msgID )
{
foundMsg = m;
}
}
Assert.IsTrue(equeue.errors.Count > 0, "no error; " + expectedMessage.msgID + " expected");
Assert.IsTrue(equeue.errors.Count <= 1, "too many errors; " + equeue.errors);
Assert.IsTrue(foundMsg != null, "couldn't find expected error: " + expectedMessage.msgID);
Assert.IsTrue(foundMsg is GrammarSemanticsMessage, "error is not a GrammarSemanticsMessage");
Assert.AreEqual( expectedMessage.arg, foundMsg.arg );
Assert.AreEqual( expectedMessage.arg2, foundMsg.arg2 );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:25,代码来源:TestTemplates.cs
示例5: 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 );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:21,代码来源:TestAttributes.cs
示例6: 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 );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:27,代码来源:TestAttributes.cs
示例7: TestUnknownGlobalDynamicAttribute
public void TestUnknownGlobalDynamicAttribute()
{
string action = "$Symbols::x";
string expecting = action;
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"scope Symbols {\n" +
" int n;\n" +
"}\n" +
"a : {'+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);
int expectedMsgID = ErrorManager.MSG_UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE;
object expectedArg = "Symbols";
object expectedArg2 = "x";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:32,代码来源:TestAttributes.cs
示例8: TestArgsOnTokenInLexerRuleOfCombined
public void TestArgsOnTokenInLexerRuleOfCombined()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"a : R;\n" +
"R : 'z' ID[32] ;\n" +
"ID : 'a';\n" );
string lexerGrammarStr = g.GetLexerGrammar();
System.IO.StringReader sr = new System.IO.StringReader( lexerGrammarStr );
Grammar lexerGrammar = new Grammar();
lexerGrammar.FileName = "<internally-generated-lexer>";
lexerGrammar.ImportTokenVocabulary( g );
lexerGrammar.ParseAndBuildAST( sr );
lexerGrammar.DefineGrammarSymbols();
lexerGrammar.CheckNameSpaceAndActions();
sr.Close();
AntlrTool antlr = newTool();
antlr.SetOutputDirectory( null ); // write to /dev/null
CodeGenerator generator = new CodeGenerator( antlr, lexerGrammar, "Java" );
lexerGrammar.CodeGenerator = generator;
generator.GenRecognizer();
int expectedMsgID = ErrorManager.MSG_RULE_HAS_NO_ARGS;
object expectedArg = "ID";
object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, lexerGrammar, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:33,代码来源:TestAttributes.cs
示例9: TestIsolatedRefToRule
public void TestIsolatedRefToRule()
{
string action = "$x;";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"a : x=b {" + action + "}\n" +
" ;\n" +
"b : 'b' ;\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_SCOPE;
object expectedArg = "x";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:22,代码来源:TestAttributes.cs
示例10: TestInvalidRuleLabelAccessesScopeAttribute
public void TestInvalidRuleLabelAccessesScopeAttribute()
{
string action = "$r.n";
string expecting = action;
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"parser grammar t;\n" +
"a\n" +
"scope { int n; }\n" +
" :\n" +
" ;\n" +
"b : r=a[3] {" + action + "}\n" +
" ;" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
ActionTranslator translator = new ActionTranslator( generator, "b",
new CommonToken( ANTLRParser.ACTION, action ), 1 );
string found = translator.Translate();
Assert.AreEqual(expecting, found);
int expectedMsgID = ErrorManager.MSG_INVALID_RULE_SCOPE_ATTRIBUTE_REF;
object expectedArg = "a";
object expectedArg2 = "n";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:29,代码来源:TestAttributes.cs
示例11: TestInvalidReturnValues
public void TestInvalidReturnValues()
{
string action = "$x";
string expecting = action;
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"parser grammar t;\n" +
"a returns [User u, int i]\n" +
" : {" + action + "}\n" +
" ;" );
AntlrTool antlr = newTool();
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
ActionTranslator translator = new ActionTranslator( generator, "a",
new CommonToken( ANTLRParser.ACTION, action ), 1 );
string found = translator.Translate();
Assert.AreEqual(expecting, found);
int expectedMsgID = ErrorManager.MSG_UNKNOWN_SIMPLE_ATTRIBUTE;
object expectedArg = "x";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:25,代码来源:TestAttributes.cs
示例12: TestIllegalAssignToOwnRulenameAttr
public void TestIllegalAssignToOwnRulenameAttr()
{
string action = "$rule.stop = 0;";
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 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:JSchofield,项目名称:antlrcs,代码行数:27,代码来源:TestAttributes.cs
示例13: TestIllegalAssignToLocalAttr
public void TestIllegalAssignToLocalAttr()
{
string action = "$tree = null; $st = null; $start = 0; $stop = 0; $text = 0;";
string expecting = "retval.tree = null; retval.st = 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 rawTranslation =
translator.Translate();
int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
var expectedErrors = new List<object>( 3 );
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, "start", "" );
expectedErrors.Add( expectedMessage );
GrammarSemanticsMessage expectedMessage2 =
new GrammarSemanticsMessage( expectedMsgID, g, null, "stop", "" );
expectedErrors.Add( expectedMessage2 );
GrammarSemanticsMessage expectedMessage3 =
new GrammarSemanticsMessage( expectedMsgID, g, null, "text", "" );
expectedErrors.Add( expectedMessage3 );
checkErrors( equeue, expectedErrors );
StringTemplateGroup templates =
new StringTemplateGroup();
StringTemplate actionST = new StringTemplate( templates, rawTranslation );
string found = actionST.Render();
Assert.AreEqual( expecting, found );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:40,代码来源:TestAttributes.cs
示例14: checkError
//throws Exception
// S U P P O R T
protected void checkError( ErrorQueue equeue,
GrammarSemanticsMessage expectedMessage )
{
/*
System.out.println(equeue.infos);
System.out.println(equeue.warnings);
System.out.println(equeue.errors);
*/
Message foundMsg = null;
for ( int i = 0; i < equeue.errors.Count; i++ )
{
Message m = (Message)equeue.errors[i];
if ( m.msgID == expectedMessage.msgID )
{
foundMsg = m;
}
}
assertTrue( "no error; " + expectedMessage.msgID + " expected", equeue.errors.Count > 0 );
assertNotNull( "couldn't find expected error: " + expectedMessage.msgID + " in " + equeue, foundMsg );
assertTrue( "error is not a GrammarSemanticsMessage",
foundMsg is GrammarSemanticsMessage );
assertEquals( expectedMessage.arg, foundMsg.arg );
assertEquals( expectedMessage.arg2, foundMsg.arg2 );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:26,代码来源:TestAttributes.cs
示例15: TestUnknownDynamicAttribute
public void TestUnknownDynamicAttribute()
{
string action = "$a::x";
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
ActionTranslator translator =
new ActionTranslator( generator,
"a",
new CommonToken( ANTLRParser.ACTION, action ), 1 );
string rawTranslation =
translator.Translate();
StringTemplateGroup templates =
new StringTemplateGroup( ".", typeof( AngleBracketTemplateLexer ) );
StringTemplate actionST = new StringTemplate( templates, rawTranslation );
string found = actionST.ToString();
assertEquals( expecting, found );
int expectedMsgID = ErrorManager.MSG_UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE;
object expectedArg = "a";
object expectedArg2 = "x";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:37,代码来源:TestAttributes.cs
示例16: TestArgsOnToken
public void TestArgsOnToken()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"a : ID[32,34] ;" +
"ID : '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_ARGS_ON_TOKEN_REF;
object expectedArg = "ID";
object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:21,代码来源:TestAttributes.cs
示例17: TestRuleLabelWithoutOutputOption
public void TestRuleLabelWithoutOutputOption()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar T;\n" +
"s : x+=a ;" +
"a : 'a';\n" +
"b : 'b';\n" +
"WS : ' '|'\n';\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_LIST_LABEL_INVALID_UNLESS_RETVAL_STRUCT;
object expectedArg = "x";
object expectedArg2 = null;
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:23,代码来源:TestAttributes.cs
示例18: TestListAndRuleLabelTypeMismatch
public void TestListAndRuleLabelTypeMismatch()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"grammar t;\n" +
"options {output=AST;}\n" +
"a : bs+=b bs=b\n" +
" ;\n" +
"b : 'b';\n" );
int expectedMsgID = ErrorManager.MSG_LABEL_TYPE_CONFLICT;
object expectedArg = "bs";
object expectedArg2 = "rule!=rule-list";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:17,代码来源:TestAttributes.cs
示例19: TestTreeRuleStopAttributeIsInvalid
public void TestTreeRuleStopAttributeIsInvalid()
{
string action = "$r.x; $r.start; $r.stop";
string expecting = "(r!=null?r.x:0); (r!=null?((CommonTree)r.start):null); $r.stop";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"tree grammar t;\n" +
"options {ASTLabelType=CommonTree;}\n" +
"a returns [int x]\n" +
" :\n" +
" ;\n" +
"b : r=a {###" + action + "!!!}\n" +
" ;" );
AntlrTool antlr = newTool();
antlr.SetOutputDirectory( null ); // write to /dev/null
CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
g.CodeGenerator = generator;
generator.GenRecognizer(); // codegen phase sets some vars we need
StringTemplate codeST = generator.RecognizerST;
string code = codeST.Render();
int startIndex = code.IndexOf("###") + 3;
int endIndex = code.IndexOf("!!!");
string found = code.Substring(startIndex, endIndex - startIndex);
Assert.AreEqual( expecting, found );
int expectedMsgID = ErrorManager.MSG_UNKNOWN_RULE_ATTRIBUTE;
object expectedArg = "a";
object expectedArg2 = "stop";
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
Console.Out.WriteLine( "equeue:" + equeue );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:35,代码来源:TestAttributes.cs
示例20: TestMissingArgsInLexer
public void TestMissingArgsInLexer()
{
ErrorQueue equeue = new ErrorQueue();
ErrorManager.SetErrorListener( equeue );
Grammar g = new Grammar(
"lexer grammar t;\n" +
"A : R ;" +
"R[int i] : '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_MISSING_RULE_ARGS;
object expectedArg = "R";
object expectedArg2 = null;
// getting a second error @1:12, probably from nextToken
GrammarSemanticsMessage expectedMessage =
new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
checkError( equeue, expectedMessage );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:22,代码来源:TestAttributes.cs
注:本文中的Antlr3.Tool.GrammarSemanticsMessage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论