(blockToken: Token, position: SourcePosition)
| 319 | } |
| 320 | |
| 321 | private parseVarsBlock(blockToken: Token, position: SourcePosition): VarsBlock { |
| 322 | const raw = blockToken.value; |
| 323 | if (!raw.startsWith("{") || !raw.endsWith("}")) { |
| 324 | throw new ParserError("Malformed vars block", blockToken.position); |
| 325 | } |
| 326 | |
| 327 | const inner = raw.slice(1, raw.length - 1); |
| 328 | if (inner.trim().length === 0) { |
| 329 | return { |
| 330 | type: "VarsBlock", |
| 331 | declarations: [], |
| 332 | position, |
| 333 | }; |
| 334 | } |
| 335 | |
| 336 | const blockTokens = tokenize(inner); |
| 337 | const nestedParser = new Parser(blockTokens); |
| 338 | const declarations = nestedParser.parseVariableDeclarations(); |
| 339 | |
| 340 | // Build symbol table for validation |
| 341 | for (const declaration of declarations) { |
| 342 | if (this.symbolTable.has(declaration.name)) { |
| 343 | throw new ParserError( |
| 344 | `Variable '${declaration.name}' is already declared`, |
| 345 | declaration.position |
| 346 | ); |
| 347 | } |
| 348 | this.symbolTable.set(declaration.name, declaration.value); |
| 349 | } |
| 350 | |
| 351 | return { |
| 352 | type: "VarsBlock", |
| 353 | declarations, |
| 354 | position, |
| 355 | }; |
| 356 | } |
| 357 | |
| 358 | private parseVariableDeclarations(): VariableDeclaration[] { |
| 359 | const declarations: VariableDeclaration[] = []; |
no test coverage detected