本文整理汇总了C#中Antlr3.Tool.Grammar.GetLexerGrammar方法的典型用法代码示例。如果您正苦于以下问题:C# Grammar.GetLexerGrammar方法的具体用法?C# Grammar.GetLexerGrammar怎么用?C# Grammar.GetLexerGrammar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Tool.Grammar
的用法示例。
在下文中一共展示了Grammar.GetLexerGrammar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 );
}
示例2: TestLiteralInParserAndLexer
public void TestLiteralInParserAndLexer()
{
// 'x' is token and char in lexer rule
Grammar g = new Grammar(
"grammar t;\n" +
"a : 'x' E ; \n" +
"E: 'x' '0' ;\n" ); // nor is 'c'
//String literals = "['x']";
string[] literals = new string[] { "'x'" };
var foundLiterals = g.StringLiterals;
Assert.IsTrue( literals.SequenceEqual(foundLiterals) );
string implicitLexer =
"lexer grammar t;" + NewLine +
"T__5 : 'x' ;" + NewLine +
"" + NewLine +
"// $ANTLR src \"<string>\" 3" + NewLine +
"E: 'x' '0' ;";
Assert.AreEqual( implicitLexer, g.GetLexerGrammar() );
}