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 ); }
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() ); }