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