✓
Passing This code compiles and runs correctly.
Code
// MIRROR for `std/json:parse` — the schema-directed parser transform
// invoked from `app/lib`, not the entry file. Entry drives it with a
// well-formed document, a malformed one, and recognizer-mode input.
import app/lib
app/lib:greet(body: "{\"name\":\"ada\",\"age\":36,\"tags\":[\"a\",\"b\"],\"junk\":{}}")
app/lib:greet(body: "{\"name\":\"zed\"}")
app/lib:scan(body: "[1,{\"a\":true},null]")
Supporting Files
// lib.k — `std/json:parse` declared and used from an imported module. The
// transform compiles a bespoke recursive-descent parser per call site; this
// is the position that tells a correct emitted unit qualifier from a lucky
// one — the entry file collapses file-name and module-name into one word,
// so 642_001 cannot see a qualifier that lands wrong.
import std/io
import std/json
pub tor greet { body: string }
greet = std/json:parse(input: body)
| malformed { message, offset } |> std/io:print.ln("mod BAD {{ offset:d }}: {{ message:s }}")
| ok { name: string, age: i64, tags: []string } |> std/io:print.ln("mod {{ name:s }}|{{ age:d }}|{{ tags.len:d }}")
pub tor scan { body: string }
scan = std/json:parse(input: body)
| malformed { message, offset } |> std/io:print.ln("mod invalid {{ offset:d }}: {{ message:s }}")
| ok s |> std/io:print.ln("mod valid {{ s:s }}")
Actual
mod ada|36|2
mod BAD 14: missing field 'age'
mod valid [1,{"a":true},null]
Expected output
mod ada|36|2
mod BAD 14: missing field 'age'
mod valid [1,{"a":true},null]
Flows
flow ~greet click a branch to expand · @labels scroll to their anchor
greet (body: "{\"name\":\"ada\",\"age\":36,\"tags\":[\"a\",\"b\"],\"junk\":{}}")
flow ~greet click a branch to expand · @labels scroll to their anchor
greet (body: "{\"name\":\"zed\"}")
flow ~scan click a branch to expand · @labels scroll to their anchor
scan (body: "[1,{\"a\":true},null]")
Test Configuration
MUST_RUN