double brackets does not leave brackets behind, to align with the most common scenarios

This commit is contained in:
Luke Page
2013-02-02 23:57:31 +00:00
parent 6cd6fb2585
commit c2880a9baa
2 changed files with 9 additions and 5 deletions

View File

@@ -4,7 +4,8 @@ tree.Expression = function (value) { this.value = value; };
tree.Expression.prototype = {
eval: function (env) {
var returnValue,
inParenthesis = this.parens && !this.parensInOp;
inParenthesis = this.parens && !this.parensInOp,
doubleParen = false;
if (inParenthesis) {
env.inParenthesis();
}
@@ -13,6 +14,9 @@ tree.Expression.prototype = {
return e.eval(env);
}));
} else if (this.value.length === 1) {
if (this.value[0].parens && !this.value[0].parensInOp) {
doubleParen = true;
}
returnValue = this.value[0].eval(env);
} else {
returnValue = this;
@@ -20,7 +24,7 @@ tree.Expression.prototype = {
if (inParenthesis) {
env.outOfParenthesis();
}
if (this.parens && this.parensInOp && !(env.isMathsOn())) {
if (this.parens && this.parensInOp && !(env.isMathsOn()) && !doubleParen) {
returnValue = new(tree.Paren)(returnValue);
}
return returnValue;