195196197198199200201202203204205
/** * This is a regression test for antlr/antlr4#461. * https://github.com/antlr/antlr4/issues/461 */ @Test public void testLeftRecursiveStartRule() throws Exception { LexerGrammar lg = new LexerGrammar( "lexer grammar L;\n" + "A : 'a' ;\n" + "B : 'b' ;\n" + "C : 'c' ;\n" + "PLUS : '+' ;\n" +
6869707172737475767778
String tokenNames = "A, B, C, D"; checkSymbols(g, rules, tokenNames); } @Test public void testLexerTokensSection() throws Exception { LexerGrammar g = new LexerGrammar( "lexer grammar t;\n" + "tokens {\n" + " C,\n" + " D" + "}\n"+
104105106107108109110111112113114
"s3->RuleStop_a_1\n" + "RuleStop_a_1-EOF->s4\n"; checkRuleATN(g, "a", expecting); } @Test public void testLexerIsntSetMultiCharString() throws Exception { LexerGrammar g = new LexerGrammar( "lexer grammar P;\n"+ "A : ('0x' | '0X') ;"); String expecting = "s0->RuleStart_A_1\n" + "RuleStart_A_1->BlockStart_7\n" +
120121122123124125126127128129130
"s6-'X'->BlockEnd_8\n" + "BlockEnd_8->RuleStop_A_2\n"; checkTokensRule(g, null, expecting); } @Test public void testRange() throws Exception { LexerGrammar g = new LexerGrammar( "lexer grammar P;\n"+ "A : 'a'..'c' ;" ); String expecting = "s0->RuleStart_A_1\n" +
132133134135136137138139140141142
"s3-'a'..'c'->s4\n" + "s4->RuleStop_A_2\n"; checkTokensRule(g, null, expecting); } @Test public void testRangeOrRange() throws Exception { LexerGrammar g = new LexerGrammar( "lexer grammar P;\n"+ "A : ('a'..'c' 'h' | 'q' 'j'..'l') ;" ); String expecting = "s0->RuleStart_A_1\n" +
914915916917918919920921922923924
":s6-EOF->.s7\n"; checkRule(g, "a", expecting); } */ @Test public void testDefaultMode() throws Exception { LexerGrammar g = new LexerGrammar( "lexer grammar L;\n"+ "A : 'a' ;\n" + "X : 'x' ;\n" + "mode FOO;\n" + "B : 'b' ;\n" +
933934935936937938939940941942943
"s11->RuleStop_A_3\n" + "s13->RuleStop_X_5\n"; checkTokensRule(g, "DEFAULT_MODE", expecting); } @Test public void testMode() throws Exception { LexerGrammar g = new LexerGrammar( "lexer grammar L;\n"+ "A : 'a' ;\n" + "X : 'x' ;\n" + "mode FOO;\n" + "B : 'b' ;\n" +
108109110111112113114115116117118
"e : E ;\n"); checkDeserializationIsStable(g); } @Test public void testLexerTwoRules() throws Exception { LexerGrammar lg = new LexerGrammar( "lexer grammar L;\n"+ "A : 'a' ;\n" + "B : 'b' ;\n"); checkDeserializationIsStable(lg); }
116117118119120121122123124125
"B : 'b' ;\n"); checkDeserializationIsStable(lg); } @Test public void testLexerEOF() throws Exception { LexerGrammar lg = new LexerGrammar( "lexer grammar L;\n"+ "A : 'a' EOF ;\n"); checkDeserializationIsStable(lg); }
123124125126127128129130131132
"A : 'a' EOF ;\n"); checkDeserializationIsStable(lg); } @Test public void testLexerEOFInSet() throws Exception { LexerGrammar lg = new LexerGrammar( "lexer grammar L;\n"+ "A : 'a' (EOF|'\\n') ;\n"); checkDeserializationIsStable(lg); }