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