Skip to main content

panproto_parse/
lib.rs

1//! # panproto-parse
2//!
3//! Tree-sitter full-AST parsers and emitters for panproto language protocols.
4//!
5//! This crate provides the schema-level presentation functors that map between
6//! source code text and panproto [`Schema`] models. It operates at the schema
7//! level of panproto's two-parameter architecture (complementing `panproto-io`
8//! which operates at the instance level).
9//!
10//! ## Theory extraction
11//!
12//! Tree-sitter grammars are theory presentations. Each grammar's `node-types.json`
13//! is structurally isomorphic to a GAT: named node types become sorts, fields
14//! become operations. The [`theory_extract`] module auto-derives panproto theories
15//! from grammar metadata, ensuring the theory is always in sync with the parser.
16//!
17//! ## Generic walker
18//!
19//! Because theories are auto-derived from the grammar, the AST walker is fully
20//! generic: one [`walker::AstWalker`] implementation works for all languages.
21//! The node's `kind()` IS the panproto vertex kind; the field name IS the edge
22//! kind. Per-language customization is limited to formatting constraints and
23//! import resolution hints.
24//!
25//! ## Pipeline
26//!
27//! ```text
28//! source code ──parse──→ Schema ──merge/diff/check──→ Schema ──emit──→ source code
29//! ```
30//!
31//! [`Schema`]: panproto_schema::Schema
32
33/// Error types for full-AST parsing and emission.
34pub mod error;
35
36/// Scope-aware vertex ID generation for full-AST schemas.
37pub mod id_scheme;
38
39/// Automated theory extraction from tree-sitter grammar metadata.
40pub mod theory_extract;
41
42/// Grammar-driven named-scope detection via tree-sitter `tags.scm` queries.
43pub mod scope_detector;
44
45/// Generic tree-sitter AST walker.
46pub mod walker;
47
48/// Per-language parser and emitter implementations.
49pub mod languages;
50
51/// Parser registry mapping protocol names to implementations.
52pub mod registry;
53
54/// De-novo source emission from by-construction schemas.
55pub mod emit_pretty;
56
57/// The parse / emit pair as a verified asymmetric lens with explicit
58/// law-checkers (retraction in the image of the parser).
59pub mod parse_emit_lens;
60
61/// Put-direction of the parse / decorate / emit lens: build a
62/// decorated schema from an abstract one by routing through
63/// `emit_pretty + parse`.
64pub mod decorate;
65
66/// Runtime `LayoutPolicy` for the put-direction of the parse / emit
67/// lens; carries whitespace and indentation conventions.
68pub mod layout_policy;
69
70/// The parse / decorate / emit lens packaged as a first-class
71/// `panproto-lens::Protolens`.
72///
73/// The protolens describes the schema-level relationship between
74/// abstract and decorated schemas.
75pub mod parse_emit_protolens;
76
77pub use decorate::decorate_with_parser;
78pub use error::ParseError;
79pub use id_scheme::IdGenerator;
80pub use layout_policy::LayoutPolicy;
81pub use parse_emit_lens::{
82    LawViolation as ParseEmitLawViolation, ParseEmitLens, check_emit_parse, check_parse_emit,
83    edge_multiset, kind_multiset, strip_complement,
84};
85pub use parse_emit_protolens::parse_emit_protolens;
86pub use registry::{AstParser, ParserRegistry};
87pub use scope_detector::{NamedScope, ScopeDetector, ScopeKind};
88pub use theory_extract::{ExtractedTheoryMeta, extract_theory_from_node_types};
89pub use walker::{AstWalker, WalkerConfig};