Skip to main content

ParserSemCtx

Struct ParserSemCtx 

Source
pub struct ParserSemCtx<'a, S>
where S: TokenSource,
{ /* private fields */ }
Expand description

Runtime view passed to parser semantic hooks.

The context is intentionally read-only with respect to parser structure: predicates may run speculatively during prediction, and hooks can be called more than once for paths that are later abandoned. Lookahead methods may buffer tokens from the underlying token source, matching normal parser prediction behavior.

Implementations§

Source§

impl<'a, S> ParserSemCtx<'a, S>
where S: TokenSource,

Source

pub const fn rule_index(&self) -> usize

Rule index that owns the predicate/action coordinate.

Source

pub fn rule_name(&self) -> Option<&str>

Rule name that owns the coordinate, when recognizer metadata has it.

Source

pub const fn coordinate_index(&self) -> usize

Predicate/action index inside the owning rule. Parser actions keyed only by ATN source state report usize::MAX here; use Self::action for the stable action event.

Source

pub fn input_index(&self) -> usize

Current token-stream index.

Source

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

Token type at one-based lookahead/lookbehind offset.

Source

pub fn lt(&mut self, offset: isize) -> Option<&CommonToken>

Token at one-based lookahead/lookbehind offset.

Source

pub fn token_text(&mut self, offset: isize) -> Option<&str>

Token text at one-based lookahead/lookbehind offset.

Source

pub const fn context(&self) -> Option<&'a ParserRuleContext>

Current generated rule context, when a generated rule predicate supplied one.

Source

pub const fn tree(&self) -> Option<&'a ParseTree>

Completed parse tree passed to an action hook, if the action is being replayed after recognition.

Source

pub fn local_int_arg(&self) -> Option<i64>

Integer local argument visible to this predicate coordinate.

Source

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

Integer member value observed on the current speculative path.

Source

pub const fn action(&self) -> Option<ParserAction>

Parser action event being replayed, when this context belongs to an action hook.

Source

pub fn action_text(&mut self) -> String

Text covered by a parser action event.

Mirrors BaseParser::text_interval / $text: when the stop token is EOF the interval ends at the previous visible token, so trailing hidden tokens (and the EOF marker) are excluded rather than blindly subtracting one, which could point at hidden whitespace. CommonTokenStream::text itself guards start > stop, so an empty interval yields "".

Trait Implementations§

Source§

impl<S> Debug for ParserSemCtx<'_, S>
where S: TokenSource,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, S> !RefUnwindSafe for ParserSemCtx<'a, S>

§

impl<'a, S> !Send for ParserSemCtx<'a, S>

§

impl<'a, S> !Sync for ParserSemCtx<'a, S>

§

impl<'a, S> !UnwindSafe for ParserSemCtx<'a, S>

§

impl<'a, S> Freeze for ParserSemCtx<'a, S>

§

impl<'a, S> Unpin for ParserSemCtx<'a, S>

§

impl<'a, S> UnsafeUnpin for ParserSemCtx<'a, S>

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.