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