Skip to main content

PredContext

Trait PredContext 

Source
pub trait PredContext {
    type TokenText<'a>: AsRef<str>
       where Self: 'a;

Show 13 methods // Required methods fn la(&mut self, offset: isize) -> i64; fn token_text(&mut self, offset: isize) -> Option<Self::TokenText<'_>>; fn token_index_adjacent(&mut self) -> bool; fn ctx_rule_text(&self, rule_index: usize) -> Option<String>; fn member(&self, member: usize) -> Option<i64>; fn local_arg(&self) -> Option<i64>; fn column(&self) -> Option<i64>; fn token_start_column(&self) -> Option<i64>; fn token_text_so_far(&self) -> Option<String>; fn hook(&mut self, hook: HookId) -> bool; // Provided methods fn member_top(&self, _member: usize) -> Option<i64> { ... } fn member_len(&self, _member: usize) -> usize { ... } fn trace_bool(&mut self, value: bool) -> bool { ... }
}
Expand description

Recognizer-state queries the predicate evaluator needs.

Implementations are thin adapters over a lexer or parser; queries that do not exist for the implementing recognizer return None (evaluating to Null). Lookahead methods take &mut self because token streams buffer lazily.

Required Associated Types§

Source

type TokenText<'a>: AsRef<str> where Self: 'a

Required Methods§

Source

fn la(&mut self, offset: isize) -> i64

Token type (parser) or character (lexer) at the given lookahead.

Source

fn token_text(&mut self, offset: isize) -> Option<Self::TokenText<'_>>

Text of the token at the given lookahead, if present.

Source

fn token_index_adjacent(&mut self) -> bool

Whether LT(-2) and LT(-1) are adjacent token-stream entries.

Source

fn ctx_rule_text(&self, rule_index: usize) -> Option<String>

Text of the current context’s first child with this rule index.

Source

fn member(&self, member: usize) -> Option<i64>

Integer member slot value.

Source

fn local_arg(&self) -> Option<i64>

Integer argument of the current rule invocation.

Source

fn column(&self) -> Option<i64>

Lexer current character position within the line.

Source

fn token_start_column(&self) -> Option<i64>

Lexer character position of the current token’s start.

Source

fn token_text_so_far(&self) -> Option<String>

Lexer text matched so far for the in-progress token.

Source

fn hook(&mut self, hook: HookId) -> bool

Evaluates an externally implemented predicate hook.

Provided Methods§

Source

fn member_top(&self, _member: usize) -> Option<i64>

Top of a stack-valued member slot; None when empty or never pushed.

Recognizers with no grammar-declared stack state keep the default.

Source

fn member_len(&self, _member: usize) -> usize

Depth of a stack-valued member slot.

Source

fn trace_bool(&mut self, value: bool) -> bool

Reports an observable predicate-evaluation template and returns value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<I> PredContext for LexerSemIrCtx<'_, I>
where I: CharStream,

Source§

type TokenText<'a> = String where Self: 'a