diff --git a/bun.lockb b/bun.lockb index e29a5a9..041baa2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index d3485f6..b41d87d 100644 --- a/package.json +++ b/package.json @@ -12,21 +12,21 @@ "run:test": "bun run ./src/test.ts" }, "devDependencies": { - "@types/node": "^20.9.4", + "@types/node": "^20.14.12", "@types/treeify": "^1.0.3", "@types/yargs": "^17.0.32", "blessed": "^0.1.81", - "bun-types": "^1.0.14", - "prettier": "^3.1.1", - "tinybench": "^2.5.1", + "bun-types": "^1.1.20", + "prettier": "^3.3.3", + "tinybench": "^2.8.0", "treeify": "^1.1.0", - "typescript": "^5.3.2" + "typescript": "^5.5.4" }, "dependencies": { - "binaryen": "^116.0.0", + "binaryen": "^118.0.0", "chalk": "^5.3.0", "wasmati": "^0.2.0", - "wazum": "latest", + "wazum": "^0.0.13", "yargs": "^17.7.2" }, "repository": { diff --git a/src/parser/index.ts b/src/parser/index.ts index 5595142..d25d5a8 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -240,9 +240,13 @@ export class Parser { const elements: EnumElement[] = []; let index = 0; + let elementValue: NumberLiteral | null = null; + let elementName: TokenData; while (true) { - const name = this.tokenizer.getToken(); - if (name.token !== Token.Identifier) return null; + if (!elementValue) { + elementName = this.tokenizer.getToken(); + if (elementName.token !== Token.Identifier) return null; + } const trailing = this.tokenizer.getToken(); if (trailing.text === "}" || trailing.text === ",") { const element = new EnumElement( @@ -250,14 +254,26 @@ export class Parser { name.text, name.range ), - new NumberLiteral( + elementValue || new NumberLiteral( index.toString() ) ); - + console.log("Element: ", element) + if (elementValue) elementValue = null; index++; elements.push(element); if (trailing.text === "}") break; + } else if (trailing.text === "=") { + elementValue = this.parseNumberLiteral(scope); + console.log("Value: ", elementValue); + if (!elementValue) { + new CompileTimeError( + "Value of an enum element must be of type number or string!", + ErrorTypes.TypeError, + 12 + ); + break; + } } } diff --git a/src/test.ts b/src/test.ts index c2cc7bc..98f2d76 100644 --- a/src/test.ts +++ b/src/test.ts @@ -6,7 +6,7 @@ import { Transpile } from "./transpiler/transpiler"; const start = Date.now(); const tokenizer = new Tokenizer(` enum Axis { - X, + X = 5, Y, Z } @@ -22,7 +22,7 @@ console.log(tokenizer.getAll()); const parser = new Parser(tokenizer, "test.zp"); const program = parser.parseProgram(); //console.dir(program, { depth: null }); -console.log(program); +console.dir(program, { depth: 10 }); const transpiled = Transpile.from(program); console.log("Transpiled:\n" + transpiled); diff --git a/test.ts b/test.ts index f6e032c..f10c10a 100644 --- a/test.ts +++ b/test.ts @@ -1,7 +1,7 @@ enum Axis { - X = 0, - Y = 1, - Z = 2 + Axis = 5, + Axis = 1, + Axis = 2 } export function add(a: i32, b: i32) { let c = a + b