Skip to main content

Module n3_parser

Module n3_parser 

Source
Expand description

Native, zero-copy N3 (Notation3) parser.

Two complementary front-ends over the same tokenizer:

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).
N3ParserError
Rule
Heap-backed rule (cold-path convenience).
StackFormula
Zero-allocation formula: borrowed triples in a fixed stack array.
StackRule
Zero-allocation rule.
Triple

Enums§

N3Event
Streamed event from the heap front-end (N3Parser::parse_all).
RuleType
StackEvent
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 by N3Parser::parse_all before 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’s CompiledFormula capacity).

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 Term to its 64-bit quin hash (variables return None).