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(&mut self, offset: isize) -> Option<&CommonToken>
pub fn lt(&mut self, offset: isize) -> Option<&CommonToken>
Token at one-based lookahead/lookbehind offset.
Sourcepub fn token_text(&mut self, offset: isize) -> Option<&str>
pub fn token_text(&mut self, offset: isize) -> Option<&str>
Token text at one-based lookahead/lookbehind offset.
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 tree(&self) -> Option<&'a ParseTree>
pub const fn tree(&self) -> Option<&'a ParseTree>
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(&mut self) -> String
pub fn action_text(&mut 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 "".