normalize-surface-syntax 0.3.2

Surface-level syntax translation between languages via a common IR
Documentation
1
2
3
4
5
# normalize-surface-syntax/src/ir

Core IR types for surface-syntax translation.

`expr.rs` defines `Expr` (variable references, binary/unary operations, calls, member access, arrays, objects, anonymous functions, conditionals, assignments, and `TemplateLiteral`), `Literal`, `BinaryOp`, `UnaryOp`, and `TemplatePart` (`Text(String)` or `Expr(Box<Expr>)`). Structured variants (`Binary`, `Unary`, `Call`, `Member`, `Conditional`, `Assign`) carry an optional `span: Option<Span>` for source location tracking. `stmt.rs` defines `Stmt` (variable declarations with optional `type_annotation: Option<String>`, expression statements, if/while/for, return, function definitions, try/catch, `Comment { text, block }`, `Import { source, names }`, `Export { names, source }`, `Class { name, extends, methods }`, and `Destructure { pat, value, mutable }` for destructuring bindings); structured variants also carry `span: Option<Span>`. Supporting types: `ImportName { name, alias, is_namespace }`, `ExportName { name, alias }`, `Method { name, params, body, is_static, return_type }`. `Comment` stores raw content (without delimiters) and a flag indicating line vs block comment — builders `comment_line(text)` and `comment_block(text)`. `pat.rs` defines `Pat` (binding patterns: `Ident(String)`, `Object(Vec<PatField>)`, `Array(Vec<Option<Pat>>, Option<String>)`, `Rest(Box<Pat>)`) and `PatField { key, pat, default }` for named object pattern fields. `mod.rs` defines `Program` (top-level body), `Function` (with `params: Vec<Param>` and `return_type: Option<String>`), `Param` (`name: String`, `type_annotation: Option<String>`), and `Span { start_line, start_col, end_line, end_col }` (1-based lines, 0-based columns). `structure_eq.rs` provides `StructureEq` for comparing IR trees while ignoring surface hints like mutability, computed properties, type annotations, and spans — includes implementations for `Stmt`, `Expr`, `Pat`, `PatField`, `Function`, `Method`, and `TemplatePart`.