ocaml: phase 1 match/with + pattern parser (+9 tests, 113 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s
Patterns: wildcard, literal, var, ctor (nullary + arg, flattens tuple args so Pair(a,b) -> (:pcon "Pair" PA PB)), tuple, list literal, cons :: (right-assoc), unit. Match: leading | optional, (:match SCRUT CLAUSES) with each clause (:case PAT BODY). Body parsed via parse-expr because | is below level-1 binop precedence.
This commit is contained in:
@@ -133,8 +133,11 @@ SX CEK evaluator (both JS and OCaml hosts)
|
||||
via `ocaml-parse-program`. _(Pending: `type`/`module`/`exception`/`open`/
|
||||
`include` decls, `match`/`with`, `try`/`with`, `function`, record literals/
|
||||
updates, field access, sequences `;`, `and` mutually-recursive bindings.)_
|
||||
- [ ] **Patterns:** constructor, literal, variable, wildcard `_`, tuple, list cons `::`,
|
||||
list literal, record, `as`, or-pattern `P1 | P2`, `when` guard.
|
||||
- [~] **Patterns:** constructor (nullary + with args, incl. flattened tuple
|
||||
args `Pair (a, b)` → `(:pcon "Pair" PA PB)`), literal (int/string/char/
|
||||
bool/unit), variable, wildcard `_`, tuple, list cons `::`, list literal.
|
||||
_(Pending: record patterns, `as` binding, or-pattern `P1 | P2`, `when`
|
||||
guard.)_
|
||||
- [ ] OCaml is **not** indentation-sensitive — no layout algorithm needed.
|
||||
- [ ] Tests in `lib/ocaml/tests/parse.sx` — 50+ round-trip parse tests.
|
||||
|
||||
@@ -311,6 +314,14 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-07 Phase 1 — `match`/`with` + pattern parser. Patterns: wildcard,
|
||||
literal, var, ctor (nullary + with arg, with tuple-arg flattening so
|
||||
`Pair (a, b)` → `(:pcon "Pair" PA PB)`), tuple, list literal, cons `::`
|
||||
(right-assoc), parens, unit. Match clauses: leading `|` optional, body
|
||||
parsed via `parse-expr`. AST: `(:match SCRUT CLAUSES)` where each clause
|
||||
is `(:case PAT BODY)`. 113/113 tests passing (+9). Note: parse-expr is
|
||||
used for case bodies, so a trailing `| pat -> body` after a complex body
|
||||
will be reached because `|` is not in the binop table for level 1.
|
||||
- 2026-05-07 Phase 1 — top-level program parser `ocaml-parse-program`. Parses
|
||||
a sequence of `let [rec] name params* = expr` decls and bare expressions
|
||||
separated by `;;`. Output `(:program DECLS)` with each decl one of `(:def …)`,
|
||||
|
||||
Reference in New Issue
Block a user