Search in sources :

Example 41 with IntegerList

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

the class TestIntegerList method tooLargeIntegerToCharArrayThrows.

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

Example 42 with IntegerList

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

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, l.toCharArray());
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) Test(org.junit.Test)

Example 43 with IntegerList

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

the class ATNSerializer method getDecoded.

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

Example 44 with IntegerList

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

the class ATNSerializer method serializeSets.

private static void serializeSets(IntegerList data, Collection<IntervalSet> sets, CodePointSerializer codePointSerializer) {
    int nSets = sets.size();
    data.add(nSets);
    for (IntervalSet set : sets) {
        boolean containsEof = set.contains(Token.EOF);
        if (containsEof && set.getIntervals().get(0).b == Token.EOF) {
            data.add(set.getIntervals().size() - 1);
        } else {
            data.add(set.getIntervals().size());
        }
        data.add(containsEof ? 1 : 0);
        for (Interval I : set.getIntervals()) {
            if (I.a == Token.EOF) {
                if (I.b == Token.EOF) {
                    continue;
                } else {
                    codePointSerializer.serializeCodePoint(data, 0);
                }
            } else {
                codePointSerializer.serializeCodePoint(data, I.a);
            }
            codePointSerializer.serializeCodePoint(data, I.b);
        }
    }
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Interval(org.antlr.v4.runtime.misc.Interval)

Example 45 with IntegerList

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

the class Tool method generateInterpreterData.

private void generateInterpreterData(Grammar g) {
    StringBuilder content = new StringBuilder();
    content.append("token literal names:\n");
    String[] names = g.getTokenLiteralNames();
    for (String name : names) {
        content.append(name + "\n");
    }
    content.append("\n");
    content.append("token symbolic names:\n");
    names = g.getTokenSymbolicNames();
    for (String name : names) {
        content.append(name + "\n");
    }
    content.append("\n");
    content.append("rule names:\n");
    names = g.getRuleNames();
    for (String name : names) {
        content.append(name + "\n");
    }
    content.append("\n");
    if (g.isLexer()) {
        content.append("channel names:\n");
        content.append("DEFAULT_TOKEN_CHANNEL\n");
        content.append("HIDDEN\n");
        for (String channel : g.channelValueToNameList) {
            content.append(channel + "\n");
        }
        content.append("\n");
        content.append("mode names:\n");
        for (String mode : ((LexerGrammar) g).modes.keySet()) {
            content.append(mode + "\n");
        }
    }
    content.append("\n");
    IntegerList serializedATN = ATNSerializer.getSerialized(g.atn);
    content.append("atn:\n");
    content.append(serializedATN.toString());
    try {
        Writer fw = getOutputFileWriter(g, g.name + ".interp");
        try {
            fw.write(content.toString());
        } finally {
            fw.close();
        }
    } catch (IOException ioe) {
        errMgr.toolError(ErrorType.CANNOT_WRITE_FILE, ioe);
    }
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter)

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