From 0c2dd845f339ed62f9a8bb74e45b10e359840bad Mon Sep 17 00:00:00 2001 From: Ashish Myles Date: Mon, 4 Sep 2017 15:48:56 -0400 Subject: [PATCH] Update Parser comments to match implementation. (#837) --- src/Parser.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Parser.js b/src/Parser.js index 57ecac5c..2728eb96 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -43,15 +43,23 @@ import ParseError from "./ParseError"; * standalone object which can be used as an argument to another function. */ -/** - * An initial function (without its arguments), or an argument to a function. - * The `result` argument should be a ParseNode. - */ -function ParseFuncOrArgument(result, isFunction, token) { - this.result = result; - // Is this a function (i.e. is it something defined in functions.js)? - this.isFunction = isFunction; - this.token = token; +/** A function name or an argument to a function. */ +class ParseFuncOrArgument { + /** + * @param {ParseNode|string} result It's a string if `isFunction=true` or if + * `result="$"` for switching into math mode; otherwise, it's a ParseNode + * and `isFunction` must be false. If it's a function, the string should + * be a name defined by defineFunction, e.g. "\\frac". + * @param {boolean} isFunction True when this is a function. False when it's a + * function argument or "$" to switch into math mode. + * @param {Token} token + */ + constructor(result, isFunction, token) { + this.result = result; + // Is this a function (i.e. is it something defined in functions.js)? + this.isFunction = isFunction; + this.token = token; + } } class Parser { @@ -106,7 +114,7 @@ class Parser { /** * Main parsing function, which parses an entire input. * - * @return {?Array.} + * @return {Array.} */ parse() { // Try to parse the input @@ -140,7 +148,7 @@ class Parser { * should end with, or `null` if something else should end the * expression. * - * @return {ParseNode} + * @return {Array} */ parseExpression(breakOnInfix, breakOnTokenText) { const body = []; @@ -179,7 +187,8 @@ class Parser { * There can only be one infix operator per group. If there's more than one * then the expression is ambiguous. This can be resolved by adding {}. * - * @returns {Array} + * @param {Array} body + * @return {Array} */ handleInfixNodes(body) { let overIndex = -1; @@ -635,7 +644,7 @@ class Parser { if (!this.settings.throwOnError && this.nextToken.text[0] === "\\") { arg = new ParseFuncOrArgument( - this.handleUnsupportedCmd(this.nextToken.text), + this.handleUnsupportedCmd(), false); } else { throw new ParseError(