simc-ast-builder
Version:
Parser and AST generator for SimulationCraft files
59 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleMinMaxExpr = exports.handleMinExpr = exports.handleMaxExpr = void 0;
/**
* Handler for max expressions
*/
const handleMaxExpr = (ctx, visitor) => {
// Only handle if this is a max function
if (!ctx.OP_MAX()) {
throw new Error("Not a max expression");
}
const left = visitor.visit(ctx.expression(0));
const right = visitor.visit(ctx.expression(1));
return {
expressionType: "numeric",
function: "max",
kind: "expression",
left,
nodeType: "minOrMax",
right,
};
};
exports.handleMaxExpr = handleMaxExpr;
/**
* Handler for min expressions
*/
const handleMinExpr = (ctx, visitor) => {
// Only handle if this is a min function
if (!ctx.OP_MIN()) {
throw new Error("Not a min expression");
}
const left = visitor.visit(ctx.expression(0));
const right = visitor.visit(ctx.expression(1));
return {
expressionType: "numeric",
function: "min",
kind: "expression",
left,
nodeType: "minOrMax",
right,
};
};
exports.handleMinExpr = handleMinExpr;
/**
* Generic handler for min/max expressions
*/
const handleMinMaxExpr = (ctx, visitor) => {
if (ctx.OP_MAX()) {
return handleMaxExpr(ctx, visitor);
}
else if (ctx.OP_MIN()) {
return handleMinExpr(ctx, visitor);
}
else {
throw new Error("Unknown min/max function");
}
};
exports.handleMinMaxExpr = handleMinMaxExpr;
//# sourceMappingURL=MinMaxExprHandler.js.map