comparison expr.py @ 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 ec0e83ec329f
children
comparison
equal deleted inserted replaced
14:facdc089ffbc 15:6f0c032b65f5
55 class neq_op_token(object): 55 class neq_op_token(object):
56 "!=" 56 "!="
57 def led(self, parser, left): 57 def led(self, parser, left):
58 return left != parser.expression(self.lbp) 58 return left != parser.expression(self.lbp)
59 59
60 class not_op_token(object):
61 "!"
62 def nud(self, parser):
63 return not parser.expression()
64
60 class and_op_token(object): 65 class and_op_token(object):
61 "&&" 66 "&&"
62 def led(self, parser, left): 67 def led(self, parser, left):
63 right = parser.expression(self.lbp) 68 right = parser.expression(self.lbp)
64 return left and right 69 return left and right
132 def or_(scanner, t): return or_op_token() 137 def or_(scanner, t): return or_op_token()
133 def and_(scanner, t): return and_op_token() 138 def and_(scanner, t): return and_op_token()
134 def lparen(scanner, t): return lparen_token() 139 def lparen(scanner, t): return lparen_token()
135 def rparen(scanner, t): return rparen_token() 140 def rparen(scanner, t): return rparen_token()
136 def string_(scanner, t): return string_token(t) 141 def string_(scanner, t): return string_token(t)
142 def not_(scanner, t): return not_op_token()
137 143
138 scanner = re.Scanner([ 144 scanner = re.Scanner([
139 (r"true|false", bool_), 145 (r"true|false", bool_),
140 (r"[a-zA-Z_]\w*", identifier), 146 (r"[a-zA-Z_]\w*", identifier),
141 (r"[0-9]+", integer), 147 (r"[0-9]+", integer),
142 (r'("[^"]*")|(\'[^\']*\')', string_), 148 (r'("[^"]*")|(\'[^\']*\')', string_),
143 (r"==", eq), 149 (r"==", eq),
144 (r"!=", neq), 150 (r"!=", neq),
145 (r"\|\|", or_), 151 (r"\|\|", or_),
152 (r"!", not_),
146 (r"&&", and_), 153 (r"&&", and_),
147 (r"\(", lparen), 154 (r"\(", lparen),
148 (r"\)", rparen), 155 (r"\)", rparen),
149 (r"\s+", None), # skip whitespace 156 (r"\s+", None), # skip whitespace
150 ]) 157 ])