Commit bc4cbf9
authored
feat(parser): accept
Closes #40.
Stdlib has used `[T]` as the array/list type spelling all along —
`fn map<T, U>(arr: [T], f: T -> U) -> [U]`, `Result[[T], E]`, etc. —
but `lib/parser.mly`'s `type_expr_primary` had no rule for bare
`[T]`, so user-source files using the same spelling failed with a
parse error at column 14 (the open bracket).
Added one rule to `type_expr_primary`:
| LBRACKET ty = type_expr RBRACKET
{ TyApp (mk_ident "List" $startpos $endpos, [TyArg ty]) }
`[T]` desugars to `List[T]` — a type application. Same shape as the
existing `name = upper_ident LBRACKET ... RBRACKET` rule a few lines
above; just the no-name-prefix variant.
## What this unblocks
idaptik's STAPEL-VOLL-AUDIT estimates ~95% of its translatable surface
uses arrays in some form (cross-component lists, register snapshots,
puzzle hints, multi-element data). With this rule, those files can
compile.
## Test plan
Compile any of these (all should now parse cleanly):
fn first(xs: [Int]) -> Int { xs[0] }
struct Tags { names: [String] }
fn map<T, U>(arr: [T], f: T -> U) -> [U] { ... }
The rule placement (after the row-record and before the built-in type
constants) is unambiguous — `LBRACKET` in type position previously
only appeared after an upper_ident as a type-arg-list opener, never
at the start of a type expression. No shift-reduce conflict expected.
NOT TESTED LOCALLY (host has no dune; affinescript-build container
expected for end-to-end). Would appreciate CI verification.[T] array/list shorthand in user source (#67)1 parent c909043 commit bc4cbf9
1 file changed
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
351 | 361 | | |
352 | 362 | | |
353 | 363 | | |
| |||
0 commit comments