simc-ast-builder
Version:
Parser and AST generator for SimulationCraft files
30 lines • 981 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConditionSplitter = void 0;
/**
* Utility class to split a logical condition AST into its top-level AND parts.
*
* Example:
* Given an ExpressionNode representing A && (B && C),
* splitByAnd(node) returns [A, B, C].
*/
class ConditionSplitter {
/**
* Splits an ExpressionNode into its top-level AND parts.
* If the node is not an AND, returns [node].
* @param node The root ExpressionNode.
* @returns ExpressionNode[] Array of AND parts, in source order.
*/
static splitByAnd(node) {
if (node.nodeType === "and") {
const andNode = node;
return [
...ConditionSplitter.splitByAnd(andNode.left),
...ConditionSplitter.splitByAnd(andNode.right),
];
}
return [node];
}
}
exports.ConditionSplitter = ConditionSplitter;
//# sourceMappingURL=ConditionSplitter.js.map