--- loncom/html/adm/LC_math_editor/src/parser.js 2014/09/24 18:14:39 1.1 +++ loncom/html/adm/LC_math_editor/src/parser.js 2015/02/24 15:20:44 1.2 @@ -18,6 +18,8 @@ through which recipients can access the */ +"use strict"; + /** * Equation parser * @constructor @@ -34,7 +36,7 @@ function Parser(implicit_operators, unit this.unit_mode = false; else this.unit_mode = unit_mode; - if (typeof constants == "undefined") + if (typeof constants == "undefined" || constants == null) this.constants = []; else this.constants = constants; @@ -117,7 +119,7 @@ Parser.prototype.addHiddenOperators = fu in_exp = false; else if (!in_exp && token.type == Token.NUMBER) in_units = false; - else if (token.type == Token.OPERATOR && "*/^()".indexOf(token.value) == -1) + else if (!in_exp && token.type == Token.OPERATOR && "*/^()".indexOf(token.value) == -1) in_units = false; else if (token.type == Token.NAME && next_token.value == "(") in_units = false; @@ -127,18 +129,18 @@ Parser.prototype.addHiddenOperators = fu (token.type == Token.NAME && next_token.type == Token.NAME) || (token.type == Token.NUMBER && next_token.type == Token.NAME) || (token.type == Token.NUMBER && next_token.type == Token.NUMBER) || - (token.type == Token.NUMBER && (next_token.value == "(" || next_token.value == "[")) || + (token.type == Token.NUMBER && (next_token.value == "(" || next_token.value == "[" || next_token.value == "{")) || /*(token.type == Token.NAME && next_token.value == "(") ||*/ /* name ( could be a function call */ - ((token.value == ")" || token.value == "]") && next_token.type == Token.NAME) || - ((token.value == ")" || token.value == "]") && next_token.type == Token.NUMBER) || - ((token.value == ")" || token.value == "]") && next_token.value == "(") + ((token.value == ")" || token.value == "]" || token.value == "}") && next_token.type == Token.NAME) || + ((token.value == ")" || token.value == "]" || token.value == "}") && next_token.type == Token.NUMBER) || + ((token.value == ")" || token.value == "]" || token.value == "}") && next_token.value == "(") ) { // support for things like "(1/2) (m/s)" is complex... var units = (this.unit_mode && !in_units && (token.type == Token.NUMBER || - (token.value == ")" || token.value == "]")) && + (token.value == ")" || token.value == "]" || token.value == "}")) && (next_token.type == Token.NAME || - ((next_token.value == "(" || next_token.value == "[") && this.tokens.length > i + 2 && + ((next_token.value == "(" || next_token.value == "[" || next_token.value == "{") && this.tokens.length > i + 2 && this.tokens[i + 2].type == Token.NAME))); if (units) { var test_token, index_test;