MCPcopy Create free account
hub / github.com/KaTeX/KaTeX / parseFunction

Method parseFunction

src/Parser.ts:462–490  ·  view source on GitHub ↗

* Parses an entire function, including its base and all of its arguments.

(
        breakOnTokenText?: BreakToken,
        name?: string, // For determining its context
    )

Source from the content-addressed store, hash-verified

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

Callers 4

parseGroupMethod · 0.95
delimsizing.tsFile · 0.80
handlerFunction · 0.80
handlerFunction · 0.80

Calls 4

fetchMethod · 0.95
consumeMethod · 0.95
parseArgumentsMethod · 0.95
callFunctionMethod · 0.95

Tested by

no test coverage detected