* Parses an entire function, including its base and all of its arguments.
(
breakOnTokenText?: BreakToken,
name?: string, // For determining its context
)
| 459 | * Parses an entire function, including its base and all of its arguments. |
| 460 | */ |
| 461 | parseFunction( |
| 462 | breakOnTokenText?: BreakToken, |
| 463 | name?: string, // For determining its context |
| 464 | ): AnyParseNode | null { |
| 465 | const token = this.fetch(); |
| 466 | const func = token.text; |
| 467 | const funcData = functions[func]; |
| 468 | if (!funcData) { |
| 469 | return null; |
| 470 | } |
| 471 | this.consume(); // consume command token |
| 472 | |
| 473 | if (name && name !== "atom" && !funcData.allowedInArgument) { |
| 474 | throw new ParseError( |
| 475 | "Got function '" + func + "' with no arguments" + |
| 476 | (name ? " as " + name : ""), token); |
| 477 | // Treat undefined allowedInText as false. |
| 478 | } else if (this.mode === "text" && !funcData.allowedInText) { |
| 479 | throw new ParseError( |
| 480 | "Can't use function '" + func + "' in text mode", token); |
| 481 | // Treat undefined allowedInMath as true. |
| 482 | } else if (this.mode === "math" && funcData.allowedInMath === false) { |
| 483 | throw new ParseError( |
| 484 | "Can't use function '" + func + "' in math mode", token); |
| 485 | } |
| 486 | |
| 487 | const {args, optArgs} = this.parseArguments(func, funcData); |
| 488 | return this.callFunction(func, args, optArgs, token, breakOnTokenText); |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Call a function handler with a suitable context and arguments. |
no test coverage detected