pub struct ParserAtn { /* private fields */ }Expand description
Immutable packed parser ATN.
Generated parsers borrow a static word stream directly. Deserialization of ordinary ANTLR v4 integer metadata produces the same layout in one owned allocation.
Implementations§
Source§impl ParserAtn
impl ParserAtn
Sourcepub fn with_bypass_alternatives(&self) -> Result<Self, ParserAtnError>
pub fn with_bypass_alternatives(&self) -> Result<Self, ParserAtnError>
Builds a copy of this parser ATN with rule-bypass alternatives added.
Every rule gains an imaginary token type (max_token_type + rule + 1)
and a bypass block so the ATN interpreter can match that single
imaginary token in place of the whole rule. max_token_type is
unchanged (see the module docs). The returned ATN is otherwise a faithful
copy: state kinds, transitions, interval sets, decisions, and
rule/precedence metadata are all preserved.
§Errors
Returns ParserAtnError if the state/transition/token counts overflow
the packed compact-index range, if a left-recursive rule’s precedence
prefix cannot be identified, or if the re-emitted stream fails
validation.
Sourcepub fn bypass_token_type(
&self,
rule_index: usize,
) -> Result<i32, ParserAtnError>
pub fn bypass_token_type( &self, rule_index: usize, ) -> Result<i32, ParserAtnError>
The imaginary token type reserved for a rule’s bypass alternative:
max_token_type + rule_index + 1.
This is the single source of the formula shared by
Self::with_bypass_alternatives (which labels the bypass Atom edge
with it) and the pattern matcher (which stamps rule-tag tokens with it),
so the two can never disagree about a tag’s token type.
§Errors
Returns ParserAtnError::Overflow when the type would exceed i32.
Source§impl ParserAtn
impl ParserAtn
Sourcepub fn from_static(words: &'static [u32]) -> Result<Self, ParserAtnError>
pub fn from_static(words: &'static [u32]) -> Result<Self, ParserAtnError>
Validates and borrows generator-emitted packed data without allocating.
Sourcepub fn from_owned(words: Vec<u32>) -> Result<Self, ParserAtnError>
pub fn from_owned(words: Vec<u32>) -> Result<Self, ParserAtnError>
Validates one owned packed stream.
Sourcepub fn format_version(&self) -> u32
pub fn format_version(&self) -> u32
Canonical generator/runtime format version carried by this ATN.
pub const fn max_token_type(&self) -> i32
pub const fn state_count(&self) -> usize
pub const fn transition_count(&self) -> usize
pub const fn decision_count(&self) -> usize
pub const fn rule_count(&self) -> usize
pub fn state(&self, state_number: usize) -> Option<ParserAtnState<'_>>
pub fn state_by_id(&self, id: AtnStateId) -> Option<ParserAtnState<'_>>
pub const fn states(&self) -> ParserAtnStates<'_> ⓘ
pub fn transition(&self, id: TransitionId) -> Option<ParserTransition<'_>>
pub const fn decision_to_state(&self) -> ParserStateIdTable<'_>
pub const fn rule_to_start_state(&self) -> ParserStateIdTable<'_>
pub const fn rule_to_stop_state(&self) -> ParserStateIdTable<'_>
Sourcepub fn packed_words(&self) -> &[u32]
pub fn packed_words(&self) -> &[u32]
Returns the exact generator-emitted representation.
Sourcepub fn token_set(&self, index: usize) -> Option<ParserIntervalSet<'_>>
pub fn token_set(&self, index: usize) -> Option<ParserIntervalSet<'_>>
Returns one immutable parser token set by its packed metadata index.
Generated rule bodies use this to share the same adaptive membership representation as ATN prediction instead of embedding a second set.