axon_frontend/lib.rs
1//! AXON compiler frontend.
2//!
3//! Pure frontend of the AXON language: lexer, parser, AST, epistemic
4//! type primitives, type checker, IR generator, and the top-level
5//! compile-time checker that glues them together.
6//!
7//! # Design contract
8//!
9//! This crate has **zero runtime dependencies**. The only allowed
10//! external dep is `serde` (plus its proc-macro chain). Any addition
11//! of a runtime dep (tokio, axum, sqlx, reqwest, aws-*, jsonwebtoken,
12//! …) is rejected at CI time.
13//!
14//! # Consumers
15//!
16//! - `axon` crate (the AXON runtime in `../axon-rs/`) re-exports these
17//! modules so existing callers keep working.
18//! - `axon-lsp` (Language Server, separate repo) consumes the frontend
19//! directly without dragging runtime deps.
20//!
21//! # Byte-identical parity
22//!
23//! Outputs must match the Python reference implementation
24//! (`../axon/`) on the golden-file test corpus. Divergences are
25//! release blockers.
26
27pub mod ast;
28pub mod checker;
29pub mod cron;
30pub mod epistemic;
31pub mod ir_generator;
32pub mod ir_nodes;
33pub mod lexer;
34pub mod parser;
35pub mod smart_suggest;
36pub mod store_column_proof;
37pub mod store_introspect;
38/// §Fase 109.a — the symbolic differentiator + simplifier over the
39/// closed `Expr` (the proof-carrying derivative).
40pub mod expr_diff;
41pub mod store_schema;
42pub mod store_schema_manifest;
43pub mod tokens;
44pub mod type_checker;
45
46// §Fase 11.a — compile-time catalogs used by the type checker.
47// `refinement` declares the closed Trust<T> catalog; `stream_effect`
48// declares the closed backpressure policy catalog. Both are pure
49// enum-like definitions with `std::fmt` only — no runtime deps.
50// The matching runtime implementations (`trust_verifiers`,
51// `stream_runtime`) live in the `axon` runtime crate.
52pub mod refinement;
53pub mod stream_effect;
54
55// §Fase 11.c — closed catalogue of regulatory authorisations
56// (GDPR/CCPA/SOX/HIPAA/GLBA/PCI-DSS) used by the type checker to
57// enforce `@legal_basis` annotations. Pure catalog, no runtime deps.
58pub mod legal_basis;
59
60// §Fase 11.e — OTS (Ontological Tool Synthesis) compile-time slug
61// catalogs. Runtime pipeline execution lives in `axon::ots` and
62// re-exports these for backward compatibility.
63pub mod ots_catalog;
64
65// §Fase 13.g — LSP-facing analysis primitives for typed channels.
66// Pure AST helpers consumed by `axon-lsp` (sibling repo) to implement
67// hover, completion, go-to-definition and find-references. Zero
68// runtime deps — stays inside the Fase 12.c contract.
69pub mod channel_analysis;
70
71// §Fase 41.a — session types: the pure algebra of typed bidirectional
72// dialogue (WebSocket as a cognitive primitive). The session-type
73// grammar + the duality involution `(·)⊥` + regular-coinductive
74// equality for `μ`-types + the connection law (`peer ≡ self⊥`).
75// Grounded in Caires–Pfenning (session types = intuitionistic linear
76// propositions). Pure — no runtime deps; the `socket` surface (41.b),
77// credit-refined backpressure (41.c) and the typed-WS runtime (41.d,
78// in the `axon` crate) build on this. See
79// docs/paper_websocket_cognitive_primitive.md.
80pub mod session;
81// §Fase 41.h — multiparty session types (Honda–Yoshida–Carbone). A
82// `GlobalType` declares an n-party protocol; projection `G⌐r` extracts
83// each role's binary `SessionType` (the §41.a algebra). The safe-
84// realizability gate is `project_all`: a `Result::Ok` is the structural
85// certificate that independent per-role runtimes faithfully realise `G`.
86pub mod multiparty;
87
88// §Fase 6.a — the closed registry of every primitive AXON exposes as
89// a named language construct. Single source of truth for the ℰMCP
90// coverage gate + scaffold CLI + future LSP completions / docs-site
91// generators. Pure const data, no runtime deps. See the module-level
92// docs for the discipline (registry + corpus = atomic addition).
93pub mod primitive_registry;
94pub use primitive_registry::{
95 by_category, coverage_summary, find as find_primitive, with_status, CoverageSummary,
96 DocStatus, PrimitiveInfo, PRIMITIVE_REGISTRY,
97};
98
99// §Fase 80.f — the blessed upstream preset catalog (versioned, forkable,
100// ordinary `.axon` source per D80.5) + the `from Preset@vN` expansion the
101// parser runs before type-check. Pure const data + a pure AST pass.
102pub mod upstream_presets;
103
104// §Fase 80.g — `voice` macro-expansion to source text (the `axon desugar`
105// payload). Pure AST pass run by the parser before preset expansion.
106pub mod voice_desugar;
107
108// §Fase 84 — Remote Hands: the pure, shared argv-template classifier + risk
109// catalog used by BOTH the type-checker and the runtime dispatcher (D84.1).
110pub mod technician;
111
112/// §Fase 92.a — convert a duration literal (the lexer's `Duration` token
113/// shape: digits + one of `s`/`ms`/`m`/`h`/`d`) into whole seconds. Pure,
114/// total over the token grammar; `None` for anything else (a malformed
115/// literal is `axon-T894` at the type-check layer). `ms` floors to whole
116/// seconds — a sub-second credential TTL is `0` and rejected by the same
117/// law. Shared by the IR lowering and the type checker so the two can
118/// never disagree about what a `ttl:` means.
119pub fn duration_literal_to_secs(literal: &str) -> Option<u64> {
120 let t = literal.trim();
121 let split = t.find(|c: char| !c.is_ascii_digit())?;
122 let (digits, suffix) = t.split_at(split);
123 let n: u64 = digits.parse().ok()?;
124 match suffix {
125 "s" => Some(n),
126 "ms" => Some(n / 1000),
127 "m" => n.checked_mul(60),
128 "h" => n.checked_mul(3600),
129 "d" => n.checked_mul(86_400),
130 _ => None,
131 }
132}