Skip to main content

RouteSet

Struct RouteSet 

pub struct RouteSet { /* private fields */ }
Expand description

Which reductions still call the user’s ReduceCallback vs. build natively — a transform pays the callback (host-boundary) cost only for rules the user customized; the rest build as a plain parse. Keyed by display (a rule’s callback identity — aliased alternatives get their own; design A1), not rule id. A hooked display fires the callback; the rest take the native BuildTree/splice arms in apply_shape — no hook call (children still build, into the arena or a Splice). Built once by RouteSet::build; fetched per parse via ReduceCallback::routes (None = all hooked, today’s behavior).

It also carries the per-terminal token-callback mask (hooked_tokens), so the shift anchor ([ParserState::shift_token]) can gate ReduceCallback::token_shifted off the same fetched object. The mask is routing-independent — it can be non-empty while every display is un-hooked — so a binding must install the RouteSet whenever either is non-trivial (see all_hooked).

Implementations§

§

impl RouteSet

pub fn build( table: &ParseTable, user_hooked: &[bool], hooked_tokens: &[bool], ) -> RouteSet

Build the route mask (core owns grammar-shape knowledge): seed hooked from user_hooked, and carry the token-callback mask verbatim.

  • user_hooked[display_id]: a user callable resolves (or __default__ overridden — then all true). Never a splice display: the binding rejects user attributes on those at construction (ConfigurationError, ruling 2026-07-12); a violation is debug_asserted here.
  • hooked_tokens[token_id]: a token callback for this terminal. It fires at the SHIFT anchor (see RouteSet / ReduceCallback::token_shifted), NOT by forcing a routing crossing, so it does not touch hooked — it is stored and read per shift. (Before the shift-time move it demoted any display keeping the terminal onto the callback path; that scheme, and its all-hooked fallback for a token callback landing inside a _-rule, are gone — the token’s Handle now flows through the native splice/build arms untouched.)

With user_hooked the only seed of hooked, a splice display is never hooked (hooked && splice is unreachable), so the debug guards below hold unconditionally.

pub fn all_hooked_with_token_mask( n_displays: usize, hooked_tokens: &[bool], ) -> RouteSet

The all-hooked routing carrying only the shift-anchor token mask — the __default__-overridden case. Every display fires the hook (the mask is all-true, so Self::is_hooked is true everywhere and no display is native), routing identically to routes == None ([crate::lalr]’s transform_is_hooked); the only difference is that hooked_tokens rides along so terminal callbacks still reach the shift anchor. Unlike Self::build it seeds no per-display mask and runs no no-hooked-splice check — all-hooked legitimately fires splice displays, which build’s assert (and the binding’s construction-time rejection) forbid for the per-display path. Self::is_inert is false iff the mask is non-empty, so a binding installs it only when a callback exists.

pub fn is_hooked(&self, display_id: DisplayId) -> bool

Does display_id’s reduce fire the hook? Out-of-range ids (the Earley ambiguity sentinels can never reach a transform parse, but defensively) stay hooked.

pub fn all_hooked(&self) -> bool

true when every display is hooked (the display route table is inert — every reduce fires the hook regardless). Display-only by design; a live token mask does not affect it. Use Self::is_inert to decide whether the whole RouteSet can be dropped.

pub fn is_inert(&self) -> bool

true when the object carries no information a parse needs — every display hooked AND no terminal callback. A binding may skip installing the RouteSet iff this holds; installing on !is_inert() keeps the shift anchor’s token mask alive even when all_hooked() (e.g. __default__ overridden with a token callback present).

pub fn mask(&self) -> &[bool]

The raw display mask (introspection/tests).

pub fn hooked_tokens(&self) -> &[bool]

The per-terminal token-callback mask — the shift anchor ([ParserState::shift_token]) gates ReduceCallback::token_shifted on hooked_tokens()[type_id].

Auto Trait Implementations§

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 = !

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.