Search in sources :

Example 61 with ATN

use of org.antlr.v4.runtime.atn.ATN in project antlr4 by antlr.

the class TestATNSerialization method testSimpleNoBlock.

@Test
public void testSimpleNoBlock() throws Exception {
    Grammar g = new Grammar("parser grammar T;\n" + "a : A B ;");
    String expecting = "max type 2\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + "5:BASIC 0\n" + "rule 0:0\n" + "0->2 EPSILON 0,0,0\n" + "2->3 ATOM 1,0,0\n" + "3->4 ATOM 2,0,0\n" + "4->1 EPSILON 0,0,0\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) ATN(org.antlr.v4.runtime.atn.ATN) Test(org.junit.Test)

Example 62 with ATN

use of org.antlr.v4.runtime.atn.ATN in project antlr4 by antlr.

the class TestATNSerialization method testLexerUnicodeUnescapedBMPNotSetWithRange.

@Test
public void testLexerUnicodeUnescapedBMPNotSetWithRange() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ~('亜'|'亝'|'江'|'た'..'ほ')\n ;");
    String expecting = "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + "rule 0:1 1\n" + "mode 0:0\n" + "0:'\\u305F'..'\\u307B', '\\u4E9C'..'\\u4E9D', '\\u6C5F'..'\\u6C5F'\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + "3->4 NOT_SET 0,0,0\n" + "4->2 EPSILON 0,0,0\n" + "0:0\n";
    ATN atn = createATN(lg, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 63 with ATN

use of org.antlr.v4.runtime.atn.ATN in project antlr4 by antlr.

the class TestATNSerialization method testLexerUnicodeUnescapedBMPNotSet.

@Test
public void testLexerUnicodeUnescapedBMPNotSet() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ~('亜'|'亝')\n ;");
    String expecting = "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + "rule 0:1 1\n" + "mode 0:0\n" + "0:'\\u4E9C'..'\\u4E9D'\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + "3->4 NOT_SET 0,0,0\n" + "4->2 EPSILON 0,0,0\n" + "0:0\n";
    ATN atn = createATN(lg, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 64 with ATN

use of org.antlr.v4.runtime.atn.ATN in project antlr4 by antlr.

the class TestATNSerialization method testLexerLoops.

@Test
public void testLexerLoops() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "INT : '0'..'9'+ ;\n");
    String expecting = "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "4:PLUS_BLOCK_START 0 5\n" + "5:BLOCK_END 0\n" + "6:PLUS_LOOP_BACK 0\n" + "7:LOOP_END 0 6\n" + "rule 0:1 1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "1->4 EPSILON 0,0,0\n" + "3->5 RANGE 48,57,0\n" + "4->3 EPSILON 0,0,0\n" + "5->6 EPSILON 0,0,0\n" + "6->4 EPSILON 0,0,0\n" + "6->7 EPSILON 0,0,0\n" + "7->2 EPSILON 0,0,0\n" + "0:0\n" + "1:6\n";
    ATN atn = createATN(lg, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 65 with ATN

use of org.antlr.v4.runtime.atn.ATN in project antlr4 by antlr.

the class TestATNSerialization method testRuleRef.

@Test
public void testRuleRef() throws Exception {
    Grammar g = new Grammar("parser grammar T;\n" + "a : e ;\n" + "e : E ;\n");
    String expecting = "max type 1\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:RULE_START 1\n" + "3:RULE_STOP 1\n" + "4:BASIC 0\n" + "5:BASIC 0\n" + "6:BASIC 1\n" + "7:BASIC 1\n" + "8:BASIC 1\n" + "rule 0:0\n" + "rule 1:2\n" + "0->4 EPSILON 0,0,0\n" + "2->6 EPSILON 0,0,0\n" + "4->5 RULE 2,1,0\n" + "5->1 EPSILON 0,0,0\n" + "6->7 ATOM 1,0,0\n" + "7->3 EPSILON 0,0,0\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) ATN(org.antlr.v4.runtime.atn.ATN) Test(org.junit.Test)

Aggregations

ATN (org.antlr.v4.runtime.atn.ATN)73 LexerGrammar (org.antlr.v4.tool.LexerGrammar)48 Test (org.junit.Test)41 ATNState (org.antlr.v4.runtime.atn.ATNState)23 Grammar (org.antlr.v4.tool.Grammar)20 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)18 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)16 ArrayList (java.util.ArrayList)13 DFA (org.antlr.v4.runtime.dfa.DFA)13 ATNDeserializer (org.antlr.v4.runtime.atn.ATNDeserializer)12 LexerATNSimulator (org.antlr.v4.runtime.atn.LexerATNSimulator)11 STGroupString (org.stringtemplate.v4.STGroupString)11 DecisionState (org.antlr.v4.runtime.atn.DecisionState)10 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)10 Rule (org.antlr.v4.tool.Rule)10 DOTGenerator (org.antlr.v4.tool.DOTGenerator)9 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)8 IntegerList (org.antlr.v4.runtime.misc.IntegerList)6 ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)6 BitSet (java.util.BitSet)5