After a leading `.` (enum literal `.enum`, field access `x.enum` /
`E.struct`, match arm `case .enum:`) a reserved keyword is unambiguously
the member/variant NAME — the dot rules out the keyword reading — so no
backtick escape is needed. A declaration of such a variant still needs
the backtick (enum { `enum: i64 }), since the decl site has no dot.
Adds Parser.dotMemberName() (identifier OR identifier-shaped keyword)
and routes the leading-dot enum-literal and postfix field-access sites
through it. readme updated. The reify example 0614 now uses the cleaner
reify(.enum(...)) spelling (still xfail — reify lands next commit).
30 lines
918 B
Plaintext
30 lines
918 B
Plaintext
// REIFY Phase 0: mint a NEW nominal enum from a `TypeInfo` value at comptime,
|
|
// then construct one of its variants and match on it — exercising that a
|
|
// reify'd enum (with NO backing AST decl) flows through enum codegen unmodified
|
|
// (layout / construct / match), Contract 2.
|
|
//
|
|
// The enum has two variants: `value` carrying an i64 payload, and `closed` with
|
|
// no payload (`payload = void`).
|
|
#import "modules/std.sx";
|
|
#import "modules/std/meta.sx";
|
|
|
|
E :: reify(.enum(.{ variants = .[
|
|
EnumVariant.{ name = "value", payload = i64 },
|
|
EnumVariant.{ name = "closed", payload = void },
|
|
] }));
|
|
|
|
main :: () -> i32 {
|
|
e := E.value(3);
|
|
if e == {
|
|
case .value: (v) { print("value {}\n", v); }
|
|
case .closed: { print("closed\n"); }
|
|
}
|
|
|
|
c := E.closed;
|
|
if c == {
|
|
case .value: (v) { print("value {}\n", v); }
|
|
case .closed: { print("closed\n"); }
|
|
}
|
|
return 0;
|
|
}
|