Scope
Implements Phase 5 of docs/plans/collections.md. Three pattern forms on lists, one on maps:
- Empty list pattern
[] — guard osprey_list_length(xs) == 0
- Fixed-length pattern
[x, y] — guard length, bind via osprey_list_get
- Head/tail pattern
[head, ...tail] — guard length ≥ N, bind head positions and a sub-list via a new osprey_list_drop(n) runtime call
- Subset map pattern
{ "key": binding, ... } — guard contains(key) for each listed key, bind via get
Required work
- Grammar update in
compiler/osprey.g4 — new pattern productions.
make regenerate-parser.
- New AST nodes:
EmptyListPattern, FixedListPattern, HeadTailListPattern, SubsetMapPattern.
- Builder support in
compiler/internal/ast/builder_match.go.
- Match codegen branches in
compiler/internal/codegen/ to emit the guards and bindings.
- Tested examples covering each pattern form in
compiler/examples/tested/basics/lists/.
Acceptance
- Spec examples
classify(xs) and analyze(p) from spec/0004-TypeSystem.md compile and produce expected output.
- All four pattern shapes have an example in
examples/tested/basics/lists/ with .expectedoutput.
make ci green.
Origin
docs/plans/collections.md Phase 5 (deferred — required grammar + parser regen + AST + builder + match-codegen across multiple files).
Scope
Implements Phase 5 of
docs/plans/collections.md. Three pattern forms on lists, one on maps:[]— guardosprey_list_length(xs) == 0[x, y]— guard length, bind viaosprey_list_get[head, ...tail]— guard length ≥ N, bind head positions and a sub-list via a newosprey_list_drop(n)runtime call{ "key": binding, ... }— guardcontains(key)for each listed key, bind viagetRequired work
compiler/osprey.g4— new pattern productions.make regenerate-parser.EmptyListPattern,FixedListPattern,HeadTailListPattern,SubsetMapPattern.compiler/internal/ast/builder_match.go.compiler/internal/codegen/to emit the guards and bindings.compiler/examples/tested/basics/lists/.Acceptance
classify(xs)andanalyze(p)from spec/0004-TypeSystem.md compile and produce expected output.examples/tested/basics/lists/with.expectedoutput.make cigreen.Origin
docs/plans/collections.mdPhase 5 (deferred — required grammar + parser regen + AST + builder + match-codegen across multiple files).