simc-ast-builder
Version:
Parser and AST generator for SimulationCraft files
53 lines • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleMathFuncExpr = exports.handleFloorExpr = exports.handleCeilExpr = void 0;
/**
* Handler for ceil expressions
*/
const handleCeilExpr = (ctx, visitor) => {
// Only handle if this is a ceil function
if (!ctx.OP_CEIL()) {
throw new Error("Not a ceil expression");
}
return {
argument: visitor.visit(ctx.expression()),
expressionType: "numeric",
function: "ceil",
kind: "expression",
nodeType: "math",
};
};
exports.handleCeilExpr = handleCeilExpr;
/**
* Handler for floor expressions
*/
const handleFloorExpr = (ctx, visitor) => {
// Only handle if this is a floor function
if (!ctx.OP_FLOOR()) {
throw new Error("Not a floor expression");
}
return {
argument: visitor.visit(ctx.expression()),
expressionType: "numeric",
function: "floor",
kind: "expression",
nodeType: "math",
};
};
exports.handleFloorExpr = handleFloorExpr;
/**
* Generic handler for math function expressions (ceil/floor)
*/
const handleMathFuncExpr = (ctx, visitor) => {
if (ctx.OP_CEIL()) {
return handleCeilExpr(ctx, visitor);
}
else if (ctx.OP_FLOOR()) {
return handleFloorExpr(ctx, visitor);
}
else {
throw new Error("Unknown math function");
}
};
exports.handleMathFuncExpr = handleMathFuncExpr;
//# sourceMappingURL=MathFuncExprHandler.js.map