Expand description
Native, zero-copy N3 (Notation3) parser.
Two complementary front-ends over the same tokenizer:
- Borrowing AST (
Formula/Rule,Vec-backed) — the convenient cold-path form consumed bycrate::modalities::logic::n3_compiler, which immediately lowers it to a zero-heapCompiledRule. - Zero-allocation AST (
StackFormula/StackRule, fixed arrays) +N3Parser::parse_all_zero_heap— parses N3 with no heap allocation at all (proven by adhattest), for edge hardware and the hot path.
Supported N3 surface: triples with ; (predicate lists) and , (object
lists); the a (rdf:type) keyword, kept as the engine’s bare a token;
implication rules
(=> strict, ~> defeasible, ^> defeater, -o linear) with optional
[id] and (weight) annotations; { … } formula quoting / reification
(a quoted graph used as a term, identified by the canonical hash of its
text); #asp { … } and qualia:diffuse { … } blocks; # comments.
Resource caps (anti-DoS): brace nesting is bounded by
MAX_PARSE_BRACE_DEPTH and statement count by MAX_PARSE_STATEMENTS;
a quoted/parsed formula yields at most MAX_STACK_TRIPLES triples. The
evaluation caps (forward-chaining fixpoint rounds, premise depth) live in
crate::webizen (fire_guard_rules).
Structs§
- Formula
- Heap-backed formula (cold-path convenience; the compiler lowers it to a
fixed-size
CompiledFormula). - N3Parser
- A highly capable, native N3 parser over a borrowed
&str(zero-copy terms). - N3Parser
Error - Rule
- Heap-backed rule (cold-path convenience).
- Stack
Formula - Zero-allocation formula: borrowed triples in a fixed stack array.
- Stack
Rule - Zero-allocation rule.
- Triple
Enums§
- N3Event
- Streamed event from the heap front-end (
N3Parser::parse_all). - Rule
Type - Stack
Event - Streamed event from the zero-allocation front-end
(
N3Parser::parse_all_zero_heap).Copy, no heap. - Term
Constants§
- MAX_
PARSE_ BRACE_ DEPTH - Max
{nesting depth accepted byN3Parser::parse_allbefore failing closed — prevents pathological-input parser state explosion. - MAX_
PARSE_ STATEMENTS - Max top-level statements accepted in a single parse — anti-DoS bound.
- MAX_
STACK_ TRIPLES - Max triples in a zero-allocation
StackFormula(matches the compiler’sCompiledFormulacapacity).
Functions§
- q_
hash_ formula - Canonical 64-bit FNV-1a hash of a quoted-formula’s text, with runs of
Unicode whitespace collapsed to a single space (and leading/trailing
whitespace dropped). This gives a stable identity for a quoted statement
so that
{ :a :b :c }and{ :a :b :c }denote the same node — the handle other nquins use to reason about that statement (reification). Zero-allocation. - term_
uri_ hash - Map a parsed N3
Termto its 64-bit quin hash (variables returnNone).