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:
parent
ae051f5909
commit
dbfcb313bc
12 changed files with 181 additions and 0 deletions
|
|
@ -83,6 +83,7 @@ mod tests {
|
|||
},
|
||||
globals: Vec::new(),
|
||||
constants: Vec::new(),
|
||||
enums: Vec::new(),
|
||||
functions: Vec::new(),
|
||||
states: Vec::new(),
|
||||
sprites: vec![sprite],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue