Skip to main content

LexerSemCtx

Struct LexerSemCtx 

Source
pub struct LexerSemCtx<'a, I>
where I: CharStream,
{ /* private fields */ }
Expand description

Runtime view passed to lexer semantic hooks.

Implementations§

Source§

impl<'a, I> LexerSemCtx<'a, I>
where I: CharStream,

Source

pub const fn rule_index(&self) -> usize

Lexer rule index that owns the predicate/action coordinate.

Source

pub const fn coordinate_index(&self) -> usize

Predicate/action index inside the owning lexer rule.

Source

pub const fn position(&self) -> usize

Absolute input position where the predicate/action transition fired.

Source

pub fn mode(&self) -> i32

Lexer mode at this coordinate.

Source

pub const fn column(&self) -> usize

Current source column.

Source

pub fn position_column(&self) -> usize

Source column at Self::position.

Source

pub const fn token_start_column(&self) -> usize

Column captured at the current token start.

Source

pub fn text_so_far(&self) -> String

Text matched from token start to this coordinate.

Source

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

Character at a one-based lookahead/lookbehind offset.

Predicates read relative to their speculative ATN coordinate. Actions read relative to the committed input cursor, including characters consumed by an earlier action.

Source

pub const fn token_start(&self) -> usize

Absolute source index where the current token begins.

Source

pub const fn token_type(&self) -> i32

Pending type of the token being matched.

Source

pub const fn channel(&self) -> i32

Pending channel of the token being matched.

Source

pub const fn set_type(&mut self, token_type: i32) -> bool

Sets the pending emitted token type. Action context only; see Self::set_mode for the return value.

Source

pub const fn set_channel(&mut self, channel: i32) -> bool

Sets the pending emitted token channel. Action context only; see Self::set_mode for the return value.

Source

pub fn consume(&mut self) -> bool

Consumes one input character and updates source position tracking. Action context only; returns whether the operation was available.

Source

pub const fn skip(&mut self) -> bool

Marks the current match as skipped. Action context only.

Source

pub const fn more(&mut self) -> bool

Extends the current token with another lexer-rule match. Action context only.

Source

pub fn reset_accept_position(&mut self, index: usize) -> bool

Repositions the committed accept cursor. Action context only.

Source

pub fn set_token_start(&mut self, index: usize) -> bool

Moves the current token start forward within the committed match.

This is used after queueing a prefix token so automatic emission covers only the remaining suffix. Returns false for predicate contexts or an index outside the current token span.

Source

pub fn enqueue_token(&mut self, token_type: i32, stop: usize) -> bool

Queues an additional token on the current channel.

The queued token spans the current token start through stop (inclusive) and is returned before the match’s automatically emitted token. Action context only.

Source

pub fn enqueue_token_with_channel( &mut self, token_type: i32, channel: i32, stop: usize, ) -> bool

Queues an additional token on an explicit channel. See Self::enqueue_token.

Source

pub fn set_mode(&mut self, mode: i32) -> bool

Sets the current lexer mode. Available only from a custom-action hook (the mutable-borrow context); a no-op with a warning path for the speculative predicate context, where mutating lexer state is invalid.

Returns true if the mutation was applied (action context), false if it was ignored (predicate context).

Source

pub fn push_mode(&mut self, mode: i32) -> bool

Pushes the current mode and switches to mode. Action context only; see Self::set_mode for the return value.

Source

pub fn pop_mode(&mut self) -> Option<i32>

Pops the mode stack, restoring the previous mode. Action context only; returns the popped mode (None if the stack was empty or this is a predicate context).

Trait Implementations§

Source§

impl<'a, I> Debug for LexerSemCtx<'a, I>
where I: CharStream + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, I> !RefUnwindSafe for LexerSemCtx<'a, I>

§

impl<'a, I> !Send for LexerSemCtx<'a, I>

§

impl<'a, I> !Sync for LexerSemCtx<'a, I>

§

impl<'a, I> !UnwindSafe for LexerSemCtx<'a, I>

§

impl<'a, I> Freeze for LexerSemCtx<'a, I>

§

impl<'a, I> Unpin for LexerSemCtx<'a, I>

§

impl<'a, I> UnsafeUnpin for LexerSemCtx<'a, I>

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.