normalize_surface_syntax/lib.rs
1//! Surface-level syntax translation between languages.
2//!
3//! `normalize-surface-syntax` provides a common IR for imperative code and
4//! translates between language syntaxes (TypeScript, Lua, etc.) at the
5//! surface level - it maps syntax, not deep semantics.
6//!
7//! # Architecture
8//!
9//! ```text
10//! Source Languages IR Target Languages
11//! ──────────────── ───────────── ────────────────────
12//! TypeScript ─┐ ┌─> TypeScript
13//! Lua ─┼─> Program ─────┼─> Lua
14//! (future) ─┘ (ir.rs) └─> (future)
15//! ```
16//!
17//! # Example
18//!
19//! ```ignore
20//! use normalize_surface_syntax::{input, output};
21//!
22//! // Read TypeScript
23//! let ir = input::read_typescript("const x = 1 + 2;")?;
24//!
25//! // Write to Lua
26//! let lua = output::LuaWriter::emit(&ir);
27//! // => "local x = (1 + 2)"
28//! ```
29//!
30//! # S-Expression Format
31//!
32//! The IR can be serialized to a compact S-expression format (JSON arrays):
33//! - `["std.let", "x", 1]` → variable binding
34//! - `["math.add", left, right]` → binary operation
35//! - `["console.log", "hello"]` → function call
36//!
37//! This format is used for storage (e.g., lotus verbs).
38//!
39//! # Note on Translation Fidelity
40//!
41//! This is **surface-level** translation, not semantic transpilation like
42//! Haxe or ReScript. The IR captures syntax structure; domain semantics
43//! are handled by the runtime (e.g., spore).
44
45pub mod ir;
46pub mod registry;
47pub mod traits;
48
49#[cfg(feature = "sexpr")]
50pub mod sexpr;
51
52pub mod input;
53pub mod output;
54
55// Re-exports: IR types
56pub use ir::{
57 BinaryOp, ExportName, Expr, Function, ImportName, Literal, Method, Param, Pat, PatField,
58 Program, Span, Stmt, StructureEq, TemplatePart, UnaryOp,
59};
60
61// Re-exports: Traits
62pub use traits::{ReadError, Reader, Writer};
63
64// Re-exports: Registry
65pub use registry::{
66 reader_for_extension, reader_for_language, readers, register_reader, register_writer,
67 writer_for_language, writers,
68};
69
70// Re-exports: Built-in readers
71#[cfg(feature = "read-typescript")]
72pub use input::read_typescript;
73#[cfg(feature = "read-typescript")]
74pub use input::typescript::TypeScriptReader;
75
76// Re-exports: Built-in writers
77#[cfg(feature = "write-lua")]
78pub use output::LuaWriter;
79#[cfg(feature = "write-lua")]
80pub use output::lua::LuaWriterImpl;
81
82#[cfg(feature = "sexpr")]
83pub use sexpr::{SExprError, from_sexpr, to_sexpr};