Mercurial > hg > expressionparser
comparison expr.py @ 9:421e26c0299f
add a string token
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 03 Jun 2011 08:36:55 -0700 |
parents | 9b2bf000aeed |
children | 15fb1081784f |
comparison
equal
deleted
inserted
replaced
8:9b2bf000aeed | 9:421e26c0299f |
---|---|
91 | 91 |
92 class int_token(literal_token): | 92 class int_token(literal_token): |
93 def __init__(self, value): | 93 def __init__(self, value): |
94 literal_token.__init__(self, int(value)) | 94 literal_token.__init__(self, int(value)) |
95 | 95 |
96 class string_token(literal_token): | |
97 def __init__(self, value): | |
98 literal_token.__init__(self, value[1:-1]) | |
99 | |
96 precedence = [(end_token, rparen_token), | 100 precedence = [(end_token, rparen_token), |
97 (or_op_token,), | 101 (or_op_token,), |
98 (and_op_token,), | 102 (and_op_token,), |
99 (eq_op_token, neq_op_token), | 103 (eq_op_token, neq_op_token), |
100 (lparen_token,), | 104 (lparen_token,), |
124 def neq(scanner, t): return neq_op_token() | 128 def neq(scanner, t): return neq_op_token() |
125 def or_(scanner, t): return or_op_token() | 129 def or_(scanner, t): return or_op_token() |
126 def and_(scanner, t): return and_op_token() | 130 def and_(scanner, t): return and_op_token() |
127 def lparen(scanner, t): return lparen_token() | 131 def lparen(scanner, t): return lparen_token() |
128 def rparen(scanner, t): return rparen_token() | 132 def rparen(scanner, t): return rparen_token() |
129 def string_(scanner, t): return literal_token(t[1:-1]) | 133 def string_(scanner, t): return string_token(t) |
130 | 134 |
131 scanner = re.Scanner([ | 135 scanner = re.Scanner([ |
132 (r"true|false", bool_), | 136 (r"true|false", bool_), |
133 (r"[a-zA-Z_]\w*", identifier), | 137 (r"[a-zA-Z_]\w*", identifier), |
134 (r"[0-9]+", integer), | 138 (r"[0-9]+", integer), |