pub struct Parser<'a, 'ctx, 'int> { /* private fields */ }Expand description
Recursive descent parser for natural language to first-order logic.
The parser transforms a token stream (from Lexer) into logical expressions
(LogicExpr). It handles complex linguistic phenomena including:
- Quantifier scope ambiguity
- Pronoun resolution via DRS
- Modal verb interpretation
- Temporal and aspectual marking
- VP ellipsis resolution
§Lifetimes
'a: Arena lifetime for allocated AST nodes'ctx: WorldState lifetime for discourse tracking'int: Interner lifetime for symbol management
Implementations§
Source§impl<'a, 'ctx, 'int> Parser<'a, 'ctx, 'int>
impl<'a, 'ctx, 'int> Parser<'a, 'ctx, 'int>
Sourcepub fn new(
tokens: Vec<Token>,
world_state: &'ctx mut WorldState,
interner: &'int mut Interner,
ctx: AstContext<'a>,
types: TypeRegistry,
) -> Self
pub fn new( tokens: Vec<Token>, world_state: &'ctx mut WorldState, interner: &'int mut Interner, ctx: AstContext<'a>, types: TypeRegistry, ) -> Self
Create a parser with WorldState for discourse-level parsing. WorldState is REQUIRED - there is no “single sentence mode”. A single sentence is just a discourse of length 1.
pub fn set_discourse_event_var(&mut self, var: Symbol)
Sourcepub fn drs_mut(&mut self) -> &mut Drs
pub fn drs_mut(&mut self) -> &mut Drs
Get mutable reference to the active DRS (from WorldState).
Sourcepub fn swap_drs_with_world_state(&mut self)
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.
Sourcepub fn has_world_state(&self) -> bool
pub fn has_world_state(&self) -> bool
WorldState is always present (no “single sentence mode”)
pub fn mode(&self) -> ParserMode
Sourcepub fn is_known_type(&self, sym: Symbol) -> bool
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).
Sourcepub fn is_generic_type(&self, sym: Symbol) -> bool
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.
pub fn process_block_headers(&mut self)
pub fn get_event_var(&mut self) -> Symbol
pub fn capture_event_template( &mut self, verb: Symbol, roles: &[(ThematicRole, Term<'a>)], modifiers: &[Symbol], )
pub fn set_pp_attachment_mode(&mut self, attach_to_noun: bool)
pub fn set_noun_priority_mode(&mut self, mode: bool)
pub fn set_collective_mode(&mut self, mode: bool)
pub fn set_event_reading_mode(&mut self, mode: bool)
pub fn set_negative_scope_mode(&mut self, mode: NegativeScopeMode)
pub fn set_modal_preference(&mut self, pref: ModalPreference)
pub fn guard(&mut self) -> ParserGuard<'_, 'a, 'ctx, 'int>
Sourcepub fn parse(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
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).
Sourcepub fn parse_program(&mut self) -> Result<Vec<Stmt<'a>>, ParseError>
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
Trait Implementations§
Source§impl<'a, 'ctx, 'int> ClauseParsing<'a, 'ctx, 'int> for Parser<'a, 'ctx, 'int>
impl<'a, 'ctx, 'int> ClauseParsing<'a, 'ctx, 'int> for Parser<'a, 'ctx, 'int>
Source§fn parse_either_or(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_either_or(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
Parse “Either NP1 or NP2 is/are PRED” or “Either S1 or S2”
Handles coordination: “Either Alice or Bob is guilty” should become guilty(Alice) ∨ guilty(Bob), not Alice ∨ guilty(Bob)
Source§fn parse_gapped_clause(
&mut self,
borrowed_verb: Symbol,
) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_gapped_clause( &mut self, borrowed_verb: Symbol, ) -> Result<&'a LogicExpr<'a>, ParseError>
Phase 46: Generalized gapping with template-guided reconstruction. Handles NPs, PPs, temporal adverbs, and preserves roles from EventTemplate.
Source§fn parse_disjunction(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_disjunction(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
Parse disjunction (Or/Iff) - lowest precedence logical connectives. Calls parse_conjunction for operands to ensure And binds tighter.
Source§fn parse_conjunction(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_conjunction(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
Parse conjunction (And) - higher precedence than Or. Calls parse_atom for operands.
Source§fn parse_sentence(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_sentence(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
Source§fn check_wh_word(&self) -> bool
fn check_wh_word(&self) -> bool
Source§fn parse_conditional(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_conditional(&mut self) -> Result<&'a LogicExpr<'a>, ParseError>
Source§fn is_counterfactual_context(&self) -> bool
fn is_counterfactual_context(&self) -> bool
Source§fn parse_counterfactual_antecedent(
&mut self,
) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_counterfactual_antecedent( &mut self, ) -> Result<&'a LogicExpr<'a>, ParseError>
Source§fn parse_counterfactual_consequent(
&mut self,
) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_counterfactual_consequent( &mut self, ) -> Result<&'a LogicExpr<'a>, ParseError>
Source§fn extract_verb_from_expr(&self, expr: &LogicExpr<'a>) -> Option<Symbol>
fn extract_verb_from_expr(&self, expr: &LogicExpr<'a>) -> Option<Symbol>
Source§fn is_complete_clause(&self, expr: &LogicExpr<'a>) -> bool
fn is_complete_clause(&self, expr: &LogicExpr<'a>) -> bool
Source§fn parse_relative_clause(
&mut self,
gap_var: Symbol,
) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_relative_clause( &mut self, gap_var: Symbol, ) -> Result<&'a LogicExpr<'a>, ParseError>
Source§fn check_ellipsis_auxiliary(&self) -> bool
fn check_ellipsis_auxiliary(&self) -> bool
Source§fn check_ellipsis_terminator(&self) -> bool
fn check_ellipsis_terminator(&self) -> bool
Source§fn try_parse_ellipsis(
&mut self,
) -> Option<Result<&'a LogicExpr<'a>, ParseError>>
fn try_parse_ellipsis( &mut self, ) -> Option<Result<&'a LogicExpr<'a>, ParseError>>
Source§impl<'a, 'ctx, 'int> LogicVerbParsing<'a, 'ctx, 'int> for Parser<'a, 'ctx, 'int>
impl<'a, 'ctx, 'int> LogicVerbParsing<'a, 'ctx, 'int> for Parser<'a, 'ctx, 'int>
Source§fn build_group_predicate(
&mut self,
subjects: &[Symbol],
verb: Symbol,
verb_time: Time,
) -> &'a LogicExpr<'a>
fn build_group_predicate( &mut self, subjects: &[Symbol], verb: Symbol, verb_time: Time, ) -> &'a LogicExpr<'a>
Build a group predicate for intransitive verbs
Source§fn build_group_transitive(
&mut self,
subjects: &[Symbol],
objects: &[Symbol],
verb: Symbol,
verb_time: Time,
) -> &'a LogicExpr<'a>
fn build_group_transitive( &mut self, subjects: &[Symbol], objects: &[Symbol], verb: Symbol, verb_time: Time, ) -> &'a LogicExpr<'a>
Build a transitive predicate with group subject and group object
Source§fn parse_predicate_with_subject(
&mut self,
subject_symbol: Symbol,
) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_predicate_with_subject( &mut self, subject_symbol: Symbol, ) -> Result<&'a LogicExpr<'a>, ParseError>
Source§fn parse_predicate_with_subject_as_var(
&mut self,
subject_symbol: Symbol,
) -> Result<&'a LogicExpr<'a>, ParseError>
fn parse_predicate_with_subject_as_var( &mut self, subject_symbol: Symbol, ) -> Result<&'a LogicExpr<'a>, ParseError>
Source§fn try_parse_plural_subject(
&mut self,
first_subject: &NounPhrase<'a>,
) -> Result<Option<&'a LogicExpr<'a>>, ParseError>
fn try_parse_plural_subject( &mut self, first_subject: &NounPhrase<'a>, ) -> Result<Option<&'a LogicExpr<'a>>, ParseError>
Ok(Some(expr)) on success, Ok(None) if not plural, Err on semantic error.