本文整理汇总了C#中Antlr3.Tool.GrammarSemanticsMessage类的典型用法代码示例。如果您正苦于以下问题:C# GrammarSemanticsMessage类的具体用法?C# GrammarSemanticsMessage怎么用?C# GrammarSemanticsMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GrammarSemanticsMessage类属于Antlr3.Tool命名空间,在下文中一共展示了GrammarSemanticsMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}
示例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 );
}