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
I: The input source implementingFusedIteratorover bytes.
Fields§
§opers: OperDefsThe 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.
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 implementFusedIteratorover bytes.
Sourcepub fn try_new(input: I, opers: Option<OperDefs>) -> Result<Self>
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. IfNone, 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>,
impl<I> Lexer<Arena> for TermLexer<I>where
I: FusedIterator<Item = u8>,
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 beFusedIterator<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>
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>
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<()>
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
OperDefsto recognize operators and annotate tokens with operator indices, - and emits tokens via the
yield_*helpers.
§Parameters
arena: TheArenaused for allocating term values produced during lexing.rule: The matched lexer rule (from the generatedLexerData::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.