Skip to main content

Context

Struct Context 

Source
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: usize

Zero-based rule-loop iteration currently being processed.

§source: String

Full source text for plugin callbacks and diagnostics.

§meta: Value

Caller-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: InstanceInfo

Owning 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: usize

Absolute number of tokens consumed minus tokens rewound.

§t: Vec<Token>

Current lookahead buffer, oldest first.

Implementations§

Source§

impl Context

Source

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).

Source

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().

Source

pub fn probe_depth(&self) -> usize

How many probes are open. TS: ctx.probeDepth().

Source

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).

Source

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().

Source

pub fn mark(&self) -> usize

Record the current absolute parse position for a later rewind.

Source

pub fn v1(&self) -> Option<&Token>

Most recently consumed token.

Source

pub fn v2(&self) -> Option<&Token>

Token consumed immediately before v1.

Source

pub fn t0(&self) -> Option<&Token>

Source

pub fn t1(&self) -> Option<&Token>

Source

pub fn set_t0(&mut self, token: Token)

Source

pub fn set_t1(&mut self, token: Token)

Source

pub fn set_v1(&mut self, token: Token)

Source

pub fn set_v2(&mut self, token: Token)

Source

pub fn root(&self) -> Option<Value>

Source

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.

Trait Implementations§

Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.