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
Sourcepub fn probe_open(&mut self, rule: &RuleSnapshot)
pub fn probe_open(&mut self, rule: &RuleSnapshot)
Open a probe in rule: the grammar is about to parse ahead and
then rewind to a mark, so the passes until the matching
Context::probe_close are speculative, never the document’s.
@probeInit$ calls it, as must any grammar that probes with
actions of its own. Every crate::RuleDone reports probe for
a pass made while a probe is open, the pass that opens it and the
pass that closes it included. The probe belongs to the rule’s
stack depth, so that error recovery can close it when it abandons
the rule (Context::probe_abandon). TS: ctx.probeOpen(rule).
Sourcepub fn probe_close(&mut self)
pub fn probe_close(&mut self)
Close the innermost open probe (@probeDecide$ calls it, after
its rewind). The pass that closes it is still reported as the
probe’s. TS: ctx.probeClose().
Sourcepub fn probe_depth(&self) -> usize
pub fn probe_depth(&self) -> usize
How many probes are open. TS: ctx.probeDepth().
Sourcepub fn probe_abandon(&mut self, rule: &RuleSnapshot) -> bool
pub fn probe_abandon(&mut self, rule: &RuleSnapshot) -> bool
Error recovery abandons rule, popping it without the pass that
would close the probes it, or a rule above it, opened: close them
here, or every later pass would be reported as a probe’s. Returns
whether the abandoned rule’s synthesized close is a probe’s. TS:
ctx.probeAbandon(rule).
Sourcepub fn probe_take(&mut self) -> bool
pub fn probe_take(&mut self) -> bool
Whether the pass that just ran opened or closed a probe, or ends
inside one, clearing the per-pass flag for the next one. The parse
loop calls it once after every pass, subscribed or not; a pass that
began inside a probe is the probe’s too, which the loop adds, since
recovery may close the probe before the pass is reported. TS:
ctx.probeTake().
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.