# HG changeset patch # User Jeff Hammel # Date 1307115089 25200 # Node ID 325dccc383086d8cbcde5aa8663cd5aa3b1af68d # Parent 4b07bb71c2184e6c74c95810a813127aa6798664 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 diff -r 4b07bb71c218 -r 325dccc38308 expr.py --- 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()