UNPKG

diia-parser

Version:
36 lines (30 loc) 967 B
import StructureNode from "../ast/StructureNode.js"; import DiiaNode from "../ast/DiiaNode.js"; import { DiiaParserError } from "./errors.js"; export function processStructures(ast) { const structures = {}; ast.forEach((node) => { if (node instanceof StructureNode) { structures[node.name.name] = node; } }); ast.forEach((node) => { if (node instanceof DiiaNode) { if (node.structure) { if (node.structure.name in structures) { structures[node.structure.name].methods.push(node); } else { throw new DiiaParserError(`"${node.structure}" не знайдено в контексті`); } } } }); return ast.filter((node) => { if (node instanceof DiiaNode) { if (node.structure) { return false; } } return true; }); }