Search in sources :

Example 11 with IntegerList

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

the class TestIntegerList method negativeIntegerToCharArrayThrows.

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

Example 12 with IntegerList

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

the class TestIntegerList method unicodeBMPIntegerListToCharArray.

@Test
public void unicodeBMPIntegerListToCharArray() {
    IntegerList l = new IntegerList();
    l.add(0x35);
    l.add(0x4E94);
    l.add(0xFF15);
    char[] expected = new char[] { 0x35, 0x4E94, 0xFF15 };
    assertArrayEquals(expected, Utils.toCharArray(l));
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) Test(org.junit.Test)

Example 13 with IntegerList

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

the class TestIntegerList method surrogateRangeIntegerToCharArray.

@Test
public void surrogateRangeIntegerToCharArray() {
    IntegerList l = new IntegerList();
    // Java allows dangling surrogates, so (currently) we do
    // as well. We could change this if desired.
    l.add(0xDC00);
    char[] expected = new char[] { 0xDC00 };
    assertArrayEquals(expected, Utils.toCharArray(l));
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) Test(org.junit.Test)

Example 14 with IntegerList

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

the class ParserATNSimulator method addDFAEdge.

@NotNull
protected DFAState addDFAEdge(@NotNull DFA dfa, @NotNull DFAState fromState, int t, IntegerList contextTransitions, @NotNull ATNConfigSet toConfigs, PredictionContextCache contextCache) {
    assert contextTransitions == null || contextTransitions.isEmpty() || dfa.isContextSensitive();
    DFAState from = fromState;
    DFAState to = addDFAState(dfa, toConfigs, contextCache);
    if (contextTransitions != null) {
        for (int context : contextTransitions.toArray()) {
            if (context == PredictionContext.EMPTY_FULL_STATE_KEY) {
                if (from.configs.isOutermostConfigSet()) {
                    continue;
                }
            }
            from.setContextSensitive(atn);
            from.setContextSymbol(t);
            DFAState next = from.getContextTarget(context);
            if (next != null) {
                from = next;
                continue;
            }
            next = addDFAContextState(dfa, from.configs, context, contextCache);
            assert context != PredictionContext.EMPTY_FULL_STATE_KEY || next.configs.isOutermostConfigSet();
            from.setContextTarget(context, next);
            from = next;
        }
    }
    if (debug)
        System.out.println("EDGE " + from + " -> " + to + " upon " + getTokenName(t));
    addDFAEdge(from, t, to);
    if (debug)
        System.out.println("DFA=\n" + dfa.toString(parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY, parser != null ? parser.getRuleNames() : null));
    return to;
}
Also used : DFAState(org.antlr.v4.runtime.dfa.DFAState) NotNull(org.antlr.v4.runtime.misc.NotNull)

Example 15 with IntegerList

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

the class ATNSerializer method getDecoded.

public static String getDecoded(ATN atn, List<String> ruleNames, List<String> tokenNames) {
    IntegerList serialized = getSerialized(atn, ruleNames);
    char[] data = Utils.toCharArray(serialized);
    return new ATNSerializer(atn, ruleNames, tokenNames).decode(data);
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList)

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