Skip to main content

normalize_surface_syntax/
lib.rs

1//! Surface-level syntax translation between languages.
2//!
3//! `moss-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::{BinaryOp, Expr, Function, Literal, Program, Stmt, StructureEq, UnaryOp};
57
58// Re-exports: Traits
59pub use traits::{ReadError, Reader, Writer};
60
61// Re-exports: Registry
62pub use registry::{
63    reader_for_extension, reader_for_language, readers, register_reader, register_writer,
64    writer_for_language, writers,
65};
66
67// Re-exports: Built-in readers
68#[cfg(feature = "read-typescript")]
69pub use input::read_typescript;
70#[cfg(feature = "read-typescript")]
71pub use input::typescript::TypeScriptReader;
72
73// Re-exports: Built-in writers
74#[cfg(feature = "write-lua")]
75pub use output::LuaWriter;
76#[cfg(feature = "write-lua")]
77pub use output::lua::LuaWriterImpl;
78
79#[cfg(feature = "sexpr")]
80pub use sexpr::{SExpr, SExprError, from_sexpr, to_sexpr};