Files
vectorcraft/crates/js/src/error.rs
T
dotCooCoo 05c1be3548 JavaScript: parser for ES5 scripts, with cargo xtask test262
New crate vectorcraft-js reads ECMAScript 5.1 source into a syntax tree
with source positions: a UTF-16 lexer (line and column tracking, automatic
semicolon insertion, the regexp and division goals), preprocessor lines
read as directive tokens, a recursive-descent parser to an arena tree, and
the ES5 early errors, strict mode included. Nesting deeper than
Options::max_depth (200 by default) gives a SyntaxError with its line and
column rather than overflowing the stack. Nothing runs scripts yet.

cargo xtask test262 downloads test262 at a pinned commit, checks its
SHA-256, unpacks it into the gitignored corpus/ folder and runs the ES5
syntax tests. A differential test in the engine compares the lexer with
scriptcheck on line counts, directives and unterminated literals.
2026-11-07 10:29:51 -08:00

30 lines
1.1 KiB
Rust

//! The error a script that cannot be read gives: a `SyntaxError` with its message and where in the
//! source it is.
use std::fmt;
/// A script that does not follow the grammar, or breaks one of its early-error rules. `line` and
/// `column` count from 1; the column counts UTF-16 code units from the start of the line, as
/// JavaScript source positions do. `offset` is the UTF-16 offset from the start of the source.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SyntaxError {
pub message: String,
pub line: u32,
pub column: u32,
pub offset: u32,
}
impl fmt::Display for SyntaxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SyntaxError: {} (line {}, column {})", self.message, self.line, self.column)
}
}
impl std::error::Error for SyntaxError {}
/// The message of the error nesting deeper than [`crate::Options::max_depth`] gives.
pub const TOO_DEEP: &str = "nesting too deep";
/// The message of the error a source longer than [`crate::Options::max_source_units`] gives.
pub const TOO_LONG: &str = "source too long";