TermParserDriver

Struct TermParserDriver 

Source
pub struct TermParserDriver<I> { /* private fields */ }
Expand description

A driver that defines semantic actions for the term parser.

The TermParserDriver type implements ParserDriver and acts as the bridge between the parser engine (Parser) and calculator-specific semantic logic.

It provides the behavior for grammar reductions and ambiguity resolution during parsing. Each reduction corresponds to a grammar production rule in [ParData], and is responsible for building a term.

§Type Parameters

§Associated Types

  • ParserData = ParData: Generated parser metadata containing grammar rules, production IDs, and ambiguity identifiers.
  • Token = TermToken: The token type produced by the lexer and consumed by this parser.
  • Parser = Parser<I, Self, Arena>: The parser engine parameterized by this driver and context.
  • Error = TermParserError: Unified error type propagated during parsing.
  • Context = Arena: Externally supplied context.

§Responsibilities

The parser driver performs calculator-specific actions:

  • resolve_ambiguity — invoked when the grammar allows multiple valid interpretations of a token sequence. The driver chooses which parse path to follow by returning an appropriate ParserAction.
  • reduce — executed when a grammar production completes. The driver can perform semantic actions such as arithmetic evaluation, updating the symbol table, or producing intermediate values.

Trait Implementations§

Source§

impl<I> ParserDriver for TermParserDriver<I>
where I: TryNextWithContext<Arena, LexerStats, Item = TermToken, Error: Display + 'static>,

Source§

type ParserData = ParData

Parser metadata generated from the calculator grammar.

Source§

type Token = TermToken

Token type consumed by the parser.

Source§

type Parser = Parser<I, TermParserDriver<I>, <TermParserDriver<I> as ParserDriver>::Context>

Concrete parser engine type.

Source§

type Context = Arena

Context (symbol table or shared state).

Source§

fn resolve_ambiguity( &mut self, parser: &mut Self::Parser, arena: &mut Self::Context, ambig: <Self::ParserData as ParserData>::AmbigID, tok2: &Self::Token, ) -> Result<ParserAction<StateID, ProdID, AmbigID>, ParlexError>

Resolves an ambiguity reported by the parser (e.g., shift/reduce).

Given an ambiguity identifier and the lookahead token tok2, this method chooses the appropriate parser action (shift or reduce) according to the operator precedence and associativity rules.

§Parameters
  • _arena: Arena used to allocate or inspect terms.
  • ambig: The generated ambiguity ID (AmbigID).
  • tok2: The lookahead token at the ambiguity point.
§Returns

The selected parser [Action] to disambiguate the current state.

§Errors

Returns an error if the ambiguity cannot be resolved consistently.

§Notes

This grammar contains only Shift/Reduce conflicts — cases where the parser can either:

  • Reduce using a completed production rule, or
  • Shift the next incoming token (tok2).

Other types of conflicts (such as Reduce/Reduce) are much more difficult to handle programmatically and usually require modifying the grammar itself to eliminate ambiguity.

Source§

fn reduce( &mut self, parser: &mut Self::Parser, arena: &mut Self::Context, prod_id: <Self::ParserData as ParserData>::ProdID, token: &Self::Token, ) -> Result<(), ParlexError>

Performs a grammar reduction for the given production rule.

Applies the semantic action for prod_id, typically constructing or normalizing an arena-backed Term, and pushes the resulting token onto the parser’s value stack.

§Parameters
  • arena: Arena used to allocate or inspect terms.
  • prod_id: The production being reduced (ProdID).
  • token: The lookahead token (normally not used).
§Errors

Returns an error if the reduction fails due to arity mismatches, invalid operator metadata, or inconsistent stack state.

Auto Trait Implementations§

§

impl<I> Freeze for TermParserDriver<I>

§

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

§

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

§

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

§

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

§

impl<I> UnwindSafe for TermParserDriver<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