make operations left-associative Closes #20

This commit is contained in:
cloudhead
2010-05-03 14:25:12 -04:00
parent 0a271ccb5b
commit 1dcb4e77cb
3 changed files with 13 additions and 11 deletions

View File

@@ -827,24 +827,22 @@ less.Parser = function Parser(env) {
}
},
multiplication: function () {
var m, a, op;
var m, a, op, operation;
if (m = $(this.operand)) {
if ((op = $(/[\/*]/g)) && (a = $(this.multiplication))) {
return new(tree.Operation)(op, [m, a]);
} else {
return m;
while ((op = $(/[\/*]/g)) && (a = $(this.operand))) {
operation = new(tree.Operation)(op, [operation || m, a]);
}
return operation || m;
}
},
addition: function () {
var m, a, op;
var m, a, op, operation;
if (m = $(this.multiplication)) {
if ((op = $(/[-+]\s+/g) || (input[i - 1] != ' ' && $(/[-+]/g))) &&
(a = $(this.addition))) {
return new(tree.Operation)(op, [m, a]);
} else {
return m;
while ((op = $(/[-+]\s+/g) || (input[i - 1] != ' ' && $(/[-+]/g))) &&
(a = $(this.multiplication))) {
operation = new(tree.Operation)(op, [operation || m, a]);
}
return operation || m;
}
},