TermLexer

Struct TermLexer 

Source
pub struct TermLexer<I>
where I: FusedIterator<Item = u8>,
{ pub opers: OperDefs, /* private fields */ }
Expand description

The main lexer for Prolog-like terms.

TermLexer tokenizes input streams into TermTokens using DFA tables generated by parlex-gen’s alex tool. It maintains lexer state, manages nested constructs, and recognizes operators defined in OperDefs.

§Type Parameters

Fields§

§opers: OperDefs

The operator definition table used to resolve operator fixity, precedence, and associativity during lexing.

Implementations§

Source§

impl<I> TermLexer<I>
where I: FusedIterator<Item = u8>,

Implementation of TermLexer methods.

This impl provides core construction logic for initializing a new term lexer instance. It prepares the internal LexerCtx state, sets up operator definitions, and initializes all internal counters used for managing nested structures and special tokens.

§Type Parameters

  • I: The input source, which must implement FusedIterator over bytes.
Source

pub fn try_new(input: I, opers: Option<OperDefs>) -> Result<Self>

Constructs a new TermLexer from the given input stream.

Initializes the internal LexerCtx, loads operator definitions if provided, and resets all nesting and parsing counters.

§Parameters
  • input: The input byte stream to be lexed.
  • opers: Optional operator definitions (OperDefs) used to recognize operator tokens by fixity and precedence. If None, an empty operator table is created.
§Returns

A ready-to-use TermLexer instance, or an error if the underlying LexerCtx initialization fails.

§Errors

Returns an error if DFA table deserialization in LexerCtx::try_new fails or the input cannot be processed.

Trait Implementations§

Source§

impl<I> Lexer<Arena> for TermLexer<I>
where I: FusedIterator<Item = u8>,

Implements the Lexer trait for TermLexer, integrating with the parlex core library.

This binding wires the generated DFA / rule set (LexData) to the concrete term-lexing behavior provided by TermLexer. It exposes the lexer context and defines the rule action callback that builds TermTokens.

§Associated Types

  • Input — The input byte iterator (must be FusedIterator<Item = u8>).
  • LexerData — The generated lexer tables and rule enums (LexData).
  • Token — The token type produced by this lexer (TermToken).
Source§

fn ctx(&self) -> &LexerCtx<Self::Input, Self::LexerData, Self::Token>

Returns a shared reference to the internal LexerCtx.

Source§

fn ctx_mut( &mut self, ) -> &mut LexerCtx<Self::Input, Self::LexerData, Self::Token>

Returns a mutable reference to the internal LexerCtx.

Source§

fn action( &mut self, arena: &mut Arena, rule: <Self::LexerData as LexerData>::LexerRule, ) -> Result<()>

The primary user callback invoked by the parlex lexer for each matched rule.

This method implements the term-specific lexing logic:

  • constructs arena-backed values (atoms, numbers, strings, dates, etc.),
  • tracks nesting (parentheses, braces, comments, script blocks),
  • consults OperDefs to recognize operators and annotate tokens with operator indices,
  • and emits tokens via the yield_* helpers.
§Parameters
  • arena: The Arena used for allocating term values produced during lexing.
  • rule: The matched lexer rule (from the generated LexerData::LexerRule).
§Returns

Ok(()) on success; an error if token construction or state handling fails.

§Errors

Propagates errors from value parsing (e.g., numeric/date parsing), arena allocation, or invalid state transitions.

Source§

type Input = I

The input stream type producing bytes for lexing.
Source§

type LexerData = LexData

The lexer data providing DFA tables and rule definitions. Must be provided by the implementer and must be the struct generated by parlex-gen’s lexer generator, Alex.
Source§

type Token = TermToken

The token type produced by the lexer. Must be provided by the implementor.
Source§

fn stats(&self) -> LexerStats

Returns current lexer statistics.
Source§

fn try_collect(&mut self, user_data: &mut U) -> Result<Vec<Self::Token>, Error>

Collects all tokens from the input until exhaustion.
Source§

fn try_next(&mut self, user_data: &mut U) -> Result<Option<Self::Token>, Error>

Attempts to fetch the next token from the input stream.
Source§

fn accum(&mut self)

Switches on accumulation of bytes into the buffer.
Source§

fn begin(&mut self, mode: <Self::LexerData as LexerData>::LexerMode)

Switches the lexer to a different mode.
Source§

fn yield_token(&mut self, token: Self::Token)

Emits a token into the output queue.
Source§

fn clear(&mut self)

Clears the current buffer and disables accumulation.
Source§

fn take_bytes(&mut self) -> Vec<u8>

Takes accumulated bytes from the main buffer.
Source§

fn take_bytes2(&mut self) -> Vec<u8>

Takes accumulated bytes from the secondary buffer.
Source§

fn take_str(&mut self) -> Result<SmartString<LazyCompact>, Error>

Takes accumulated bytes from the main buffer and converts them into a UTF-8 string.
Source§

fn take_str2(&mut self) -> Result<SmartString<LazyCompact>, Error>

Takes accumulated bytes from the secondary buffer and converts them into a UTF-8 string.
Source§

fn extend_buffer2_with_buffer(&mut self)

Extends the secondary buffer with the contents of the main buffer.

Auto Trait Implementations§

§

impl<I> Freeze for TermLexer<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for TermLexer<I>
where I: RefUnwindSafe,

§

impl<I> Send for TermLexer<I>
where I: Send,

§

impl<I> Sync for TermLexer<I>
where I: Sync,

§

impl<I> Unpin for TermLexer<I>
where I: Unpin,

§

impl<I> UnwindSafe for TermLexer<I>
where I: 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V