✓
Passing This code compiles and runs correctly.
Code
// Pins the parse-error contract: the error carries the FURTHEST failure
// position as line/col (newline-counted at the splice), what was expected
// there (the terminal's pattern/literal text or the rule name), and what was
// found (one byte, or "end of input"). Input "[42" enters the array
// alternative, consumes `[` and the number, then dies wanting the `]`
// literal at 1:4 with nothing left — the deep-path error, not "no
// alternative at 0".
import std/parser
import std/io
std/parser:grammar(nums)
! value v |> std/parser:match(v)
| `-?[0-9]+` n -> n
| array a -> a
! array a |> std/parser:match(a)
| `\[` _ |> std/parser:sub(value): v |> std/parser:lit("]") -> v
std/parser:parse("[42", grammar: nums)
| value v |> std/io:print.ln("v={{ v:s }}")
| parse-error { line, col, expected, found } |> std/io:print.ln("err {{ line:d }}:{{ col:d }} expected {{ expected:s }} found {{ found:s }}")
Actual
err 1:4 expected ] found end of input
Must contain:
err 1:4 expected ] found end of inputFlows
flow ~grammar click a branch to expand · @labels scroll to their anchor
grammar (expr: nums)
flow ~parse click a branch to expand · @labels scroll to their anchor
parse (expr: "[42", grammar: nums)
Test Configuration
MUST_RUN