improve condition parser, support true/false values

This commit is contained in:
Alexis Sellier
2011-12-30 00:43:46 +01:00
parent 1d67c5b382
commit 7a71697965
3 changed files with 31 additions and 10 deletions

View File

@@ -517,7 +517,7 @@ less.Parser = function Parser(env) {
// detect named color
return new(tree.Color)(tree.colors[k].slice(1));
} else {
return new(tree.Keyword)(k)
return new(tree.Keyword)(k);
}
}
},
@@ -1159,16 +1159,20 @@ less.Parser = function Parser(env) {
}
},
condition: function () {
var a, b, op, index = i;
if ($('(')) {
if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
if (op = $(/^(?:>=|=<|\!=|[<=>])/)) {
if (b = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
if ($(')')) {
return new(tree.Condition)(op, a, b, index);
}
}
var a, b, op, index = i, negate = false;
expect('(');
if ($('!')) { negate = true }
if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
if (op = $(/^(?:>=|=<|\!=|[<=>])/)) {
if (b = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
expect(')');
return new(tree.Condition)(op, a, b, index);
} else {
error('expected expression');
}
} else {
expect(')');
return new(tree.Condition)(negate ? '!=' : '=', a, new(tree.Keyword)('true'), index);
}
}
},

View File

@@ -30,3 +30,9 @@
.default1 {
content: default;
}
.test1 {
content: "true.";
}
.test2 {
content: "false.";
}

View File

@@ -58,3 +58,14 @@
content: default;
}
.default1 { .default }
// true & false keywords
.test (@a) when (@a) {
content: "true.";
}
.test (@a) when (!@a) {
content: "false.";
}
.test1 { .test(true) }
.test2 { .test(false) }