Skip to main content

BaseLexer

Struct BaseLexer 

Source
pub struct BaseLexer<I, F = CommonTokenFactory> { /* private fields */ }

Implementations§

Source§

impl<I> BaseLexer<I>
where I: CharStream,

Source

pub const fn new(input: I, data: RecognizerData) -> Self

Creates a lexer base using CommonTokenFactory.

Source§

impl<I, F> BaseLexer<I, F>
where I: CharStream, F: TokenFactory,

Source

pub const fn with_factory(input: I, data: RecognizerData, factory: F) -> Self

Creates a lexer base with a custom token factory.

Source

pub const fn input(&self) -> &I

Source

pub const fn input_mut(&mut self) -> &mut I

Source

pub fn begin_token(&mut self)

Captures the input index and source position for the token currently being matched.

Source

pub const fn token_start(&self) -> usize

Returns the absolute character index where the current token began.

Source

pub const fn token_start_line(&self) -> usize

Returns the source line captured at the start of the current token.

Source

pub const fn token_start_column(&self) -> usize

Returns the source column captured at the start of the current token.

Source

pub fn consume_char(&mut self)

Consumes one character from the input stream and updates lexer line and column counters.

The input stream is indexed by Unicode scalar values. Newline handling follows ANTLR’s default convention of incrementing the line and resetting the column after \n.

Source

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

Rewinds or advances the input cursor to a token accept boundary.

Some generated lexers intentionally accept a longer path to disambiguate a token, then emit only the prefix and leave the suffix for the next token. Recomputing line/column from token_start keeps the visible lexer position consistent after moving the cursor backwards.

Source

pub fn emit( &self, token_type: i32, channel: i32, text: Option<String>, ) -> CommonToken

Builds a token spanning from the current token start to the character before the input cursor.

When generated or interpreted lexer code does not supply explicit text, the base lexer captures the matched source interval so downstream token streams and parse trees can render token text without retaining a source pair object.

Source

pub fn emit_with_stop( &self, token_type: i32, channel: i32, stop: usize, text: Option<String>, ) -> CommonToken

Builds a token with an explicit stop index.

EOF-matching lexer rules do not consume a Unicode scalar value, so their stop index can be one before the current input index. The caller passes usize::MAX to represent ANTLR’s -1 stop index at empty input.

Source

pub fn token_text(&self) -> String

Returns the current token text from the token start through the input cursor.

Source

pub fn token_text_until(&self, stop_exclusive: usize) -> String

Returns the current token text from the token start through stop_exclusive.

Lexer custom actions can occur before the accepted token is complete. The action event records the position where the transition fired, and generated action code uses this helper to render ANTLR’s Text() template at that exact point.

Source

pub fn column_at(&self, position: usize) -> usize

Computes the zero-based source column at an absolute input position reached during prediction of the current token.

Source

pub fn eof_token(&self) -> CommonToken

Builds the synthetic EOF token at the current input cursor.

Source§

impl<I, F> BaseLexer<I, F>
where I: CharStream, F: TokenFactory,

Source

pub const fn line(&self) -> usize

Source

pub const fn column(&self) -> usize

Source

pub fn source_name(&self) -> &str

Source

pub const fn hit_eof(&self) -> bool

Source

pub const fn set_hit_eof(&mut self, hit_eof: bool)

Source

pub fn record_error( &mut self, line: usize, column: usize, message: impl Into<String>, )

Buffers a lexer diagnostic until the token stream consumer is ready to emit errors in parser-compatible order.

Source

pub fn drain_errors(&mut self) -> Vec<TokenSourceError>

Returns and clears lexer diagnostics produced while fetching tokens.

Source

pub fn record_lexer_dfa_edge(&mut self, from: usize, symbol: i32, to: usize)

Records a visible lexer DFA edge unless it was already observed.

Source

pub fn lexer_dfa_string(&self) -> String

Serializes the observed default-mode lexer DFA in ANTLR’s text shape.

Trait Implementations§

Source§

impl<I: Clone, F: Clone> Clone for BaseLexer<I, F>

Source§

fn clone(&self) -> BaseLexer<I, F>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug, F: Debug> Debug for BaseLexer<I, F>

Source§

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

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

impl<I, F> Lexer for BaseLexer<I, F>
where I: CharStream, F: TokenFactory,

Source§

fn mode(&self) -> i32

Source§

fn set_mode(&mut self, mode: i32)

Source§

fn push_mode(&mut self, mode: i32)

Source§

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

Source§

impl<I, F> Recognizer for BaseLexer<I, F>
where I: CharStream, F: TokenFactory,

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<I, F> Freeze for BaseLexer<I, F>
where I: Freeze, F: Freeze,

§

impl<I, F> RefUnwindSafe for BaseLexer<I, F>

§

impl<I, F> Send for BaseLexer<I, F>
where I: Send, F: Send,

§

impl<I, F> Sync for BaseLexer<I, F>
where I: Sync, F: Sync,

§

impl<I, F> Unpin for BaseLexer<I, F>
where I: Unpin, F: Unpin,

§

impl<I, F> UnsafeUnpin for BaseLexer<I, F>
where I: UnsafeUnpin, F: UnsafeUnpin,

§

impl<I, F> UnwindSafe for BaseLexer<I, F>
where I: UnwindSafe, F: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.