pub trait SemanticHooks {
// Provided methods
fn observes_parser_predicates(&self) -> bool { ... }
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 { ... }
fn lexer_token_emitted(&mut self, token: &CommonToken) { ... }
}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§
Sourcefn observes_parser_predicates(&self) -> bool
fn observes_parser_predicates(&self) -> bool
Whether this hook object may observe parser predicate transitions.
Custom hooks default to conservative predicate handling so the fast
recognizer does not bypass a sempred implementation.
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.)
Sourcefn lexer_token_emitted(&mut self, token: &CommonToken)
fn lexer_token_emitted(&mut self, token: &CommonToken)
Observes a token after committed lexer actions and portable commands have run and the token has been emitted, immediately before it is returned to the token stream.
Hidden and custom-channel tokens are included. skip and intermediate
more matches do not produce callbacks.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".