Search in sources :

Example 6 with ATNDeserializer

use of org.antlr.v4.runtime.atn.ATNDeserializer in project antlr4 by antlr.

the class BaseNodeTest method createATN.

protected ATN createATN(Grammar g, boolean useSerializer) {
    if (g.atn == null) {
        semanticProcess(g);
        assertEquals(0, g.tool.getNumErrors());
        ParserATNFactory f;
        if (g.isLexer()) {
            f = new LexerATNFactory((LexerGrammar) g);
        } else {
            f = new ParserATNFactory(g);
        }
        g.atn = f.createATN();
        assertEquals(0, g.tool.getNumErrors());
    }
    ATN atn = g.atn;
    if (useSerializer) {
        char[] serialized = ATNSerializer.getSerializedAsChars(atn);
        return new ATNDeserializer().deserialize(serialized);
    }
    return atn;
}
Also used : ATNDeserializer(org.antlr.v4.runtime.atn.ATNDeserializer) ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerATNFactory(org.antlr.v4.automata.LexerATNFactory)

Example 7 with ATNDeserializer

use of org.antlr.v4.runtime.atn.ATNDeserializer in project antlr4 by antlr.

the class BasePythonTest method createATN.

protected ATN createATN(Grammar g, boolean useSerializer) {
    if (g.atn == null) {
        semanticProcess(g);
        assertEquals(0, g.tool.getNumErrors());
        ParserATNFactory f;
        if (g.isLexer()) {
            f = new LexerATNFactory((LexerGrammar) g);
        } else {
            f = new ParserATNFactory(g);
        }
        g.atn = f.createATN();
        assertEquals(0, g.tool.getNumErrors());
    }
    ATN atn = g.atn;
    if (useSerializer) {
        char[] serialized = ATNSerializer.getSerializedAsChars(atn);
        return new ATNDeserializer().deserialize(serialized);
    }
    return atn;
}
Also used : ATNDeserializer(org.antlr.v4.runtime.atn.ATNDeserializer) ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerATNFactory(org.antlr.v4.automata.LexerATNFactory)

Example 8 with ATNDeserializer

use of org.antlr.v4.runtime.atn.ATNDeserializer in project antlr4 by antlr.

the class BaseJavaTest method createATN.

protected ATN createATN(Grammar g, boolean useSerializer) {
    if (g.atn == null) {
        semanticProcess(g);
        assertEquals(0, g.tool.getNumErrors());
        ParserATNFactory f;
        if (g.isLexer()) {
            f = new LexerATNFactory((LexerGrammar) g);
        } else {
            f = new ParserATNFactory(g);
        }
        g.atn = f.createATN();
        assertEquals(0, g.tool.getNumErrors());
    }
    ATN atn = g.atn;
    if (useSerializer) {
        char[] serialized = ATNSerializer.getSerializedAsChars(atn);
        return new ATNDeserializer().deserialize(serialized);
    }
    return atn;
}
Also used : ATNDeserializer(org.antlr.v4.runtime.atn.ATNDeserializer) ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerATNFactory(org.antlr.v4.automata.LexerATNFactory)

Example 9 with ATNDeserializer

use of org.antlr.v4.runtime.atn.ATNDeserializer in project antlr4 by antlr.

the class BaseBrowserTest method createATN.

protected ATN createATN(Grammar g, boolean useSerializer) {
    if (g.atn == null) {
        semanticProcess(g);
        assertEquals(0, g.tool.getNumErrors());
        ParserATNFactory f;
        if (g.isLexer()) {
            f = new LexerATNFactory((LexerGrammar) g);
        } else {
            f = new ParserATNFactory(g);
        }
        g.atn = f.createATN();
        assertEquals(0, g.tool.getNumErrors());
    }
    ATN atn = g.atn;
    if (useSerializer) {
        char[] serialized = ATNSerializer.getSerializedAsChars(atn);
        return new ATNDeserializer().deserialize(serialized);
    }
    return atn;
}
Also used : ATNDeserializer(org.antlr.v4.runtime.atn.ATNDeserializer) ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) ATN(org.antlr.v4.runtime.atn.ATN) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerATNFactory(org.antlr.v4.automata.LexerATNFactory)

Example 10 with ATNDeserializer

use of org.antlr.v4.runtime.atn.ATNDeserializer in project antlr4 by antlr.

the class Grammar method createLexerInterpreter.

public LexerInterpreter createLexerInterpreter(CharStream input) {
    if (this.isParser()) {
        throw new IllegalStateException("A lexer interpreter can only be created for a lexer or combined grammar.");
    }
    if (this.isCombined()) {
        return implicitLexer.createLexerInterpreter(input);
    }
    char[] serializedAtn = ATNSerializer.getSerializedAsChars(atn);
    ATN deserialized = new ATNDeserializer().deserialize(serializedAtn);
    List<String> allChannels = new ArrayList<String>();
    allChannels.add("DEFAULT_TOKEN_CHANNEL");
    allChannels.add("HIDDEN");
    allChannels.addAll(channelValueToNameList);
    return new LexerInterpreter(fileName, getVocabulary(), Arrays.asList(getRuleNames()), allChannels, ((LexerGrammar) this).modes.keySet(), deserialized, input);
}
Also used : ATNDeserializer(org.antlr.v4.runtime.atn.ATNDeserializer) LexerInterpreter(org.antlr.v4.runtime.LexerInterpreter) ArrayList(java.util.ArrayList) ATN(org.antlr.v4.runtime.atn.ATN)

Aggregations

ATN (org.antlr.v4.runtime.atn.ATN)12 ATNDeserializer (org.antlr.v4.runtime.atn.ATNDeserializer)12 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)6 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)6 LexerGrammar (org.antlr.v4.tool.LexerGrammar)6 ParserInterpreter (org.antlr.v4.runtime.ParserInterpreter)2 ArrayList (java.util.ArrayList)1 BailErrorStrategy (org.antlr.v4.runtime.BailErrorStrategy)1 InputMismatchException (org.antlr.v4.runtime.InputMismatchException)1 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 ATNDeserializationOptions (org.antlr.v4.runtime.atn.ATNDeserializationOptions)1