Skip to main content

ParserGuard

Struct ParserGuard 

Source
pub struct ParserGuard<'p, 'a, 'ctx, 'int> { /* private fields */ }
Expand description

RAII guard for speculative parsing with automatic rollback.

Created by Parser::guard(), this guard saves the parser state on creation and automatically restores it if the guard is dropped without being committed.

§Usage

let mut guard = parser.guard();
if let Ok(result) = try_parse(&mut *guard) {
    guard.commit(); // Success - keep changes
    return Ok(result);
}
// guard dropped here - parser state restored

Implementations§

Source§

impl<'p, 'a, 'ctx, 'int> ParserGuard<'p, 'a, 'ctx, 'int>

Source

pub fn commit(self)

Commits the parse, preventing rollback when the guard is dropped.

Methods from Deref<Target = Parser<'a, 'ctx, 'int>>§

Source

pub fn stmt_spans(&self) -> &[Span]

The span of each top-level statement from the last parse_program call, aligned 1:1 with the returned statement list.

Source

pub fn set_discourse_event_var(&mut self, var: Symbol)

Source

pub fn drs_mut(&mut self) -> &mut Drs

Get mutable reference to the active DRS (from WorldState).

Source

pub fn drs_ref(&self) -> &Drs

Get immutable reference to the active DRS (from WorldState).

Source

pub fn swap_drs_with_world_state(&mut self)

Swap DRS between Parser and WorldState. Call at start of parsing to get the accumulated DRS from WorldState. Call at end of parsing to save the updated DRS back to WorldState.

Source

pub fn has_world_state(&self) -> bool

WorldState is always present (no “single sentence mode”)

Source

pub fn mode(&self) -> ParserMode

Source

pub fn is_known_type(&self, sym: Symbol) -> bool

Check if a symbol is a known type in the registry. Used to disambiguate “Stack of Integers” (generic type) vs “Owner of House” (possessive).

Source

pub fn is_generic_type(&self, sym: Symbol) -> bool

Check if a symbol is a known generic type (takes type parameters). Used to parse “Stack of Integers” as generic instantiation.

Source

pub fn process_block_headers(&mut self)

Source

pub fn get_event_var(&mut self) -> Symbol

Source

pub fn capture_event_template( &mut self, verb: Symbol, roles: &[(ThematicRole, Term<'a>)], modifiers: &[Symbol], )

Source

pub fn set_pp_attachment_mode(&mut self, attach_to_noun: bool)

Source

pub fn set_noun_priority_mode(&mut self, mode: bool)

Source

pub fn set_collective_mode(&mut self, mode: bool)

Source

pub fn set_distributive_marker(&mut self, on: bool)

Force the distributive (per-member) reading of mixed verbs with definite plurals — the readings enumerator’s counterpart to the default collective reading.

Source

pub fn set_pragmatic_mode(&mut self, on: bool)

Enable pragmatic enrichment (scalar implicatures, degree standards) for whole-program parses — the defeasible theorem door needs the implicature channel that the literal parse omits.

Source

pub fn set_event_reading_mode(&mut self, mode: bool)

Source

pub fn set_negative_scope_mode(&mut self, mode: NegativeScopeMode)

Source

pub fn set_modal_preference(&mut self, pref: ModalPreference)

Source

pub fn guard(&mut self) -> ParserGuard<'_, 'a, 'ctx, 'int>

Source

pub fn parse(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>

Parses the token stream into a logical expression.

This is the main entry point for declarative/FOL parsing. It handles multi-sentence inputs by conjoining them with logical AND, and processes various sentence types including declaratives, questions, and imperatives.

§Returns

An arena-allocated LogicExpr representing the parsed input, or a ParseError with source location and Socratic explanation.

§Discourse State

The parser maintains discourse state across sentences, enabling anaphora resolution (“he”, “she”, “they” refer to prior entities) and temporal coherence (tense interpretation relative to reference time).

Source

pub fn parse_pragmatic(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>

Parses with pragmatic enrichment: the truth-conditional parse PLUS scalar implicature (§8.7). The literal parse() is unchanged; here a leading weak scalar “some” is strengthened to ∃… +> ¬∀…. Used by the pragmatic compile path so the implicature appears as a separate labeled component.

Source

pub fn parse_program(&mut self) -> Result<Vec<Stmt<'a>>, ParseError>

Parses a LOGOS program into a list of statements.

This is the main entry point for imperative/executable LOGOS code. It handles block structures (Definition, Policy, Procedure, Theorem), function definitions, type definitions, and executable statements.

§Returns

A vector of arena-allocated Stmt representing the program, or a ParseError with source location and Socratic explanation.

§Block Types
  • Definition: Type definitions (structs, enums, generics)
  • Policy: Security predicates and capability rules
  • Procedure: Executable code blocks
  • Theorem: Logical propositions with proof strategies
Source

pub fn program_opt_flags(&self) -> OptimizationConfig

The program-wide optimization config from file-level ## No <X> decorators (all-on minus the file-level disables). The compile entry combines this with from_env and per-function flags.

Source

pub fn program_tier_pins(&self) -> PinSet

The program-wide tiered-optimizer pins from file-level ## Tier <opt> <value> decorators (HOTSWAP §8). The run-path engine overlays these onto the env crate::optimization::HotswapConfig before optimizing.

Trait Implementations§

Source§

impl<'p, 'a, 'ctx, 'int> Deref for ParserGuard<'p, 'a, 'ctx, 'int>

Source§

type Target = Parser<'a, 'ctx, 'int>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<ParserGuard<'p, 'a, 'ctx, 'int> as Deref>::Target

Dereferences the value.
Source§

impl<'p, 'a, 'ctx, 'int> DerefMut for ParserGuard<'p, 'a, 'ctx, 'int>

Source§

fn deref_mut( &mut self, ) -> &mut <ParserGuard<'p, 'a, 'ctx, 'int> as Deref>::Target

Mutably dereferences the value.
Source§

impl<'p, 'a, 'ctx, 'int> Drop for ParserGuard<'p, 'a, 'ctx, 'int>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'p, 'a, 'ctx, 'int> Freeze for ParserGuard<'p, 'a, 'ctx, 'int>

§

impl<'p, 'a, 'ctx, 'int> !RefUnwindSafe for ParserGuard<'p, 'a, 'ctx, 'int>

§

impl<'p, 'a, 'ctx, 'int> !Send for ParserGuard<'p, 'a, 'ctx, 'int>

§

impl<'p, 'a, 'ctx, 'int> !Sync for ParserGuard<'p, 'a, 'ctx, 'int>

§

impl<'p, 'a, 'ctx, 'int> Unpin for ParserGuard<'p, 'a, 'ctx, 'int>

§

impl<'p, 'a, 'ctx, 'int> UnsafeUnpin for ParserGuard<'p, 'a, 'ctx, 'int>

§

impl<'p, 'a, 'ctx, 'int> !UnwindSafe for ParserGuard<'p, 'a, 'ctx, 'int>

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,