[pypy-svn] r66192 - in pypy/branch/parser-compiler/pypy/interpreter/astcompiler: . test
benjamin at codespeak.net
benjamin at codespeak.net
Mon Jul 13 23:05:37 CEST 2009
Author: benjamin
Date: Mon Jul 13 23:05:35 2009
New Revision: 66192
Modified:
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
Log:
support parsing of octal and hex literals
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py Mon Jul 13 23:05:35 2009
@@ -1029,15 +1029,25 @@
def parse_number(self, raw):
base = 10
+ if raw.startswith("0"):
+ if len(raw) > 2 and raw[1] in "Xx":
+ base = 16
+ elif len(raw) > 1:
+ base = 8
+ raw = raw.rstrip("0xX")
+ if not raw:
+ raw = "0"
w_num_str = self.space.wrap(raw)
+ w_index = None
+ w_base = self.space.wrap(base)
if raw[-1] in "lL":
tp = self.space.w_long
- return self.space.call_function(tp, w_num_str)
+ return self.space.call_function(tp, w_num_str, w_base)
elif raw[-1] in "jJ":
tp = self.space.w_complex
return self.space.call_function(tp, w_num_str)
try:
- return self.space.call_function(self.space.w_int, w_num_str)
+ return self.space.call_function(self.space.w_int, w_num_str, w_base)
except error.OperationError, e:
if not e.match(self.space, self.space.w_ValueError):
raise
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py Mon Jul 13 23:05:35 2009
@@ -1032,6 +1032,13 @@
assert space.eq_w(get_num("32l"), space.newlong(32))
assert space.eq_w(get_num("13j"), space.wrap(13j))
assert space.eq_w(get_num("13J"), space.wrap(13J))
+ assert space.eq_w(get_num("053"), space.wrap(053))
+ assert space.eq_w(get_num("00053"), space.wrap(053))
+ for num in ("0x53", "0X53", "0x0000053", "0X00053"):
+ assert space.eq_w(get_num(num), space.wrap(0x53))
+ assert space.eq_w(get_num("0X53"), space.wrap(0x53))
+ assert space.eq_w(get_num("0"), space.wrap(0))
+ assert space.eq_w(get_num("00000"), space.wrap(0))
def check_comprehension(self, brackets, ast_type):
def brack(s):
More information about the Pypy-commit
mailing list