Search in sources :

Example 91 with Grammar

use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.

the class TestATNConstruction method testAorB.

@Test
public void testAorB() throws Exception {
    Grammar g = new Grammar("parser grammar P;\n" + "a : A | B {;} ;");
    String expecting = "RuleStart_a_0->BlockStart_5\n" + "BlockStart_5->s2\n" + "BlockStart_5->s3\n" + "s2-A->BlockEnd_6\n" + "s3-B->s4\n" + "BlockEnd_6->RuleStop_a_1\n" + "s4-action_0:-1->BlockEnd_6\n" + "RuleStop_a_1-EOF->s7\n";
    checkRuleATN(g, "a", expecting);
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 92 with Grammar

use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.

the class TestATNConstruction method testRangeOrRange.

@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" + "RuleStart_A_1->BlockStart_7\n" + "BlockStart_7->s3\n" + "BlockStart_7->s5\n" + "s3-'a'..'c'->s4\n" + "s5-'q'->s6\n" + "s4-'h'->BlockEnd_8\n" + "s6-'j'..'l'->BlockEnd_8\n" + "BlockEnd_8->RuleStop_A_2\n";
    checkTokensRule(g, null, expecting);
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 93 with Grammar

use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.

the class TestATNConstruction method testCharSetUnicodeBMPEscapeRange.

@Test
public void testCharSetUnicodeBMPEscapeRange() throws Exception {
    LexerGrammar g = new LexerGrammar("lexer grammar P;\n" + "A : [a-c\\uABCD-\\uABFF] ;");
    String expecting = "s0->RuleStart_A_1\n" + "RuleStart_A_1->s3\n" + "s3-{97..99, 43981..44031}->s4\n" + "s4->RuleStop_A_2\n";
    checkTokensRule(g, null, expecting);
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 94 with Grammar

use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.

the class TestATNConstruction method testAorEpsilon.

@Test
public void testAorEpsilon() throws Exception {
    Grammar g = new Grammar("parser grammar P;\n" + "a : A | ;");
    String expecting = "RuleStart_a_0->BlockStart_4\n" + "BlockStart_4->s2\n" + "BlockStart_4->s3\n" + "s2-A->BlockEnd_5\n" + "s3->BlockEnd_5\n" + "BlockEnd_5->RuleStop_a_1\n" + "RuleStop_a_1-EOF->s6\n";
    checkRuleATN(g, "a", expecting);
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 95 with Grammar

use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.

the class TestATNConstruction method testEmptyOrEmpty.

@Test
public void testEmptyOrEmpty() throws Exception {
    Grammar g = new Grammar("parser grammar P;\n" + "a : | ;");
    String expecting = "RuleStart_a_0->BlockStart_4\n" + "BlockStart_4->s2\n" + "BlockStart_4->s3\n" + "s2->BlockEnd_5\n" + "s3->BlockEnd_5\n" + "BlockEnd_5->RuleStop_a_1\n" + "RuleStop_a_1-EOF->s6\n";
    checkRuleATN(g, "a", expecting);
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Aggregations

LexerGrammar (org.antlr.v4.tool.LexerGrammar)305 Test (org.junit.Test)304 Grammar (org.antlr.v4.tool.Grammar)183 ATN (org.antlr.v4.runtime.atn.ATN)65 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)62 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)59 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)53 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)47 TokenStreamRewriter (org.antlr.v4.runtime.TokenStreamRewriter)43 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)31 ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)29 Rule (org.antlr.v4.tool.Rule)25 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)21 STGroupString (org.stringtemplate.v4.STGroupString)21 ArrayList (java.util.ArrayList)18 ATNState (org.antlr.v4.runtime.atn.ATNState)18 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)17 ST (org.stringtemplate.v4.ST)17 ParseTree (org.antlr.v4.runtime.tree.ParseTree)15 BaseRuntimeTest (org.antlr.v4.test.runtime.BaseRuntimeTest)15