Expand description
quickjs-parse — ECMAScript 2025 lexer, AST and parser.
Milestone status: the lexer is complete (M1a); the AST and parser are the next step and do not exist yet.
use js_parse::{Lexer, TokenKind};
let mut lexer = Lexer::new("let answer = 0x2a + 1_000;");
let mut kinds = Vec::new();
loop {
let token = lexer.next_token().expect("valid source");
let done = matches!(token.kind, TokenKind::Eof);
kinds.push(token.kind);
if done {
break;
}
}
assert_eq!(kinds.len(), 8);§Known limitation
String values are Rust Strings, so a lone surrogate ("\ud800") cannot be
represented yet: it is decoded to U+FFFD. QuickJS keeps UTF-16 code units
and reports "\ud800".length === 1, so the string representation must gain
WTF-8 (or UTF-16) support in the js-value milestone. This is tracked as a
TODO(js-value) and only affects lone surrogates, never well-formed text.
Re-exports§
pub use parser::EvalContext;pub use parser::Parser;pub use parser::parse_eval_script;pub use parser::parse_eval_script_in;pub use parser::parse_expression;pub use parser::parse_module;pub use parser::parse_script;pub use parser::parse_script_strict;
Modules§
- ast
- The ECMAScript 2025 abstract syntax tree.
- parser
- The parser: tokens to
crate::ast. - parser_
limits - Parser configuration constants and helpers.
Structs§
- BigInt
Literal - A BigInt literal: the source digits and their radix, kept raw so that
js-valuecan build the arbitrary-precision integer. - Lexer
- A streaming lexer over one source text.
- Position
- Byte offset, line (1-based) and column (1-based) of a source position.
- Span
- Half-open source range.
- Syntax
Error - A syntax error produced while scanning or parsing.
- Template
Token - A template literal chunk.
- Token
- A token plus where it came from.
Enums§
- Keyword
- A reserved word that is a keyword in every context (ES2025 §12.7.2), plus
enum(always reserved). - Number
Literal - The value of a numeric literal.
- Punct
- Every punctuator in ECMAScript 2025, longest-first where it matters.
- Template
Kind - Which part of a template literal a token is.
- Token
Kind - A lexical token.
Type Aliases§
- LexError
- Lexical errors share the syntax error type: the engine reports both as
SyntaxError. - Parse
Error - Parser errors share the syntax error type.
- Result
- Result type used by the lexer and the parser.