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