Skip to content

Commit

Permalink
Adddd != operator. Closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jan 8, 2011
1 parent 42aa7e8 commit e3a55b9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The Exponent operator:
2 ** 8
// => 256

### Equality: == >= <= > <
### Equality: == != >= <= > <

Equality operators can be used to equate units, colors, strings, and even identifiers. This is a powerful concept, as even arbitrary identifiers such as as `wahoo` can be utilized as atoms, a function could return `yes` or `no` instead of `true` or `false` (although not advised).

Expand Down
3 changes: 2 additions & 1 deletion lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ Lexer.prototype = {
* | '<='
* | '='
* | '=='
* | '!='
* | '!'
* | '~'
* | '?='
Expand All @@ -484,7 +485,7 @@ Lexer.prototype = {

get op() {
var captures;
if (captures = /^(&&|\|\||[<>=?]=|\*\*|[-,=?:!~+<>*\/%])( *)/.exec(this.str)) {
if (captures = /^(&&|\|\||[!<>=?]=|\*\*|[-,=?:!~+<>*\/%])( *)/.exec(this.str)) {
var op = captures[1];
this.skip(captures);
op = alias[op] || op;
Expand Down
2 changes: 2 additions & 0 deletions lib/nodes/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Node.prototype.operate = function(op, right){
return nodes.Boolean(val == name || val == lower);
case '==':
return nodes.Boolean(this.hash == right.hash);
case '!=':
return nodes.Boolean(this.hash != right.hash);
case '>=':
return nodes.Boolean(this.hash >= right.hash);
case '<=':
Expand Down
4 changes: 3 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ Parser.prototype = {
case '<':
case '>=':
case '<=':
case '!=':
case '==':
case '?':
case 'is a':
Expand Down Expand Up @@ -565,14 +566,15 @@ Parser.prototype = {
},

/**
* typecheck (('==' | '>=' | '<=' | '>' | '<') typecheck)*
* typecheck (('==' | '!=' | '>=' | '<=' | '>' | '<') typecheck)*
*/

get equality() {
var op
, node = this.typecheck;
while (op =
this.accept('==')
|| this.accept('!=')
|| this.accept('>=')
|| this.accept('<=')
|| this.accept('<')
Expand Down
1 change: 1 addition & 0 deletions test/integration/tests/operators.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ body {
foo: true;
foo: false;
foo: "got 15px";
foo: true;
}
2 changes: 2 additions & 0 deletions test/integration/tests/operators.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ body
// "got 15px"
foo "got " + 15px

// true
foo 1 != 5

0 comments on commit e3a55b9

Please sign in to comment.