Mercurial > hg > expressionparser
changeset 7:325dccc38308
begin using subclasses for tokens; the eventual goal is that a token class will know everything it can about what it is and the parser just knows about what tokens are
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 03 Jun 2011 08:31:29 -0700 |
parents | 4b07bb71c218 |
children | 9b2bf000aeed |
files | expr.py |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/expr.py Fri Jun 03 08:24:48 2011 -0700 +++ b/expr.py Fri Jun 03 08:31:29 2011 -0700 @@ -82,6 +82,11 @@ # lowest left binding power, always ends parsing lbp = 0 +class bool_token(literal_token): + def __init__(self, value): + value = {'true':True, 'false':False}[value] + literal_token.__init__(self, value) + precedence = [(end_token, rparen_token), (or_op_token,), (and_op_token,), @@ -106,7 +111,7 @@ Lex the input text into tokens and yield them in sequence. """ # scanner callbacks - def bool_(scanner, t): return literal_token({'true':True, 'false':False}[t]) + def bool_(scanner, t): return bool_token(t) def identifier(scanner, t): return ident_token(t) def integer(scanner, t): return literal_token(int(t)) def eq(scanner, t): return eq_op_token()