simc-ast-builder
Version:
Parser and AST generator for SimulationCraft files
43 lines • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handlePrevOffGcd = void 0;
const SimCVisitorError_1 = require("../../errors/SimCVisitorError");
/**
* Handler for prev_off_gcd access contexts
* This handles access to previous off-GCD spell usage
* Supports patterns like:
* - prev_off_gcd.spell_name (implicit index 1)
* - prev_off_gcd.1.spell_name (explicit index 1)
* - prev_off_gcd.2.spell_name (explicit index 2)
* - prev_off_gcd.3.spell_name (explicit index 3)
*/
const handlePrevOffGcd = ({ ctx, parts, }) => {
if (parts.length < 2) {
throw new SimCVisitorError_1.SimCVisitorError("Prev off GCD 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 off GCD access with index requires an action name", ctx);
}
actionName = parts[2] || "";
}
return {
actionName,
expressionType: "boolean",
index,
kind: "expression",
nodeType: "prev_off_gcd",
};
};
exports.handlePrevOffGcd = handlePrevOffGcd;
//# sourceMappingURL=PrevOffGcdHandler.js.map