pub struct ParserSemCtx<'a, S>where
S: TokenSource,{ /* private fields */ }Expand description
Runtime view passed to parser semantic hooks.
The context is intentionally read-only with respect to parser structure: predicates may run speculatively during prediction, and hooks can be called more than once for paths that are later abandoned. Lookahead methods may buffer tokens from the underlying token source, matching normal parser prediction behavior.
Implementations§
Source§impl<'a, S> ParserSemCtx<'a, S>where
S: TokenSource,
impl<'a, S> ParserSemCtx<'a, S>where
S: TokenSource,
Sourcepub const fn rule_index(&self) -> usize
pub const fn rule_index(&self) -> usize
Rule index that owns the predicate/action coordinate.
Sourcepub fn rule_name(&self) -> Option<&str>
pub fn rule_name(&self) -> Option<&str>
Rule name that owns the coordinate, when recognizer metadata has it.
Sourcepub const fn coordinate_index(&self) -> usize
pub const fn coordinate_index(&self) -> usize
Predicate/action index inside the owning rule. Parser actions keyed only
by ATN source state report usize::MAX here; use Self::action for
the stable action event.
Sourcepub fn input_index(&self) -> usize
pub fn input_index(&self) -> usize
Current token-stream index.
Sourcepub fn la(&mut self, offset: isize) -> i32
pub fn la(&mut self, offset: isize) -> i32
Token type at one-based lookahead/lookbehind offset.
Sourcepub fn lt(&self, offset: isize) -> Option<TokenView<'_>>
pub fn lt(&self, offset: isize) -> Option<TokenView<'_>>
Token at one-based lookahead/lookbehind offset.
Sourcepub fn token_text(&self, offset: isize) -> Option<TokenView<'_>>
pub fn token_text(&self, offset: isize) -> Option<TokenView<'_>>
Borrowing token view for text inspection at a one-based offset.
Sourcepub fn token_at(&self, index: usize) -> Option<TokenView<'_>>
pub fn token_at(&self, index: usize) -> Option<TokenView<'_>>
Token at an absolute buffered index, including hidden/custom channels.
Unlike Self::lt, this does not apply the token stream’s channel
filter and does not move its cursor. It is intended for semantic helpers
such as automatic-semicolon-insertion checks that inspect trivia
immediately before the current visible token.
Sourcepub const fn context(&self) -> Option<&'a ParserRuleContext>
pub const fn context(&self) -> Option<&'a ParserRuleContext>
Current generated rule context, when a generated rule predicate supplied one.
Sourcepub const fn parse_tree_storage(&self) -> &'a ParseTreeStorage
pub const fn parse_tree_storage(&self) -> &'a ParseTreeStorage
Flat tree storage containing completed children visible to this hook.
Sourcepub const fn token_store(&self) -> &TokenStore
pub const fn token_store(&self) -> &TokenStore
Canonical token store used by completed flat-tree nodes.
Sourcepub const fn tree_id(&self) -> Option<NodeId>
pub const fn tree_id(&self) -> Option<NodeId>
Completed parse-tree root ID passed to a replayed action hook.
Sourcepub fn tree(&self) -> Option<Node<'_>>
pub fn tree(&self) -> Option<Node<'_>>
Completed parse tree passed to an action hook, if the action is being replayed after recognition.
Sourcepub fn local_int_arg(&self) -> Option<i64>
pub fn local_int_arg(&self) -> Option<i64>
Integer local argument visible to this predicate coordinate.
Sourcepub fn member_int(&self, member: usize) -> Option<i64>
pub fn member_int(&self, member: usize) -> Option<i64>
Integer member value observed on the current speculative path.
Sourcepub const fn action(&self) -> Option<ParserAction>
pub const fn action(&self) -> Option<ParserAction>
Parser action event being replayed, when this context belongs to an action hook.
Sourcepub fn action_text(&self) -> String
pub fn action_text(&self) -> String
Text covered by a parser action event.
Mirrors BaseParser::text_interval / $text: when the stop token is
EOF the interval ends at the previous visible token, so trailing hidden
tokens (and the EOF marker) are excluded rather than blindly subtracting
one, which could point at hidden whitespace. CommonTokenStream::text
itself guards start > stop, so an empty interval yields "".