UNPKG

simc-ast-builder

Version:

Parser and AST generator for SimulationCraft files

43 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handlePrev = void 0; const SimCVisitorError_1 = require("../../errors/SimCVisitorError"); /** * Handler for prev access contexts * This handles access to the previous cast of a spell * Supports patterns like: * - prev.spell_name (implicit index 1) * - prev.1.spell_name (explicit index 1) * - prev.2.spell_name (explicit index 2) * - prev.3.spell_name (explicit index 3) */ const handlePrev = ({ ctx, parts }) => { if (parts.length < 2) { throw new SimCVisitorError_1.SimCVisitorError("Prev access requires an action name", ctx); } // Check if the first part is a number (index) const firstPart = parts[1] || ""; let index = parseInt(firstPart, 10); let actionName; if (isNaN(index)) { // If not a number, it's the action name with implicit index 1 index = 1; actionName = firstPart; } else { // If it's a number, the next part is the action name if (parts.length < 3) { throw new SimCVisitorError_1.SimCVisitorError("Prev access with index requires an action name", ctx); } actionName = parts[2] || ""; } return { actionName, expressionType: "boolean", index, kind: "expression", nodeType: "prev", }; }; exports.handlePrev = handlePrev; //# sourceMappingURL=PrevHandler.js.map