changeset 15:6f0c032b65f5 default tip

add a not token, i hope!
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 03 Jun 2011 13:01:22 -0700
parents facdc089ffbc
children
files expr.py test.py
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/expr.py	Fri Jun 03 12:42:57 2011 -0700
+++ b/expr.py	Fri Jun 03 13:01:22 2011 -0700
@@ -57,6 +57,11 @@
     def led(self, parser, left):
         return left != parser.expression(self.lbp)
 
+class not_op_token(object):
+    "!"
+    def nud(self, parser):
+        return not parser.expression()
+
 class and_op_token(object):
     "&&"
     def led(self, parser, left):
@@ -134,6 +139,7 @@
         def lparen(scanner, t): return lparen_token()
         def rparen(scanner, t): return rparen_token()
         def string_(scanner, t): return string_token(t)
+        def not_(scanner, t): return not_op_token()
 
         scanner = re.Scanner([
             (r"true|false", bool_),
@@ -143,6 +149,7 @@
             (r"==", eq),
             (r"!=", neq),
             (r"\|\|", or_),
+            (r"!", not_),
             (r"&&", and_),
             (r"\(", lparen),
             (r"\)", rparen),
--- a/test.py	Fri Jun 03 12:42:57 2011 -0700
+++ b/test.py	Fri Jun 03 13:01:22 2011 -0700
@@ -38,6 +38,7 @@
         self.assertTrue(parse('foo != "bar"', foo='abc'))
         self.assertTrue(parse("foo != bar", foo=True, bar=False))
         self.assertTrue(parse("true != foo", foo=False))
+        self.assertTrue(parse("!false"))
 
     def test_Conjunctions(self):
         self.assertTrue(parse("true && true"))