public class ATNConfig extends Object
In addition to these values, ATNConfig stores several properties
about paths taken to get to the location which were added over time to help
with performance, correctness, and/or debugging.
getReachesIntoOuterContext(): Used to ensure semantic predicates
are not evaluated in the wrong context.hasPassedThroughNonGreedyDecision(): Used for enabling
first-match-wins instead of longest-match-wins after crossing a non-greedy
decision.getLexerActionExecutor(): Used for tracking the lexer action(s)
to execute should this instance be selected during lexing.isPrecedenceFilterSuppressed(): A state variable for one of the
dynamic disambiguation strategies employed by
ParserATNSimulator.applyPrecedenceFilter(org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.ParserRuleContext, org.antlr.v4.runtime.atn.PredictionContextCache).Due to the use of a graph-structured stack, a single ATNConfig is
capable of representing many individual ATN configurations which reached the
same location in an ATN by following different paths.
PERF: To conserve memory, ATNConfig is split into several
different concrete types. ATNConfig itself stores the minimum amount
of information typically used to define an ATNConfig instance.
Various derived types provide additional storage space for cases where a
non-default value is used for some of the object properties. The
create(org.antlr.v4.runtime.atn.ATNState, int, org.antlr.v4.runtime.atn.PredictionContext) and transform(org.antlr.v4.runtime.atn.ATNState, boolean) methods
automatically select the smallest concrete type capable of representing the
unique information for any given ATNConfig.
| Modifier | Constructor and Description |
|---|---|
protected |
ATNConfig(ATNConfig c,
ATNState state,
PredictionContext context) |
protected |
ATNConfig(ATNState state,
int alt,
PredictionContext context) |
| Modifier and Type | Method and Description |
|---|---|
ATNConfig |
appendContext(int context,
PredictionContextCache contextCache) |
ATNConfig |
appendContext(PredictionContext context,
PredictionContextCache contextCache) |
ATNConfig |
clone() |
boolean |
contains(ATNConfig subconfig)
|
static ATNConfig |
create(ATNState state,
int alt,
PredictionContext context) |
static ATNConfig |
create(ATNState state,
int alt,
PredictionContext context,
SemanticContext semanticContext) |
static ATNConfig |
create(ATNState state,
int alt,
PredictionContext context,
SemanticContext semanticContext,
LexerActionExecutor lexerActionExecutor) |
boolean |
equals(ATNConfig other) |
boolean |
equals(Object o)
An ATN configuration is equal to another if both have
the same state, they predict the same alternative, and
syntactic/semantic contexts are the same.
|
int |
getAlt()
What alt (or lexer rule) is predicted by this configuration
|
PredictionContext |
getContext() |
LexerActionExecutor |
getLexerActionExecutor() |
int |
getOuterContextDepth()
We cannot execute predicates dependent upon local context unless
we know for sure we are in the correct context.
|
boolean |
getReachesIntoOuterContext() |
SemanticContext |
getSemanticContext() |
ATNState |
getState()
Gets the ATN state associated with this configuration
|
int |
hashCode() |
boolean |
hasPassedThroughNonGreedyDecision() |
boolean |
isPrecedenceFilterSuppressed() |
void |
setContext(PredictionContext context) |
void |
setOuterContextDepth(int outerContextDepth) |
void |
setPrecedenceFilterSuppressed(boolean value) |
String |
toDotString()
Returns a graphical representation of the current
ATNConfig in
Graphviz format. |
String |
toString() |
String |
toString(Recognizer<?,?> recog,
boolean showAlt) |
String |
toString(Recognizer<?,?> recog,
boolean showAlt,
boolean showContext) |
ATNConfig |
transform(ATNState state,
boolean checkNonGreedy) |
ATNConfig |
transform(ATNState state,
LexerActionExecutor lexerActionExecutor,
boolean checkNonGreedy) |
ATNConfig |
transform(ATNState state,
PredictionContext context,
boolean checkNonGreedy) |
ATNConfig |
transform(ATNState state,
SemanticContext semanticContext,
boolean checkNonGreedy) |
protected ATNConfig(@NotNull
ATNState state,
int alt,
@NotNull
PredictionContext context)
protected ATNConfig(@NotNull
ATNConfig c,
@NotNull
ATNState state,
@NotNull
PredictionContext context)
public static ATNConfig create(@NotNull ATNState state, int alt, @Nullable PredictionContext context)
public static ATNConfig create(@NotNull ATNState state, int alt, @Nullable PredictionContext context, @NotNull SemanticContext semanticContext)
public static ATNConfig create(@NotNull ATNState state, int alt, @Nullable PredictionContext context, @NotNull SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor)
@NotNull public final ATNState getState()
public final int getAlt()
@NotNull public final PredictionContext getContext()
public void setContext(@NotNull
PredictionContext context)
public final boolean getReachesIntoOuterContext()
public final int getOuterContextDepth()
closure() tracks the depth of how far we dip into the outer context: depth > 0. Note that it may not be totally accurate depth since I don't ever decrement. TODO: make it a boolean then
public void setOuterContextDepth(int outerContextDepth)
@Nullable public LexerActionExecutor getLexerActionExecutor()
@NotNull public SemanticContext getSemanticContext()
public boolean hasPassedThroughNonGreedyDecision()
public final ATNConfig transform(@NotNull ATNState state, @NotNull SemanticContext semanticContext, boolean checkNonGreedy)
public final ATNConfig transform(@NotNull ATNState state, @Nullable PredictionContext context, boolean checkNonGreedy)
public final ATNConfig transform(@NotNull ATNState state, LexerActionExecutor lexerActionExecutor, boolean checkNonGreedy)
public ATNConfig appendContext(int context, PredictionContextCache contextCache)
public ATNConfig appendContext(PredictionContext context, PredictionContextCache contextCache)
public boolean contains(ATNConfig subconfig)
ATNConfig fully contains another
ATNConfig.
An ATN configuration represents a position (including context) in an
ATN during parsing. Since ATNConfig stores the context as a
graph, a single ATNConfig instance is capable of representing
many ATN configurations which are all in the same "location" but have
different contexts. These ATNConfig instances are again merged
when they are added to an ATNConfigSet. This method supports
ATNConfigSet.contains(java.lang.Object) by evaluating whether a particular
ATNConfig contains all of the ATN configurations represented by
another ATNConfig.
An ATNConfig a contains another ATNConfig
b if all of the following conditions are met:
getState())getAlt())This method implements a conservative approximation of containment. As
a result, when this method returns {code true} it is known that parsing
from subconfig can only recognize a subset of the inputs which
can be recognized starting at the current ATNConfig. However, due
to the imprecise evaluation of implication for the semantic contexts, no
assumptions can be made about the relationship between the configurations
when this method returns false.
subconfig - The sub configuration.true if this configuration contains subconfig;
otherwise, false.public final boolean isPrecedenceFilterSuppressed()
public final void setPrecedenceFilterSuppressed(boolean value)
public boolean equals(Object o)
public boolean equals(ATNConfig other)
public String toDotString()
ATNConfig in
Graphviz format. The graph can be stored to a .dot file
and then rendered to an image using Graphviz.ATNConfig.http://www.graphviz.org/public String toString(@Nullable Recognizer<?,?> recog, boolean showAlt)
public String toString(@Nullable Recognizer<?,?> recog, boolean showAlt, boolean showContext)
Copyright © 1992–2024 Daniel Sun. All rights reserved.