Skip to content

Commit 77e4cfe

Browse files
committed
feat(parser): accept [T] array/list shorthand in user source
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.
1 parent 2f43839 commit 77e4cfe

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

lib/parser.mly

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ type_expr_primary:
348348
the interior in one pass without lookahead conflicts. */
349349
| LBRACE body = ty_record_body RBRACE
350350
{ TyRecord (fst body, snd body) }
351+
/* Array/list shorthand: `[T]` desugars to `List[T]`. This is the syntax
352+
stdlib has used all along (`fn map<T, U>(arr: [T], f: T -> U) -> [U]`,
353+
`Result[[T], E]`, etc.) but it was previously only accepted in stdlib
354+
load paths, not in user source. Closes #40. */
355+
| LBRACKET ty = type_expr RBRACKET
356+
{ TyApp (mk_ident "List" $startpos $endpos, [TyArg ty]) }
351357
/* Built-in types */
352358
| NAT { TyCon (mk_ident "Nat" $startpos $endpos) }
353359
| INT_T { TyCon (mk_ident "Int" $startpos $endpos) }

0 commit comments

Comments
 (0)