haskell: Phase 14 — record syntax in parser (con-rec AST node)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m1s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m1s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1212,16 +1212,47 @@
|
|||||||
(not (hk-match? "conid" nil))
|
(not (hk-match? "conid" nil))
|
||||||
(hk-err "expected constructor name"))
|
(hk-err "expected constructor name"))
|
||||||
(let
|
(let
|
||||||
((name (get (hk-advance!) "value")) (fields (list)))
|
((name (get (hk-advance!) "value")))
|
||||||
(define
|
(cond
|
||||||
hk-cd-loop
|
((hk-match? "lbrace" nil)
|
||||||
(fn
|
(begin
|
||||||
()
|
(hk-advance!)
|
||||||
(when
|
(let
|
||||||
(hk-atype-start? (hk-peek))
|
((rec-fields (list)))
|
||||||
(do (append! fields (hk-parse-atype)) (hk-cd-loop)))))
|
(define
|
||||||
(hk-cd-loop)
|
hk-rec-loop
|
||||||
(list :con-def name fields))))
|
(fn
|
||||||
|
()
|
||||||
|
(when
|
||||||
|
(hk-match? "varid" nil)
|
||||||
|
(let
|
||||||
|
((fname (get (hk-advance!) "value")))
|
||||||
|
(begin
|
||||||
|
(hk-expect! "reservedop" "::")
|
||||||
|
(let
|
||||||
|
((ftype (hk-parse-type)))
|
||||||
|
(begin
|
||||||
|
(append! rec-fields (list fname ftype))
|
||||||
|
(when
|
||||||
|
(hk-match? "comma" nil)
|
||||||
|
(begin (hk-advance!) (hk-rec-loop))))))))))
|
||||||
|
(hk-rec-loop)
|
||||||
|
(hk-expect! "rbrace" nil)
|
||||||
|
(list :con-rec name rec-fields))))
|
||||||
|
(:else
|
||||||
|
(let
|
||||||
|
((fields (list)))
|
||||||
|
(define
|
||||||
|
hk-cd-loop
|
||||||
|
(fn
|
||||||
|
()
|
||||||
|
(when
|
||||||
|
(hk-atype-start? (hk-peek))
|
||||||
|
(begin
|
||||||
|
(append! fields (hk-parse-atype))
|
||||||
|
(hk-cd-loop)))))
|
||||||
|
(hk-cd-loop)
|
||||||
|
(list :con-def name fields)))))))
|
||||||
(define
|
(define
|
||||||
hk-parse-tvars
|
hk-parse-tvars
|
||||||
(fn
|
(fn
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
|
|||||||
|
|
||||||
### Phase 14 — Record syntax
|
### Phase 14 — Record syntax
|
||||||
|
|
||||||
- [ ] Parser: extend `hk-parse-data` to recognise `{ field :: Type, … }`
|
- [x] Parser: extend `hk-parse-data` to recognise `{ field :: Type, … }`
|
||||||
constructor bodies. AST node: `(:con-rec CNAME [(FNAME TYPE) …])`.
|
constructor bodies. AST node: `(:con-rec CNAME [(FNAME TYPE) …])`.
|
||||||
- [ ] Desugar: `:con-rec` → positional `:con-def` plus generated accessor
|
- [ ] Desugar: `:con-rec` → positional `:con-def` plus generated accessor
|
||||||
functions `(\rec -> case rec of …)` for each field name.
|
functions `(\rec -> case rec of …)` for each field name.
|
||||||
@@ -313,6 +313,13 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
|
|||||||
|
|
||||||
_Newest first._
|
_Newest first._
|
||||||
|
|
||||||
|
**2026-05-07** — Phase 14 record parser: `data Foo = Foo { name :: T, … }`:
|
||||||
|
- Extended `hk-parse-con-def` to peek for `{` after the constructor name; if
|
||||||
|
found, parse `varid :: type` pairs separated by commas, terminate with `}`,
|
||||||
|
return `(:con-rec name [(fname ftype) …])`. Positional constructors fall
|
||||||
|
through to the existing `:con-def` path. Verified record parses; no
|
||||||
|
regressions in parse.sx (43/43), parser-decls (24/24), deriving (15/15).
|
||||||
|
|
||||||
**2026-05-07** — Phase 13 conformance: shapes.hs (5/5) → Phase 13 complete:
|
**2026-05-07** — Phase 13 conformance: shapes.hs (5/5) → Phase 13 complete:
|
||||||
- `class Shape` with a default `perimeter` (using a where-clause inside the
|
- `class Shape` with a default `perimeter` (using a where-clause inside the
|
||||||
default body), two instances `Square` / `Rect` — Square overrides
|
default body), two instances `Square` / `Rect` — Square overrides
|
||||||
|
|||||||
Reference in New Issue
Block a user