[pypy-svn] r66464 - in pypy/branch/parser-compiler/pypy/interpreter/astcompiler: . test
benjamin at codespeak.net
benjamin at codespeak.net
Tue Jul 21 01:37:26 CEST 2009
Author: benjamin
Date: Tue Jul 21 01:37:25 2009
New Revision: 66464
Modified:
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
Log:
fix parsing of negative hex and octal 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 Tue Jul 21 01:37:25 2009
@@ -1051,6 +1051,11 @@
def parse_number(self, raw):
base = 10
+ if raw.startswith("-"):
+ negative = True
+ raw = raw.lstrip("-")
+ else:
+ negative = False
if raw.startswith("0"):
if len(raw) > 2 and raw[1] in "Xx":
base = 16
@@ -1066,6 +1071,8 @@
raw = raw[i:]
if not raw[0].isdigit():
raw = "0" + raw
+ if negative:
+ raw = "-" + raw
w_num_str = self.space.wrap(raw)
w_index = None
w_base = self.space.wrap(base)
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 Tue Jul 21 01:37:25 2009
@@ -1078,6 +1078,7 @@
assert space.eq_w(get_num("00000"), space.wrap(0))
assert space.eq_w(get_num("-3"), space.wrap(-3))
assert space.eq_w(get_num("-0"), space.wrap(0))
+ assert space.eq_w(get_num("-0xAAAAAAL"), space.wrap(-0xAAAAAAL))
n = get_num(str(-sys.maxint - 1))
assert space.is_true(space.isinstance(n, space.w_int))
More information about the Pypy-commit
mailing list