Skip to main content

Module parser

Module parser 

Source
Expand description

Recursive descent parser for natural language to first-order logic.

This module implements a hand-written recursive descent parser that transforms natural language sentences into logical expressions. The parser operates in two modes: Declarative for natural language propositions (Logicaffeine mode) and Imperative for strict, deterministic scoping (LOGOS mode).

§Architecture

The parser is split into specialized submodules:

ModuleResponsibility
clauseSentence-level parsing: conditionals, conjunctions, relative clauses
nounNoun phrase parsing with determiners, adjectives, possessives
verbVerb phrase parsing, event semantics, thematic roles
modalModal verbs (can, must, might) with Kripke semantics
quantifierQuantifier scope: every, some, no, most
questionWh-movement and question formation
pragmaticsPragmatic inference during parsing
commonShared utilities (copula lists, etc.)

§Key Types

  • Parser: The main parser struct holding tokens, state, and arenas
  • ParserMode: Declarative (NL) vs Imperative (LOGOS) mode
  • ParserGuard: RAII guard for speculative parsing with automatic rollback
  • NegativeScopeMode: Wide vs narrow scope for lexically negative verbs
  • ModalPreference: Default, epistemic, or deontic readings for modals

§Example

use logicaffeine_language::parser::{Parser, ParserMode, ClauseParsing};

// Lexer produces tokens, then parser produces LogicExpr
let expr = parser.parse_sentence()?;

Modules§

lgx_lower
Lowering a component’s View: into the DOM calls every tier already runs.

Structs§

EventTemplate
Template for constructing Neo-Davidsonian events.
NestedStmtSpans
Where each statement read inside a block sits in the source — a function’s body, a loop’s, a branch’s — by StmtId. Top-level statements are in Parser::stmt_spans instead: they live in the returned Vec, whose buffer may be freed and reused, while a block lives in the arena for as long as the AST does. A statement the parser wrote itself (a desugaring’s) has no entry, so a finding in it falls back to the statement the author wrote around it.
Parser
ParserGuard
RAII guard for speculative parsing with automatic rollback.

Enums§

ModalPreference
Controls interpretation of polysemous modals (may, can, could). Used by compile_forest to generate multiple semantic readings.
NegativeScopeMode
Controls scope of negation for lexically negative verbs (lacks, miss). “user who lacks a key” can mean:
ParserMode
Determines how the parser interprets sentences.
ResolvedPronoun
a deictic constant (referring to an entity outside the discourse).

Traits§

ClauseParsing
Trait for parsing clause-level structures.
ImperativeVerbParsing
Trait for parsing verb phrases in imperative (LOGOS) mode.
LogicVerbParsing
Trait for parsing verb phrases in declarative (logic) mode.
ModalParsing
Trait for parsing modal verbs and aspect chains.
NounParsing
Trait for parsing noun phrases.
PragmaticsParsing
Trait for parsing pragmatic and focus-sensitive constructions.
QuantifierParsing
Trait for parsing quantified expressions and managing scope.
QuestionParsing
Trait for parsing interrogative sentences.