pub trait SemanticHooks {
// Provided methods
fn sempred<S>(
&mut self,
ctx: &mut ParserSemCtx<'_, S>,
rule_index: usize,
pred_index: usize,
) -> Option<bool>
where S: TokenSource { ... }
fn action<S>(
&mut self,
ctx: &mut ParserSemCtx<'_, S>,
action: ParserAction,
) -> bool
where S: TokenSource { ... }
fn lexer_sempred<I, F>(
&mut self,
ctx: &mut LexerSemCtx<'_, I, F>,
rule_index: usize,
pred_index: usize,
) -> Option<bool>
where I: CharStream,
F: TokenFactory { ... }
fn lexer_action<I, F>(
&mut self,
ctx: &mut LexerSemCtx<'_, I, F>,
action: LexerCustomAction,
) -> bool
where I: CharStream,
F: TokenFactory { ... }
}Expand description
User extension point for parser semantic predicates and actions that the metadata generator did not translate into built-in runtime metadata.
Returning None/false says “not handled”, so the runtime falls through
to the configured UnknownSemanticPolicy. Predicate hooks may run during
speculative prediction and must be replay-safe.
Provided Methods§
fn sempred<S>(
&mut self,
ctx: &mut ParserSemCtx<'_, S>,
rule_index: usize,
pred_index: usize,
) -> Option<bool>where
S: TokenSource,
fn action<S>(
&mut self,
ctx: &mut ParserSemCtx<'_, S>,
action: ParserAction,
) -> boolwhere
S: TokenSource,
fn lexer_sempred<I, F>(
&mut self,
ctx: &mut LexerSemCtx<'_, I, F>,
rule_index: usize,
pred_index: usize,
) -> Option<bool>where
I: CharStream,
F: TokenFactory,
Sourcefn lexer_action<I, F>(
&mut self,
ctx: &mut LexerSemCtx<'_, I, F>,
action: LexerCustomAction,
) -> boolwhere
I: CharStream,
F: TokenFactory,
fn lexer_action<I, F>(
&mut self,
ctx: &mut LexerSemCtx<'_, I, F>,
action: LexerCustomAction,
) -> boolwhere
I: CharStream,
F: TokenFactory,
Runs a lexer custom action on the committed lexing path. Returns whether the hook handled the action.
The action runs post-accept, so ctx carries a mutable lexer borrow: a
hook may change lexer state — LexerSemCtx::push_mode,
LexerSemCtx::pop_mode, LexerSemCtx::set_mode — just like the
closure-based custom_action API. (The speculative predicate context in
Self::lexer_sempred is a shared borrow, so those mutators are inert
there.)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".