pub struct ParserAtnSimulator<'a> { /* private fields */ }Implementations§
Source§impl<'a> ParserAtnSimulator<'a>
impl<'a> ParserAtnSimulator<'a>
pub fn new(atn: &'a Atn) -> Self
Sourcepub const fn set_exact_ambig_detection(&mut self, exact: bool)
pub const fn set_exact_ambig_detection(&mut self, exact: bool)
Switches the full-context resolution strategy (Java’s
LL_EXACT_AMBIG_DETECTION versus plain LL).
Sourcepub fn dump_dfa_java_style(&self, vocabulary: &Vocabulary) -> String
pub fn dump_dfa_java_style(&self, vocabulary: &Vocabulary) -> String
Creates a simulator that starts from, and publishes back into, a thread-local DFA cache keyed by a generated parser’s static ATN.
Generated parsers usually create a fresh parser object per parse. Without this cache every parse relearns the same adaptive DFA; with it, later parser instances reuse the SLL cache learned by earlier instances while still keeping mutable simulator state local to the parser during a parse.
The DFAs are checked OUT of the cache by move (and back in on drop):
cloning a warm DFA per parser instance costs O(learned states) — ~10%
of a small parse. A second simulator created for the same ATN while one
is alive finds the slot empty and starts cold; the drop-time check-in
then keeps whichever tables learned more.
Renders every non-empty learned decision DFA in the format of Java’s
Parser.dumpDFA() / DFASerializer — Decision N: headers followed
by s0-'else'->:s1^=>1 edge lines — which the runtime testsuite’s
showDFA descriptors byte-compare.
pub fn decision_dfas(&self) -> &[Dfa]
pub fn adaptive_predict( &mut self, decision: usize, lookahead: impl IntoIterator<Item = i32>, ) -> Result<usize, ParserAtnSimulatorError>
pub fn adaptive_predict_stream<T: IntStream>( &mut self, decision: usize, input: &mut T, ) -> Result<usize, ParserAtnSimulatorError>
pub fn adaptive_predict_stream_with_precedence<T: IntStream>( &mut self, decision: usize, precedence: usize, input: &mut T, ) -> Result<usize, ParserAtnSimulatorError>
pub fn adaptive_predict_stream_info_with_precedence<T: IntStream>( &mut self, decision: usize, precedence: usize, input: &mut T, ) -> Result<ParserAtnPrediction, ParserAtnSimulatorError>
Sourcepub fn adaptive_predict_stream_info_sll_probe<T: IntStream>(
&mut self,
decision: usize,
precedence: usize,
input: &mut T,
) -> Result<ParserAtnPrediction, ParserAtnSimulatorError>
pub fn adaptive_predict_stream_info_sll_probe<T: IntStream>( &mut self, decision: usize, precedence: usize, input: &mut T, ) -> Result<ParserAtnPrediction, ParserAtnSimulatorError>
SLL-probe variant of Self::adaptive_predict_stream_info_with_precedence.
Identical to the precedence entry except that, when the SLL walk reaches
a conflict state requiring full context, it returns the SLL prediction
(carrying requires_full_context = true) WITHOUT running the
full-context LL loop. The generated two-stage prediction calls this for
stage 1 and only consults requires_full_context to decide whether to
re-run with the real outer context, so the empty-context LL pass this
skips would be discarded anyway. Avoids the double LL pass per escalation.