Skip to content

Commit 8347ba0

Browse files
hyperpolymathclaude
andcommitted
feat: support inline variant type syntax in parser
Adds `type X = A | B | C;` syntax as sugar for `enum X { A, B, C }`. Requires at least 2 variants separated by PIPE to avoid conflicting with the existing type alias rule. Reuses the existing `variant_decl` grammar and `TyEnum` AST node — no AST changes needed. Fixes: test_types.as in airborne-submarine-squadron Also fixes: stdlib/prelude.as, examples/traits.as variant definitions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3a31737 commit 8347ba0

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

lib/parser.mly

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ type_decl:
212212
td_name = name;
213213
td_type_params = Option.value type_params ~default:[];
214214
td_body = TyAlias ty } }
215+
/* Inline variant syntax: type X = A | B | C(Int) | D; */
216+
| vis = visibility? TYPE name = ident type_params = type_params? EQ
217+
first = variant_decl PIPE rest = separated_nonempty_list(PIPE, variant_decl) SEMICOLON
218+
{ { td_vis = Option.value vis ~default:Private;
219+
td_name = name;
220+
td_type_params = Option.value type_params ~default:[];
221+
td_body = TyEnum (first :: rest) } }
215222
| vis = visibility? STRUCT name = ident type_params = type_params?
216223
LBRACE fields = separated_list(COMMA, struct_field) RBRACE
217224
{ { td_vis = Option.value vis ~default:Private;

0 commit comments

Comments
 (0)