use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNSerialization method testLexerUnicodeEscapedBMPNotSetWithRange.
@Test
public void testLexerUnicodeEscapedBMPNotSetWithRange() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ~('\\u4E9C'|'\\u4E9D'|'\\u6C5F'|'\\u305F'..'\\u307B')\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.getRuleNames()), Arrays.asList(lg.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNSerialization method testLexerEOFInSet.
@Test
public void testLexerEOFInSet() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "INT : 'a' (EOF|'\\n') ;\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" + "5:BLOCK_START 0 6\n" + "6:BLOCK_END 0\n" + "rule 0:1 1\n" + "mode 0:0\n" + "0:EOF, '\\n'..'\\n'\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + "3->5 ATOM 97,0,0\n" + "4->6 SET 0,0,0\n" + "5->4 EPSILON 0,0,0\n" + "6->2 EPSILON 0,0,0\n" + "0:0\n" + "1:5\n";
ATN atn = createATN(lg, true);
String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getRuleNames()), Arrays.asList(lg.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNSerialization method test2ModesInLexer.
@Test
public void test2ModesInLexer() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a'\n ;\n" + "mode M;\n" + "B : 'b';\n" + "mode M2;\n" + "C : 'c';\n");
String expecting = "max type 3\n" + "0:TOKEN_START -1\n" + "1:TOKEN_START -1\n" + "2:TOKEN_START -1\n" + "3:RULE_START 0\n" + "4:RULE_STOP 0\n" + "5:RULE_START 1\n" + "6:RULE_STOP 1\n" + "7:RULE_START 2\n" + "8:RULE_STOP 2\n" + "9:BASIC 0\n" + "10:BASIC 0\n" + "11:BASIC 1\n" + "12:BASIC 1\n" + "13:BASIC 2\n" + "14:BASIC 2\n" + "rule 0:3 1\n" + "rule 1:5 2\n" + "rule 2:7 3\n" + "mode 0:0\n" + "mode 1:1\n" + "mode 2:2\n" + "0->3 EPSILON 0,0,0\n" + "1->5 EPSILON 0,0,0\n" + "2->7 EPSILON 0,0,0\n" + "3->9 EPSILON 0,0,0\n" + "5->11 EPSILON 0,0,0\n" + "7->13 EPSILON 0,0,0\n" + "9->10 ATOM 97,0,0\n" + "10->4 EPSILON 0,0,0\n" + "11->12 ATOM 98,0,0\n" + "12->6 EPSILON 0,0,0\n" + "13->14 ATOM 99,0,0\n" + "14->8 EPSILON 0,0,0\n" + "0:0\n" + "1:1\n" + "2:2\n";
ATN atn = createATN(lg, true);
String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getRuleNames()), Arrays.asList(lg.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNSerialization method testLexerUnicodeSMPLiteralSerializedToSet.
@Test
public void testLexerUnicodeSMPLiteralSerializedToSet() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "INT : '\\u{1F4A9}' ;");
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:128169..128169\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + "3->4 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.getRuleNames()), Arrays.asList(lg.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNSerialization method testLexerUnicodeEscapedSMPNotSetWithRange.
@Test
public void testLexerUnicodeEscapedSMPNotSetWithRange() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ~('\\u{1F4A9}'|'\\u{1F4AA}'|'\\u{1F441}'|'\\u{1D40F}'..'\\u{1D413}')\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:119823..119827, 128065..128065, 128169..128170\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.getRuleNames()), Arrays.asList(lg.getTokenNames()));
assertEquals(expecting, result);
}
Aggregations