Skip to main content

BaseParser

Struct BaseParser 

Source
pub struct BaseParser<S> { /* private fields */ }

Implementations§

Source§

impl<S> BaseParser<S>
where S: TokenSource,

Source

pub const fn new(input: CommonTokenStream<S>, data: RecognizerData) -> Self

Creates a parser base over a buffered token stream and recognizer metadata.

Source

pub const fn input(&mut self) -> &mut CommonTokenStream<S>

Source

pub fn la(&mut self, offset: isize) -> i32

Source

pub fn consume(&mut self)

Source

pub fn set_int_member(&mut self, member: usize, value: i64)

Sets a generated integer member value used by target-template tests.

Source

pub fn int_member(&self, member: usize) -> Option<i64>

Reads a generated integer member value.

Source

pub fn add_int_member(&mut self, member: usize, delta: i64) -> i64

Adds delta to a generated integer member and returns the new value.

Source

pub fn match_token(&mut self, token_type: i32) -> Result<ParseTree, AntlrError>

Matches and consumes the current token when it has the expected token type.

On success the consumed token is wrapped as a terminal parse-tree node. On mismatch the error carries vocabulary display names so diagnostics are stable across literal and symbolic token naming.

Source

pub fn match_eof(&mut self) -> Result<ParseTree, AntlrError>

Source

pub const fn rule_node(&self, context: ParserRuleContext) -> ParseTree

Source

pub fn parse_atn_rule( &mut self, atn: &Atn, rule_index: usize, ) -> Result<ParseTree, AntlrError>

Parses a generated rule by interpreting the parser ATN from the rule’s start state to its stop state.

The recognizer backtracks across alternatives and loop exits using token stream indices instead of committing to input consumption immediately. Once a viable ATN path is found, the parser commits the accepted token interval and returns a rule node whose children mirror every grammar rule invocation reached on that path, matching ANTLR’s parse-tree shape.

Source

pub fn parse_atn_rule_with_actions( &mut self, atn: &Atn, rule_index: usize, ) -> Result<(ParseTree, Vec<ParserAction>), AntlrError>

Parses a generated rule and returns semantic actions reached on the selected ATN path.

This slower path preserves action ordering and token intervals for generated code that replays target-specific action templates after the recognizer has chosen one viable parse path.

Source

pub fn parse_atn_rule_with_action_inits( &mut self, atn: &Atn, rule_index: usize, init_action_rules: &[usize], ) -> Result<(ParseTree, Vec<ParserAction>), AntlrError>

Parses a generated rule and emits ATN actions plus selected rule-init actions reached on the chosen path.

Generated parsers use this when a grammar contains rule-level @init templates that must run for nested rule invocations. The runtime keeps the action list path-sensitive, so init templates are replayed only for rules that were actually entered by the selected parse.

Source

pub fn parse_atn_rule_with_action_options( &mut self, atn: &Atn, rule_index: usize, init_action_rules: &[usize], track_alt_numbers: bool, ) -> Result<(ParseTree, Vec<ParserAction>), AntlrError>

Parses a generated rule with optional semantic-action replay features.

track_alt_numbers is used by grammars that opt into ANTLR’s alt-numbered context behavior. It keeps ordinary parse-tree rendering unchanged for grammars that do not request that target template.

Source

pub fn parse_atn_rule_with_runtime_options( &mut self, atn: &Atn, rule_index: usize, options: ParserRuntimeOptions<'_>, ) -> Result<(ParseTree, Vec<ParserAction>), AntlrError>

Parses a generated rule with action replay and parser predicate support.

predicates maps serialized (rule_index, pred_index) coordinates to target-template predicate semantics emitted by the generator. Missing entries are treated as true so unsupported predicate-free grammars keep the previous unconditional transition behavior.

Source

pub fn parse_interpreted_rule( &mut self, rule_index: usize, ) -> Result<ParseTree, AntlrError>

Temporary parser entry used by generated parser methods while the parser ATN simulator is being implemented.

This keeps generated parser crates buildable and gives us a stable method surface for every grammar rule. It intentionally accepts all remaining tokens into one rule context; it is not the final parser semantics.

Source

pub fn text_interval(&mut self, start: usize, stop: Option<usize>) -> String

Returns token text for a buffered token interval used by generated $text actions.

ANTLR treats EOF as a range boundary rather than printable input text, even when an action interval explicitly stops at the EOF token.

Source

pub fn expected_tokens_at_state(&self, atn: &Atn, state_number: usize) -> String

Formats the tokens expected from an ATN state using ANTLR display names.

Source

pub fn token_display_at(&mut self, index: usize) -> Option<String>

Formats a buffered token in ANTLR’s diagnostic token display form.

Trait Implementations§

Source§

impl<S: Debug> Debug for BaseParser<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> Parser for BaseParser<S>
where S: TokenSource,

Source§

fn build_parse_trees(&self) -> bool

Reports whether generated parser rules should build parse-tree nodes while recognizing input.
Source§

fn set_build_parse_trees(&mut self, build: bool)

Enables or disables parse-tree construction for subsequent rule calls.
Source§

fn report_diagnostic_errors(&self) -> bool

Reports whether prediction diagnostic-listener messages are emitted during parser ATN recognition.
Source§

fn set_report_diagnostic_errors(&mut self, report: bool)

Enables or disables ANTLR-style prediction diagnostics for subsequent rule calls.
Source§

fn prediction_mode(&self) -> PredictionMode

Reports the prediction strategy used when selecting among alternatives.
Source§

fn set_prediction_mode(&mut self, mode: PredictionMode)

Sets the prediction strategy for subsequent rule calls.
Source§

impl<S> Recognizer for BaseParser<S>
where S: TokenSource,

Source§

fn data(&self) -> &RecognizerData

Source§

fn data_mut(&mut self) -> &mut RecognizerData

Source§

fn grammar_file_name(&self) -> &str

Source§

fn rule_names(&self) -> &[String]

Source§

fn channel_names(&self) -> &[String]

Source§

fn mode_names(&self) -> &[String]

Source§

fn vocabulary(&self) -> &Vocabulary

Source§

fn state(&self) -> isize

Source§

fn set_state(&mut self, state: isize)

Source§

fn sempred(&mut self, _rule_index: usize, _pred_index: usize) -> bool

Source§

fn action(&mut self, _rule_index: usize, _action_index: usize)

Auto Trait Implementations§

§

impl<S> Freeze for BaseParser<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for BaseParser<S>
where S: RefUnwindSafe,

§

impl<S> Send for BaseParser<S>
where S: Send,

§

impl<S> Sync for BaseParser<S>
where S: Sync,

§

impl<S> Unpin for BaseParser<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for BaseParser<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for BaseParser<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.