UNPKG

simc-ast-builder

Version:

Parser and AST generator for SimulationCraft files

44 lines 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleAccessExpr = handleAccessExpr; const SimCVisitorError_1 = require("../../errors/SimCVisitorError"); const fieldUtils_1 = require("../../utils/fieldUtils"); const ContextHandlerRegistry_1 = require("../ContextHandlerRegistry"); /** * Handler for access expression contexts */ function handleAccessExpr(ctx, visitor) { // Extract all parts of the access pattern (e.g., buff.foo.up) let parts = (0, fieldUtils_1.extractAccessParts)(ctx); // Defensive fallback: if only one part and it contains dots, split it again if (parts.length === 1) { const onlyPart = parts[0]; if (typeof onlyPart === "string" && onlyPart.includes(".")) { const splitParts = onlyPart.split(".").filter((p) => p !== ""); parts = splitParts; } } // Log the access parts for debugging // console.log(`Access parts: ${parts.join(", ")}`); // Handle empty parts if (parts.length === 0) { throw new SimCVisitorError_1.SimCVisitorError("Empty access pattern", ctx); } // Always use the first part as the access type const accessType = parts[0]; if (!accessType) { throw new SimCVisitorError_1.SimCVisitorError("Missing access type", ctx); } // Use the access handler registry to process the access pattern // Dispatch to the specific access type handler (e.g., "Buff") const accessHandler = ContextHandlerRegistry_1.contextHandlerRegistry.getAccessHandler(accessType.toLowerCase()); if (accessHandler) { return ContextHandlerRegistry_1.contextHandlerRegistry.dispatchAccess(accessType.toLowerCase(), ctx, visitor, parts); } // Log the access pattern details for debugging console.error(`FAILED ACCESS: ${accessType}`); console.error(`FULL PATTERN: ${parts.join(".")}`); console.error(`CONTEXT TEXT: ${ctx.text}`); throw new SimCVisitorError_1.SimCVisitorError(`No access handler found for type: ${accessType}`, ctx); } //# sourceMappingURL=AccessExprHandler.js.map