LexerCtx

Struct LexerCtx 

Source
pub struct LexerCtx<I, D, T>
where D: LexerData,
{ pub mode: D::LexerMode, pub accum_flag: bool, pub buffer: Vec<u8>, pub buffer2: Vec<u8>, pub end_flag: bool, pub line_no: usize, /* private fields */ }
Expand description

Core lexer execution context.

LexerCtx manages the entire runtime state of the lexer, including its input stream, DFA tables, buffers, and recognized tokens. It is responsible for coordinating lexing operations, tracking position and mode, and maintaining internal statistics.

§Type Parameters

  • I: The input source, typically an iterator over bytes.
  • D: The lexer definition, which implements the LexerData trait. This type is usually generated by the parlex-gen lexer generator (Alex).
  • T: The token type produced by the lexer.

Fields§

§mode: D::LexerMode

The current lexer mode, defined by the lexer data type D.

§accum_flag: bool

Indicates whether the lexer is currently accumulating token text.

§buffer: Vec<u8>

Primary buffer used to accumulate the characters of the current token.

§buffer2: Vec<u8>

Secondary buffer available to the user, for example, for constructing more complex tokens.

§end_flag: bool

Signals that the end of input has been reached.

§line_no: usize

The current line number in the input, used for diagnostics.

Implementations§

Source§

impl<I, D, T> LexerCtx<I, D, T>
where I: FusedIterator<Item = u8>, D: LexerData, T: Token,

Implementation of LexerCtx methods.

This impl defines the primary construction and matching logic for the lexer context. It provides methods to initialize a new lexer context instance, load DFA tables, and perform token matching over the input stream.

§Type Parameters

  • I: The input source, which must be a FusedIterator yielding bytes.
  • D: The lexer definition type implementing the LexerData trait. This type is usually generated by the parlex-gen lexer generator (Alex).
  • T: The token type implementing the Token trait.
Source

pub fn try_new(input: I) -> Result<Self>

Constructs a new LexerCtx from the given input.

This initializes DFA tables from D::dfa_bytes(), sets the lexer to its starting mode, and prepares all buffers and counters for processing.

§Parameters
  • input: A fused iterator of bytes serving as the lexer’s input stream.
§Returns

A fully initialized lexer context, or an error if the DFA tables cannot be deserialized.

§Errors

Returns an error if any DFA fails to deserialize via dense::DFA::from_bytes.

Auto Trait Implementations§

§

impl<I, D, T> Freeze for LexerCtx<I, D, T>
where <D as LexerData>::LexerMode: Freeze, I: Freeze,

§

impl<I, D, T> RefUnwindSafe for LexerCtx<I, D, T>

§

impl<I, D, T> Send for LexerCtx<I, D, T>
where <D as LexerData>::LexerMode: Send, I: Send, T: Send,

§

impl<I, D, T> Sync for LexerCtx<I, D, T>
where <D as LexerData>::LexerMode: Sync, I: Sync, T: Sync,

§

impl<I, D, T> Unpin for LexerCtx<I, D, T>
where <D as LexerData>::LexerMode: Unpin, I: Unpin, T: Unpin,

§

impl<I, D, T> UnwindSafe for LexerCtx<I, D, T>

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.