js_parse/lib.rs
1//! `quickjs-parse` — ECMAScript 2025 lexer, AST and parser.
2//!
3//! Milestone status: **the lexer is complete (M1a)**; the AST and parser are the
4//! next step and do not exist yet.
5//!
6//! ```no_run
7//! use js_parse::{Lexer, TokenKind};
8//!
9//! let mut lexer = Lexer::new("let answer = 0x2a + 1_000;");
10//! let mut kinds = Vec::new();
11//! loop {
12//! let token = lexer.next_token().expect("valid source");
13//! let done = matches!(token.kind, TokenKind::Eof);
14//! kinds.push(token.kind);
15//! if done {
16//! break;
17//! }
18//! }
19//! assert_eq!(kinds.len(), 8);
20//! ```
21//!
22//! # Known limitation
23//!
24//! String values are Rust `String`s, so a lone surrogate (`"\ud800"`) cannot be
25//! represented yet: it is decoded to U+FFFD. QuickJS keeps UTF-16 code units
26//! and reports `"\ud800".length === 1`, so the string representation must gain
27//! WTF-8 (or UTF-16) support in the `js-value` milestone. This is tracked as a
28//! `TODO(js-value)` and only affects lone surrogates, never well-formed text.
29
30#![deny(unsafe_op_in_unsafe_fn)]
31#![warn(missing_docs)]
32
33pub mod ast;
34mod error;
35mod lexer;
36pub mod parser;
37mod token;
38mod unicode_id;
39
40pub use error::{LexError, ParseError, Result, SyntaxError};
41pub use lexer::Lexer;
42pub use parser::{
43 EvalContext, Parser, parse_eval_script, parse_eval_script_in, parse_expression, parse_module,
44 parse_script, parse_script_strict,
45};
46
47/// Parser configuration constants and helpers.
48pub mod parser_limits {
49 pub use crate::parser::DEFAULT_MAX_DEPTH;
50}
51pub use token::{
52 BigIntLiteral, Keyword, NumberLiteral, Position, Punct, Span, TemplateKind, TemplateToken,
53 Token, TokenKind,
54};