Search in sources :

Example 36 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by tunnelvisionlabs.

the class TestIntegerList method unicodeSMPIntegerListToCharArray.

@Test
public void unicodeSMPIntegerListToCharArray() {
    IntegerList l = new IntegerList();
    l.add(0x104A5);
    l.add(0x116C5);
    l.add(0x1D7FB);
    char[] expected = new char[] { 0xD801, 0xDCA5, 0xD805, 0xDEC5, 0xD835, 0xDFFB };
    assertArrayEquals(expected, Utils.toCharArray(l));
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) Test(org.junit.Test)

Example 37 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by tunnelvisionlabs.

the class TestIntegerList method tooLargeIntegerToCharArrayThrows.

@Test
public void tooLargeIntegerToCharArrayThrows() {
    IntegerList l = new IntegerList();
    l.add(0x110000);
    thrown.expect(IllegalArgumentException.class);
    Utils.toCharArray(l);
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) Test(org.junit.Test)

Example 38 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.

the class TestATNParserPrediction method checkDFAConstruction.

public void checkDFAConstruction(LexerGrammar lg, Grammar g, int decision, String[] inputString, String[] dfaString) {
    // Tool.internalOption_ShowATNConfigsInDFA = true;
    ATN lexatn = createATN(lg, true);
    LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn, new DFA[] { new DFA(lexatn.getDecisionState(Lexer.DEFAULT_MODE)) }, new PredictionContextCache());
    semanticProcess(lg);
    g.importVocab(lg);
    semanticProcess(g);
    ParserInterpreterForTesting interp = new ParserInterpreterForTesting(g, null);
    for (int i = 0; i < inputString.length; i++) {
        // Check DFA
        IntegerList types = getTokenTypesViaATN(inputString[i], lexInterp);
        // System.out.println(types);
        TokenStream input = new MockIntTokenStream(types);
        try {
            interp.adaptivePredict(input, decision, ParserRuleContext.EMPTY);
        } catch (NoViableAltException nvae) {
            nvae.printStackTrace(System.err);
        }
        DFA dfa = interp.parser.decisionToDFA[decision];
        assertEquals(dfaString[i], dfa.toString(g.getVocabulary()));
    }
}
Also used : MockIntTokenStream(org.antlr.v4.test.runtime.MockIntTokenStream) TokenStream(org.antlr.v4.runtime.TokenStream) NoViableAltException(org.antlr.v4.runtime.NoViableAltException) LexerATNSimulator(org.antlr.v4.runtime.atn.LexerATNSimulator) IntegerList(org.antlr.v4.runtime.misc.IntegerList) MockIntTokenStream(org.antlr.v4.test.runtime.MockIntTokenStream) RuntimeTestUtils.getTokenTypesViaATN(org.antlr.v4.test.runtime.RuntimeTestUtils.getTokenTypesViaATN) ATN(org.antlr.v4.runtime.atn.ATN) PredictionContextCache(org.antlr.v4.runtime.atn.PredictionContextCache) DFA(org.antlr.v4.runtime.dfa.DFA)

Example 39 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.

the class RuntimeTestUtils method getTokenTypesViaATN.

public static IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) {
    ANTLRInputStream in = new ANTLRInputStream(input);
    IntegerList tokenTypes = new IntegerList();
    int ttype;
    do {
        ttype = lexerATN.match(in, Lexer.DEFAULT_MODE);
        tokenTypes.add(ttype);
    } while (ttype != Token.EOF);
    return tokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList)

Example 40 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.

the class TestIntegerList method emptyListToEmptyCharArray.

@Test
public void emptyListToEmptyCharArray() {
    IntegerList l = new IntegerList();
    assertArrayEquals(new char[0], l.toCharArray());
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) Test(org.junit.Test)

Aggregations

IntegerList (org.antlr.v4.runtime.misc.IntegerList)42 Test (org.junit.Test)12 STGroupString (org.stringtemplate.v4.STGroupString)7 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)6 ATN (org.antlr.v4.runtime.atn.ATN)6 LexerATNSimulator (org.antlr.v4.runtime.atn.LexerATNSimulator)6 ArrayList (java.util.ArrayList)5 TokenStream (org.antlr.v4.runtime.TokenStream)5 DFA (org.antlr.v4.runtime.dfa.DFA)5 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)5 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)4 DOTGenerator (org.antlr.v4.tool.DOTGenerator)4 Rule (org.antlr.v4.tool.Rule)4 HashMap (java.util.HashMap)3 ATNState (org.antlr.v4.runtime.atn.ATNState)3 BlockStartState (org.antlr.v4.runtime.atn.BlockStartState)3 MockIntTokenStream (org.antlr.v4.test.runtime.MockIntTokenStream)3 RuntimeTestUtils.getTokenTypesViaATN (org.antlr.v4.test.runtime.RuntimeTestUtils.getTokenTypesViaATN)3 BufferedWriter (java.io.BufferedWriter)2