ecma_syntax_cat/lib.rs
1//! # ecma-syntax-cat
2//!
3//! ECMAScript abstract syntax tree as comp-cat-rs-idiomatic Rust types.
4//! ESTree-shaped, ES2024-complete, no panics, no `Rc`/`Arc`/`RefCell`, no
5//! interior mutability, no `unsafe`.
6//!
7//! This crate is the foundation layer of a multi-crate reformulation of a
8//! JavaScript engine targeting Tauri integration. It deliberately has no
9//! runtime dependencies so that every downstream layer (lexer, parser,
10//! interpreter, type checker, source-map generator) can adopt it without
11//! inheriting our framework choices.
12//!
13//! ## Shape
14//!
15//! Every AST node is a [`Spanned<T>`] value: a kind enum paired with a
16//! [`Span`] denoting the source range it was parsed from. Recursive
17//! positions are `Box<T>`; collections are `Vec<T>`. Variant fields are
18//! named on the variant rather than in per-variant structs except where
19//! the variant has enough non-trivial fields to warrant its own type
20//! (`Function`, `ArrowFunction`, `Class`, `VariableDeclaration`).
21//!
22//! ## Quick start
23//!
24//! ```
25//! # fn main() -> Result<(), ecma_syntax_cat::error::Error> {
26//! use ecma_syntax_cat::expression::{Expression, ExpressionKind};
27//! use ecma_syntax_cat::identifier::Identifier;
28//! use ecma_syntax_cat::literal::Literal;
29//! use ecma_syntax_cat::operator::BinaryOperator;
30//! use ecma_syntax_cat::span::Span;
31//!
32//! let span = Span::synthetic();
33//! let x = Expression::new(
34//! ExpressionKind::Identifier(Identifier::new("x")?),
35//! span,
36//! );
37//! let one = Expression::new(
38//! ExpressionKind::Literal(Literal::number(1.0)),
39//! span,
40//! );
41//! let sum = Expression::new(
42//! ExpressionKind::Binary {
43//! operator: BinaryOperator::Add,
44//! left: Box::new(x),
45//! right: Box::new(one),
46//! },
47//! span,
48//! );
49//! assert_eq!(format!("{sum}"), "(x + 1)");
50//! # Ok(())
51//! # }
52//! ```
53//!
54//! [`Spanned<T>`]: crate::span::Spanned
55//! [`Span`]: crate::span::Span
56
57pub mod class;
58pub mod declaration;
59pub mod error;
60pub mod expression;
61pub mod function;
62pub mod identifier;
63pub mod literal;
64pub mod module;
65pub mod operator;
66pub mod pattern;
67pub mod program;
68pub mod span;
69pub mod statement;