* Parses an entire function, including its base and all of its arguments.
(breakOnTokenText, name, // For error reporting. greediness)
| 15240 | |
| 15241 | |
| 15242 | parseFunction(breakOnTokenText, name, // For error reporting. |
| 15243 | greediness) { |
| 15244 | const token = this.nextToken; |
| 15245 | const func = token.text; |
| 15246 | const funcData = functions[func]; |
| 15247 | |
| 15248 | if (!funcData) { |
| 15249 | return null; |
| 15250 | } |
| 15251 | |
| 15252 | if (greediness != null && funcData.greediness <= greediness) { |
| 15253 | throw new ParseError("Got function '" + func + "' with no arguments" + (name ? " as " + name : ""), token); |
| 15254 | } else if (this.mode === "text" && !funcData.allowedInText) { |
| 15255 | throw new ParseError("Can't use function '" + func + "' in text mode", token); |
| 15256 | } else if (this.mode === "math" && funcData.allowedInMath === false) { |
| 15257 | throw new ParseError("Can't use function '" + func + "' in math mode", token); |
| 15258 | } // hyperref package sets the catcode of % as an active character |
| 15259 | |
| 15260 | |
| 15261 | if (funcData.argTypes && funcData.argTypes[0] === "url") { |
| 15262 | this.gullet.lexer.setCatcode("%", 13); |
| 15263 | } // Consume the command token after possibly switching to the |
| 15264 | // mode specified by the function (for instant mode switching), |
| 15265 | // and then immediately switch back. |
| 15266 | |
| 15267 | |
| 15268 | if (funcData.consumeMode) { |
| 15269 | const oldMode = this.mode; |
| 15270 | this.switchMode(funcData.consumeMode); |
| 15271 | this.consume(); |
| 15272 | this.switchMode(oldMode); |
| 15273 | } else { |
| 15274 | this.consume(); |
| 15275 | } |
| 15276 | |
| 15277 | const _this$parseArguments = this.parseArguments(func, funcData), |
| 15278 | args = _this$parseArguments.args, |
| 15279 | optArgs = _this$parseArguments.optArgs; |
| 15280 | |
| 15281 | return this.callFunction(func, args, optArgs, token, breakOnTokenText); |
| 15282 | } |
| 15283 | /** |
| 15284 | * Call a function handler with a suitable context and arguments. |
| 15285 | */ |
no test coverage detected