Skip to main content

analyze_lossless

Function analyze_lossless 

Source
pub fn analyze_lossless(input: &str) -> String
Expand description

Parse and validate Monkey source, returning a tagged JSON envelope the linter consumes. Unlike parse_lossless, this runs parser::validation (the semantic pass the interpreter and compiler share) so callers see undefined-variable, misplaced-this, and constructor-return errors — not just syntax errors. analyze is the linter’s single entry into the Rust side: TypeScript never re-implements parse or validation.

Failures are data in the envelope, not JavaScript exceptions: { status: "error", stage, message, span? }. Parser errors are plain strings without a span; validation errors carry a UTF-8 byte span. On success the AST is serialized losslessly (i64 literals as decimal strings), matching parse_lossless: { status: "ok", program }.

Standalone source is validated against the same predefined globals a fresh interpreter/compiler sees — the full builtin table (len, puts, first, last, rest, push, print).