import { CaretNode, h, t, VNode } from "@caret-js/core"; import { CommaListNode } from "./commaList"; import { MathExpressionTag } from "../tags/mathExpression"; export class FunctionCallNode extends CaretNode { constructor(public name: string, public args: CaretNode[] = []) { super(); this.addTag(new MathExpressionTag()); } static from(name: string, args: CaretNode[] = []): FunctionCallNode { args = args.flatMap((node) => node instanceof CommaListNode ? node.expressions : [node] ); return new FunctionCallNode(name, args).mergeTagsFromNodes( args.filter((node) => node instanceof CommaListNode) ); } toDebugMathML(): VNode { return h( "mrow", {}, h("mi", {}, t(this.name)), h("mo", { stretchy: "true" }, t("(")), ...this.args.flatMap((arg, index) => [ arg.toDebugMathML(), index < this.args.length - 1 ? h("mo", {}, t(",")) : null, ]), h("mo", { stretchy: "true" }, t(")")) ); } }