feat(parser): reserved keyword as member name after .
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).
This commit is contained in:
18
readme.md
18
readme.md
@@ -184,7 +184,23 @@ positions are exempt**: a struct *field*, a union *tag*, and a protocol
|
||||
so they never mis-lower. The bare exemption covers only the identifier-classified
|
||||
reserved names (`i1`..`i64`, `u1`..`u64`, `bool`, `string`, `void`, `usize`,
|
||||
`isize`, `Any`); `f32` and `f64` are lexer keywords, so even in a member slot they
|
||||
need the backtick (`` struct { `f32: i64 } ``). A leading backtick escapes one into
|
||||
need the backtick (`` struct { `f32: i64 } ``).
|
||||
|
||||
**After a leading `.`**, however, even a full lexer keyword is accepted bare as the
|
||||
member/variant name — the dot makes the keyword reading impossible, so no backtick
|
||||
is needed. This covers the enum-literal (`.enum`), field-access (`x.enum`,
|
||||
`E.struct`), and match-arm (`case .enum:`) positions. A *declaration* of such a
|
||||
variant still needs the backtick (`` enum { `enum: i64 } ``), since the decl site
|
||||
has no disambiguating dot:
|
||||
|
||||
```sx
|
||||
TI :: enum { `enum: i64; closed; } // decl: backtick needed (no dot)
|
||||
t := TI.enum(7); // construct: dot disambiguates — bare `enum`
|
||||
if t == { case .enum: (v) { … } // match: likewise bare after `.`
|
||||
case .closed: { … } }
|
||||
```
|
||||
|
||||
A leading backtick escapes one into
|
||||
a **raw identifier**:
|
||||
`` `name `` is the literal identifier `name` (the backtick drops out of the text),
|
||||
usable in **every** position — value, declaration, and type, and optional in the
|
||||
|
||||
Reference in New Issue
Block a user