added debug info; fix parser bug with double negation

This commit is contained in:
Misko Hevery 2010-01-19 17:53:20 -08:00
parent 910ddbe34e
commit db2031c5a1
4 changed files with 40 additions and 15 deletions

View file

@ -84,4 +84,11 @@ label {
.editor TEXTAREA { .editor TEXTAREA {
height: 50px; height: 50px;
}
.debug{
font-size: .7em;
white-space: pre;
padding: 0;
margin: 0;
} }

View file

@ -39,6 +39,18 @@
<input type="button" ng-action="$anchor.edituser=undefined" value="Close"/> <input type="button" ng-action="$anchor.edituser=undefined" value="Close"/>
</div> </div>
</div> </div>
<hr/>
<div class="debug">
userFilter={{userFilter|json}}
tweetFilter={{tweetFilter|json}}
$anchor={{$anchor}}
users={{users}}
tweets={{tweets}}
</div>
</div> </div>
<div class="tweeter box"> <div class="tweeter box">
<h1>Tweets: {{$anchor.user}}</h1> <h1>Tweets: {{$anchor.user}}</h1>

View file

@ -294,15 +294,13 @@ Parser.prototype = {
} }
}, },
_unary: function(fn, parse) { _unary: function(fn, right) {
var right = parse.apply(this);
return function(self) { return function(self) {
return fn(self, right(self)); return fn(self, right(self));
}; };
}, },
_binary: function(left, fn, parse) { _binary: function(left, fn, right) {
var right = parse.apply(this);
return function(self) { return function(self) {
return fn(self, left(self), right(self)); return fn(self, left(self), right(self));
}; };
@ -343,7 +341,7 @@ Parser.prototype = {
var token; var token;
while(true) { while(true) {
if ((token = this.expect('|'))) { if ((token = this.expect('|'))) {
left = this._binary(left, token.fn, this.filter); left = this._binary(left, token.fn, this.filter());
} else { } else {
return left; return left;
} }
@ -405,7 +403,7 @@ Parser.prototype = {
this.text.substring(token.index) + "' is not assignable."; this.text.substring(token.index) + "' is not assignable.";
} }
var ident = function(){return left.isAssignable;}; var ident = function(){return left.isAssignable;};
return this._binary(ident, token.fn, this.logicalOR); return this._binary(ident, token.fn, this.logicalOR());
} else { } else {
return left; return left;
} }
@ -416,7 +414,7 @@ Parser.prototype = {
var token; var token;
while(true) { while(true) {
if ((token = this.expect('||'))) { if ((token = this.expect('||'))) {
left = this._binary(left, token.fn, this.logicalAND); left = this._binary(left, token.fn, this.logicalAND());
} else { } else {
return left; return left;
} }
@ -428,7 +426,7 @@ Parser.prototype = {
var token; var token;
while(true) { while(true) {
if ((token = this.expect('&&'))) { if ((token = this.expect('&&'))) {
left = this._binary(left, token.fn, this.negated); left = this._binary(left, token.fn, this.negated());
} else { } else {
return left; return left;
} }
@ -438,9 +436,9 @@ Parser.prototype = {
negated: function(){ negated: function(){
var token; var token;
if (token = this.expect('!')) { if (token = this.expect('!')) {
return this._unary(token.fn, this.equality); return this._unary(token.fn, this.assignment());
} else { } else {
return this.equality(); return this.equality();
} }
}, },
@ -449,7 +447,7 @@ Parser.prototype = {
var token; var token;
while(true) { while(true) {
if ((token = this.expect('==','!='))) { if ((token = this.expect('==','!='))) {
left = this._binary(left, token.fn, this.relational); left = this._binary(left, token.fn, this.relational());
} else { } else {
return left; return left;
} }
@ -461,7 +459,7 @@ Parser.prototype = {
var token; var token;
while(true) { while(true) {
if ((token = this.expect('<', '>', '<=', '>='))) { if ((token = this.expect('<', '>', '<=', '>='))) {
left = this._binary(left, token.fn, this.additive); left = this._binary(left, token.fn, this.additive());
} else { } else {
return left; return left;
} }
@ -472,7 +470,7 @@ Parser.prototype = {
var left = this.multiplicative(); var left = this.multiplicative();
var token; var token;
while(token = this.expect('+','-')) { while(token = this.expect('+','-')) {
left = this._binary(left, token.fn, this.multiplicative); left = this._binary(left, token.fn, this.multiplicative());
} }
return left; return left;
}, },
@ -481,7 +479,7 @@ Parser.prototype = {
var left = this.unary(); var left = this.unary();
var token; var token;
while(token = this.expect('*','/','%')) { while(token = this.expect('*','/','%')) {
left = this._binary(left, token.fn, this.unary); left = this._binary(left, token.fn, this.unary());
} }
return left; return left;
}, },
@ -491,7 +489,7 @@ Parser.prototype = {
if (this.expect('+')) { if (this.expect('+')) {
return this.primary(); return this.primary();
} else if (token = this.expect('-')) { } else if (token = this.expect('-')) {
return this._binary(Parser.ZERO, token.fn, this.multiplicative); return this._binary(Parser.ZERO, token.fn, this.multiplicative());
} else { } else {
return this.primary(); return this.primary();
} }

View file

@ -460,3 +460,11 @@ ParserTest.prototype.testReturnFunctionsAreNotBound = function(){
assertEquals("direct Group.all", "function", typeof Group.query); assertEquals("direct Group.all", "function", typeof Group.query);
}; };
ParserTest.prototype.testDoubleNegationBug = function (){
var scope = new Scope();
assertEquals(true, scope.eval('true'));
assertEquals(false, scope.eval('!true'));
assertEquals(true, scope.eval('!!true'));
assertEquals('a', scope.eval('{true:"a", false:"b"}[!!true]'));
};