Search in sources :

Example 31 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

the class TestATNSerialization method testLexerUnicodeEscapedSMPNotSet.

@Test
public void testLexerUnicodeEscapedSMPNotSet() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ~('\\u{1F4A9}'|'\\u{1F4AA}')\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: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.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 32 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

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.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 33 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

the class TestATNSerialization method testEOFInSet.

@Test
public void testEOFInSet() throws Exception {
    Grammar g = new Grammar("parser grammar T;\n" + "a : (A|EOF) ;");
    String expecting = "max type 1\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + "rule 0:0\n" + "0:EOF, A..A\n" + "0->2 EPSILON 0,0,0\n" + "2->3 SET 0,0,0\n" + "3->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 34 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

the class TestATNSerialization method testLexerRange.

@Test
public void testLexerRange() 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:BASIC 0\n" + "rule 0:1 1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + "3->4 RANGE 48,57,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 35 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

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.getTokenNames()));
    assertEquals(expecting, result);
}
Also used : ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)131 LexerGrammar (org.antlr.v4.tool.LexerGrammar)78 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)52 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)49 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)44 ATN (org.antlr.v4.runtime.atn.ATN)44 TokenStreamRewriter (org.antlr.v4.runtime.TokenStreamRewriter)38 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)38 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)38 ParseTree (org.antlr.v4.runtime.tree.ParseTree)29 ATNState (org.antlr.v4.runtime.atn.ATNState)11 Grammar (org.antlr.v4.tool.Grammar)10 STGroupString (org.stringtemplate.v4.STGroupString)10 ByteBuffer (java.nio.ByteBuffer)8 IntBuffer (java.nio.IntBuffer)8 UTF8CodePointDecoder (org.antlr.v4.runtime.UTF8CodePointDecoder)8 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)8 DOTGenerator (org.antlr.v4.tool.DOTGenerator)8 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)7 Rule (org.antlr.v4.tool.Rule)7