Skip to main content

ParseCtx

Struct ParseCtx 

Source
pub struct ParseCtx { /* private fields */ }
Expand description

Per-parse context carrying the facts the parser can only learn by first scanning the file’s own definitions (crate::semantic::define) — the sanctioned second pass described in parser::core. Empty for the first pass; populated for the second when the document defines any. Both the lexer and the grammar read it, so the two can never disagree about what a name is.

It carries two families of fact, each read from static definition surface only (no macro meaning, per AGENTS.md Core decision #1):

  1. User-defined verbatim constructs — those a document declares with catcode manipulation (\@makeother\$, …). The lexer consults these (alongside the built-in DB) to capture a verbatim command’s final argument as one VERB token, and a verbatim environment’s body as one VERBATIM_BODY token.
  2. Environment aliases — a command whose definition body is exactly \begin{X}/\end{X}, so \bea … \eea pairs as an ENVIRONMENT of X (issue #109). The grammar consults these; the lexer does not.

A command entry maps a name (no leading \) to its leading, non-verbatim argument shape, the verbatim argument itself being implicit — matching the built-in convention. An environment entry maps a name to its full argument shape (an environment’s args are all leading; its body follows the \begin{…} arguments), so presence in environments means the environment is verbatim.

suppressed names the inverse case: commands the current file redefines to an ordinary (non-verbatim) macro whose name collides with a built-in raw-argument command (\code, \url, \href, …). A local definition shadows the built-in, so [lex_verbatim_command] must lex \code{…} as an ordinary group rather than capture the built-in VERB (follow-up to issue #53). We read only static definition facts (a visible \newcommand/\def with no catcode signal), never macro meaning. PartialEq is load-bearing rather than incidental: parser::core decides whether the second pass has anything to do by comparing the scanned context against the declaration seed it started from, which stays correct as fields are added in a way a hand-maintained “did anything change” flag would not.

Implementations§

Source§

impl ParseCtx

Source

pub fn is_empty(&self) -> bool

Whether the context names nothing at all — no user verbatim constructs, no suppressions, and no environment aliases — so the second parse pass can be skipped entirely (the common case).

Every map must be accounted for here: a file that defines an alias but no verbatim construct would otherwise never reach pass 2, and its aliases would silently do nothing.

Source

pub fn overlay_declarations(&mut self, declared: &ResolvedDeclarations)

Overlay a project’s declarations onto this context, taking precedence over anything already recorded.

Declared beats scanned because a declaration is the user explicitly correcting an inference (AGENTS.md decision #12), which is why this is an overlay applied after the scan rather than a seed the scan writes over.

Two families cross over: the declared environment signatures, which every body-routing predicate here then answers from, and the delimiter spellings. The alias entries skip the “is it called anywhere” filter parser::core::parse_ctx applies to scanned ones: that filter exists to avoid buying a second pass for an alias no call site uses, and a declaration is already in hand before the first.

Trait Implementations§

Source§

impl Clone for ParseCtx

Source§

fn clone(&self) -> ParseCtx

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParseCtx

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ParseCtx

Source§

fn default() -> ParseCtx

Returns the “default value” for a type. Read more
Source§

impl Eq for ParseCtx

Source§

impl PartialEq for ParseCtx

Source§

fn eq(&self, other: &ParseCtx) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ParseCtx

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.