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:
| Module | Responsibility |
|---|---|
clause | Sentence-level parsing: conditionals, conjunctions, relative clauses |
noun | Noun phrase parsing with determiners, adjectives, possessives |
verb | Verb phrase parsing, event semantics, thematic roles |
modal | Modal verbs (can, must, might) with Kripke semantics |
quantifier | Quantifier scope: every, some, no, most |
question | Wh-movement and question formation |
pragmatics | Pragmatic inference during parsing |
common | Shared utilities (copula lists, etc.) |
§Key Types
Parser: The main parser struct holding tokens, state, and arenasParserMode: Declarative (NL) vs Imperative (LOGOS) modeParserGuard: RAII guard for speculative parsing with automatic rollbackNegativeScopeMode: Wide vs narrow scope for lexically negative verbsModalPreference: Default, epistemic, or deontic readings for modals
§Example
ⓘ
use logicaffeine_language::parser::{Parser, ParserMode};
// Lexer produces tokens, then parser produces LogicExpr
let expr = parser.parse_sentence()?;Structs§
- Event
Template - Template for constructing Neo-Davidsonian events.
- Parser
- Recursive descent parser for natural language to first-order logic.
- Parser
Guard - RAII guard for speculative parsing with automatic rollback.
Enums§
- Modal
Preference - Controls interpretation of polysemous modals (may, can, could). Used by compile_forest to generate multiple semantic readings.
- Negative
Scope Mode - Controls scope of negation for lexically negative verbs (lacks, miss). “user who lacks a key” can mean:
- Parser
Mode - Determines how the parser interprets sentences.
- Resolved
Pronoun - Result of pronoun resolution during parsing.
Traits§
- Clause
Parsing - Trait for parsing clause-level structures.
- Imperative
Verb Parsing - Trait for parsing verb phrases in imperative (LOGOS) mode.
- Logic
Verb Parsing - Trait for parsing verb phrases in declarative (logic) mode.
- Modal
Parsing - Trait for parsing modal verbs and aspect chains.
- Noun
Parsing - Trait for parsing noun phrases.
- Pragmatics
Parsing - Trait for parsing pragmatic and focus-sensitive constructions.
- Quantifier
Parsing - Trait for parsing quantified expressions and managing scope.
- Question
Parsing - Trait for parsing interrogative sentences.