pub struct Context {
pub iteration: usize,
pub source: String,
pub meta: Value,
pub u: IndexMap<String, Value>,
pub errs: Vec<TabnasError>,
pub options: Arc<Options>,
pub instance: InstanceInfo,
pub rule: Option<Rc<RuleSnapshot>>,
pub rule_stack: Vec<Rc<RuleSnapshot>>,
pub v: VecDeque<Token>,
pub v_abs: usize,
pub t: Vec<Token>,
/* private fields */
}Expand description
Mutable state for one parse run.
Consumed tokens are retained in v so actions can mark and rewind the
parser without asking the lexer to scan source text a second time. Marks
are absolute (v_abs), so bounded-history eviction does not change their
meaning.
Fields§
§iteration: usizeZero-based rule-loop iteration currently being processed.
source: StringFull source text for plugin callbacks and diagnostics.
meta: ValueCaller-supplied per-parse metadata.
u: IndexMap<String, Value>Custom per-parse plugin data bag.
errs: Vec<TabnasError>Errors recorded so far during recovery.
options: Arc<Options>Resolved options for this parse. Shared with the parser and its lexer, which is sound because nothing writes to them once a parse has started. Each parse still gets the options as they stood when it began, so callbacks cannot mutate the shared parser configuration.
instance: InstanceInfoOwning instance identity, installed plugins, and grammar names.
rule: Option<Rc<RuleSnapshot>>Snapshot of the current rule and its ancestor stack. The live rule is still supplied separately to callbacks so mutation remains explicit.
rule_stack: Vec<Rc<RuleSnapshot>>§v: VecDeque<Token>Retained consumed-token history, oldest first.
A VecDeque because the history is trimmed from its front once
it outgrows options.rewind.history. As a Vec that trim moved
every retained token, which amortised to one Token memmove per
token consumed – 1.8% of a parse, for a buffer nothing reads
unless a rewind happens.
v_abs: usizeAbsolute number of tokens consumed minus tokens rewound.
t: Vec<Token>Current lookahead buffer, oldest first.
Implementations§
Source§impl Context
impl Context
pub fn t0(&self) -> Option<&Token>
pub fn t1(&self) -> Option<&Token>
pub fn set_t0(&mut self, token: Token)
pub fn set_t1(&mut self, token: Token)
pub fn set_v1(&mut self, token: Token)
pub fn set_v2(&mut self, token: Token)
pub fn root(&self) -> Option<Value>
Sourcepub fn rewind(&mut self, mark: usize) -> Result<(), ActionError>
pub fn rewind(&mut self, mark: usize) -> Result<(), ActionError>
Replay every token consumed since mark.
Already-fetched lookahead remains behind the rewound tokens. An error
means the requested mark has fallen outside the retained history
window; callers can increase options.rewind.history or select
unbounded history.