MCPcopy Create free account
hub / github.com/MirrowApp/mirrow / parseVarsBlock

Method parseVarsBlock

packages/core/src/compiler/parser.ts:321–356  ·  view source on GitHub ↗
(blockToken: Token, position: SourcePosition)

Source from the content-addressed store, hash-verified

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[] = [];

Callers 1

parseMethod · 0.95

Calls 2

tokenizeFunction · 0.85

Tested by

no test coverage detected