1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-12 10:39:31 +00:00

Language: enum declarations

Adds \`enum Name { V1, V2, ... }\` as a top-level declaration. Each
variant is registered as a \`u8\` constant equal to its index in the
declaration. Variant names are global and must be unique across all
enums and other symbols (E0501 on collision).

- Lexer: \`enum\` keyword
- AST: \`EnumDecl { name, variants, span }\` field on \`Program\`
- Parser: top-level \`enum\` syntax with optional trailing commas
- Analyzer: \`register_enum\` flattens variants into the symbol table
- IR lowering and AST codegen: variants resolve through the existing
  \`const_values\` path
- Tests cover parsing, duplicate detection, and usage

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 11:36:44 +00:00
parent ae051f5909
commit dbfcb313bc
No known key found for this signature in database
12 changed files with 181 additions and 0 deletions

View file

@ -83,6 +83,7 @@ mod tests {
},
globals: Vec::new(),
constants: Vec::new(),
enums: Vec::new(),
functions: Vec::new(),
states: Vec::new(),
sprites: vec![sprite],