Top Description Fields Constructors Methods
org.antlr.v4.runtime.atn

public Class ATNSerializer

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.Token, org.antlr.v4.runtime.misc.IntegerList, .Interval, .IntervalSet, java.util.Collection, .HashMap, .LinkedHashMap, .Locale, .Map

This class represents a target neutral serializer for ATNs. An ATN is converted to a list of integers that can be converted back to and ATN. We compute the list of integers and then generate an array into the target language for a particular lexer or parser. Java is a special case where we must generate strings instead of arrays, but that is handled outside of this class. See ATNDeserializer#encodeIntsWith16BitWords(IntegerList) and org.antlr.v4.codegen.model.SerializedJavaATN.

Field Summary

Modifier and TypeField and Description
public ATN
private final IntegerList
private final IntegerList
private final IntegerList
private final Map<IntervalSet, Boolean>
sets

Note that we use a LinkedHashMap as a set to mainintain insertion order while deduplicating entries with the same key.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
addEdges(int nedges, Map<IntervalSet, Integer> setIndices)

private int
private void
private void
private void
private void
private void
private void
private Map<IntervalSet, Integer>
public static IntegerList
public IntegerList
serialize()

Serialize state descriptors, edge descriptors, and decision→state map into list of ints.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

atnback to summary
public ATN atn
databack to summary
private final IntegerList data
nonGreedyStatesback to summary
private final IntegerList nonGreedyStates
precedenceStatesback to summary
private final IntegerList precedenceStates
setsback to summary
private final Map<IntervalSet, Boolean> sets

Note that we use a LinkedHashMap as a set to mainintain insertion order while deduplicating entries with the same key.

Constructor Detail

ATNSerializerback to summary
public ATNSerializer(ATN atn)

Method Detail

addDecisionStartStatesback to summary
private void addDecisionStartStates()
addEdgesback to summary
private void addEdges(int nedges, Map<IntervalSet, Integer> setIndices)
addEdgesback to summary
private int addEdges()
addLexerActionsback to summary
private void addLexerActions()
addModeStartStatesback to summary
private void addModeStartStates()
addNonGreedyStatesback to summary
private void addNonGreedyStates()
addPreambleback to summary
private void addPreamble()
addPrecedenceStatesback to summary
private void addPrecedenceStates()
addRuleStatesAndLexerTokenTypesback to summary
private void addRuleStatesAndLexerTokenTypes()
addSetsback to summary
private Map<IntervalSet, Integer> addSets()
getSerializedback to summary
public static IntegerList getSerialized(ATN atn)
serializeback to summary
public IntegerList serialize()

Serialize state descriptors, edge descriptors, and decision→state map into list of ints. Likely out of date, but keeping as it could be helpful: SERIALIZED_VERSION UUID (2 longs) grammar-type, (ANTLRParser.LEXER, ...) max token type, num states, state-0-type ruleIndex, state-1-type ruleIndex, ... state-i-type ruleIndex optional-arg ... num rules, rule-1-start-state rule-1-args, rule-2-start-state rule-2-args, ... (args are token type,actionIndex in lexer else 0,0) num modes, mode-0-start-state, mode-1-start-state, ... (parser has 0 modes) num unicode-bmp-sets bmp-set-0-interval-count intervals, bmp-set-1-interval-count intervals, ... num unicode-smp-sets smp-set-0-interval-count intervals, smp-set-1-interval-count intervals, ... num total edges, src, trg, edge-type, edge arg1, optional edge arg2 (present always), ... num decisions, decision-0-start-state, decision-1-start-state, ... Convenient to pack into unsigned shorts to make as Java string.

serializeSetsback to summary
private static void serializeSets(IntegerList data, Collection<IntervalSet> sets)