[pypy-svn] r77626 - in pypy/branch/fast-forward/pypy/interpreter: astcompiler astcompiler/test pyparser pyparser/test

afa at codespeak.net afa at codespeak.net
Tue Oct 5 20:00:58 CEST 2010


Author: afa
Date: Tue Oct  5 20:00:56 2010
New Revision: 77626

Modified:
   pypy/branch/fast-forward/pypy/interpreter/astcompiler/astbuilder.py
   pypy/branch/fast-forward/pypy/interpreter/astcompiler/test/test_astbuilder.py
   pypy/branch/fast-forward/pypy/interpreter/pyparser/genpytokenize.py
   pypy/branch/fast-forward/pypy/interpreter/pyparser/pytokenize.py
   pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py
Log:
Add Binary literals: 0b11101


Modified: pypy/branch/fast-forward/pypy/interpreter/astcompiler/astbuilder.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/astcompiler/astbuilder.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/astcompiler/astbuilder.py	Tue Oct  5 20:00:56 2010
@@ -1037,6 +1037,8 @@
         if raw.startswith("0"):
             if len(raw) > 2 and raw[1] in "Xx":
                 base = 16
+            elif len(raw) > 2 and raw[1] in "Bb":
+                base = 2
             ## elif len(raw) > 2 and raw[1] in "Oo": # Fallback below is enough
             ##     base = 8
             elif len(raw) > 1:
@@ -1045,7 +1047,7 @@
             i = 0
             limit = len(raw) - 1
             while i < limit:
-                if raw[i] not in "0xXoO":
+                if raw[i] not in "0xXoOBb":
                     break
                 i += 1
             raw = raw[i:]

Modified: pypy/branch/fast-forward/pypy/interpreter/astcompiler/test/test_astbuilder.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/astcompiler/test/test_astbuilder.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/astcompiler/test/test_astbuilder.py	Tue Oct  5 20:00:56 2010
@@ -1139,6 +1139,8 @@
         assert space.is_true(space.isinstance(n, space.w_int))
         for num in ("0o53", "0O53", "0o0000053", "0O00053"):
             assert space.eq_w(get_num(num), space.wrap(053))
+        for num in ("0b00101", "0B00101", "0b101", "0B101"):
+            assert space.eq_w(get_num(num), space.wrap(5))
 
     def check_comprehension(self, brackets, ast_type):
         def brack(s):

Modified: pypy/branch/fast-forward/pypy/interpreter/pyparser/genpytokenize.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyparser/genpytokenize.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyparser/genpytokenize.py	Tue Oct  5 20:00:56 2010
@@ -61,11 +61,16 @@
                       maybe(states, groupStr(states, "oO")),
                       any(states, groupStr(states, "01234567")),
                       maybe(states, groupStr(states, "lL")))
+    binNumber = chain(states,
+                      newArcPair(states, "0"),
+                      groupStr(states, "bB"),
+                      any(states, groupStr(states, "01")),
+                      maybe(states, groupStr(states, "lL")))
     decNumber = chain(states,
                       groupStr(states, "123456789"),
                       any(states, makeDigits()),
                       maybe(states, groupStr(states, "lL")))
-    intNumber = group(states, hexNumber, octNumber, decNumber)
+    intNumber = group(states, hexNumber, octNumber, binNumber, decNumber)
     # ____________________________________________________________
     # Exponents
     def makeExp ():

Modified: pypy/branch/fast-forward/pypy/interpreter/pyparser/pytokenize.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyparser/pytokenize.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyparser/pytokenize.py	Tue Oct  5 20:00:56 2010
@@ -26,7 +26,7 @@
 accepts = [True, True, True, True, True, True, True, True,
            True, True, False, True, True, True, False, False,
            False, False, True, False, False, True, True,
-           True, False, True, False, True, False, True,
+           True, True, False, True, False, True, False, True,
            False, True, False, False, False, True, False,
            False, False, True]
 states = [
@@ -109,22 +109,22 @@
      'v': 1, 'w': 1, 'x': 1, 'y': 1,
      'z': 1},
 
-    {'.': 25, '0': 23, '1': 23, '2': 23,
+    {'.': 26, '0': 23, '1': 23, '2': 23,
      '3': 23, '4': 23, '5': 23, '6': 23,
-     '7': 23, '8': 24, '9': 24, 'E': 26,
-     'J': 13, 'L': 13, 'O': 22, 'X': 21,
-     'e': 26, 'j': 13, 'l': 13, 'o': 22,
-     'x': 21},
+     '7': 23, '8': 25, '9': 25, 'B': 24,
+     'E': 27, 'J': 13, 'L': 13, 'O': 22,
+     'X': 21, 'b': 24, 'e': 27, 'j': 13,
+     'l': 13, 'o': 22, 'x': 21},
 
-    {'.': 25, '0': 5, '1': 5, '2': 5,
+    {'.': 26, '0': 5, '1': 5, '2': 5,
      '3': 5, '4': 5, '5': 5, '6': 5,
-     '7': 5, '8': 5, '9': 5, 'E': 26,
-     'J': 13, 'L': 13, 'e': 26, 'j': 13,
+     '7': 5, '8': 5, '9': 5, 'E': 27,
+     'J': 13, 'L': 13, 'e': 27, 'j': 13,
      'l': 13},
 
-    {'0': 27, '1': 27, '2': 27, '3': 27,
-     '4': 27, '5': 27, '6': 27, '7': 27,
-     '8': 27, '9': 27},
+    {'0': 28, '1': 28, '2': 28, '3': 28,
+     '4': 28, '5': 28, '6': 28, '7': 28,
+     '8': 28, '9': 28},
 
     {'*': 12, '=': 13},
 
@@ -142,22 +142,22 @@
 
     {'\n': 13},
 
-    {automata.DEFAULT: 19, '\n': 28,
-     "'": 29, '\\': 30},
+    {automata.DEFAULT: 19, '\n': 29,
+     "'": 30, '\\': 31},
 
-    {automata.DEFAULT: 20, '\n': 28,
-     '"': 31, '\\': 32},
+    {automata.DEFAULT: 20, '\n': 29,
+     '"': 32, '\\': 33},
 
     {'\n': 13, '\r': 14},
 
-    {automata.DEFAULT: 18, '\n': 28,
-     '\r': 28},
+    {automata.DEFAULT: 18, '\n': 29,
+     '\r': 29},
 
-    {automata.DEFAULT: 19, '\n': 28,
-     "'": 13, '\\': 30},
+    {automata.DEFAULT: 19, '\n': 29,
+     "'": 13, '\\': 31},
 
-    {automata.DEFAULT: 20, '\n': 28,
-     '"': 13, '\\': 32},
+    {automata.DEFAULT: 20, '\n': 29,
+     '"': 13, '\\': 33},
 
     {'0': 21, '1': 21, '2': 21, '3': 21,
      '4': 21, '5': 21, '6': 21, '7': 21,
@@ -171,71 +171,74 @@
      '4': 22, '5': 22, '6': 22, '7': 22,
      'L': 13, 'l': 13},
 
-    {'.': 25, '0': 23, '1': 23, '2': 23,
+    {'.': 26, '0': 23, '1': 23, '2': 23,
      '3': 23, '4': 23, '5': 23, '6': 23,
-     '7': 23, '8': 24, '9': 24, 'E': 26,
-     'J': 13, 'L': 13, 'e': 26, 'j': 13,
+     '7': 23, '8': 25, '9': 25, 'E': 27,
+     'J': 13, 'L': 13, 'e': 27, 'j': 13,
      'l': 13},
 
-    {'.': 25, '0': 24, '1': 24, '2': 24,
-     '3': 24, '4': 24, '5': 24, '6': 24,
-     '7': 24, '8': 24, '9': 24, 'E': 26,
-     'J': 13, 'e': 26, 'j': 13},
-
-    {'0': 25, '1': 25, '2': 25, '3': 25,
-     '4': 25, '5': 25, '6': 25, '7': 25,
-     '8': 25, '9': 25, 'E': 33, 'J': 13,
-     'e': 33, 'j': 13},
-
-    {'+': 34, '-': 34, '0': 35, '1': 35,
-     '2': 35, '3': 35, '4': 35, '5': 35,
-     '6': 35, '7': 35, '8': 35,
-     '9': 35},
-
-    {'0': 27, '1': 27, '2': 27, '3': 27,
-     '4': 27, '5': 27, '6': 27, '7': 27,
-     '8': 27, '9': 27, 'E': 33, 'J': 13,
-     'e': 33, 'j': 13},
+    {'0': 24, '1': 24, 'L': 13,
+     'l': 13},
+
+    {'.': 26, '0': 25, '1': 25, '2': 25,
+     '3': 25, '4': 25, '5': 25, '6': 25,
+     '7': 25, '8': 25, '9': 25, 'E': 27,
+     'J': 13, 'e': 27, 'j': 13},
+
+    {'0': 26, '1': 26, '2': 26, '3': 26,
+     '4': 26, '5': 26, '6': 26, '7': 26,
+     '8': 26, '9': 26, 'E': 34, 'J': 13,
+     'e': 34, 'j': 13},
+
+    {'+': 35, '-': 35, '0': 36, '1': 36,
+     '2': 36, '3': 36, '4': 36, '5': 36,
+     '6': 36, '7': 36, '8': 36,
+     '9': 36},
+
+    {'0': 28, '1': 28, '2': 28, '3': 28,
+     '4': 28, '5': 28, '6': 28, '7': 28,
+     '8': 28, '9': 28, 'E': 34, 'J': 13,
+     'e': 34, 'j': 13},
 
     {},
 
     {"'": 13},
 
-    {automata.DEFAULT: 36, '\n': 13,
+    {automata.DEFAULT: 37, '\n': 13,
      '\r': 14},
 
     {'"': 13},
 
-    {automata.DEFAULT: 37, '\n': 13,
+    {automata.DEFAULT: 38, '\n': 13,
      '\r': 14},
 
-    {'+': 38, '-': 38, '0': 39, '1': 39,
-     '2': 39, '3': 39, '4': 39, '5': 39,
-     '6': 39, '7': 39, '8': 39,
-     '9': 39},
-
-    {'0': 35, '1': 35, '2': 35, '3': 35,
-     '4': 35, '5': 35, '6': 35, '7': 35,
-     '8': 35, '9': 35},
-
-    {'0': 35, '1': 35, '2': 35, '3': 35,
-     '4': 35, '5': 35, '6': 35, '7': 35,
-     '8': 35, '9': 35, 'J': 13,
+    {'+': 39, '-': 39, '0': 40, '1': 40,
+     '2': 40, '3': 40, '4': 40, '5': 40,
+     '6': 40, '7': 40, '8': 40,
+     '9': 40},
+
+    {'0': 36, '1': 36, '2': 36, '3': 36,
+     '4': 36, '5': 36, '6': 36, '7': 36,
+     '8': 36, '9': 36},
+
+    {'0': 36, '1': 36, '2': 36, '3': 36,
+     '4': 36, '5': 36, '6': 36, '7': 36,
+     '8': 36, '9': 36, 'J': 13,
      'j': 13},
 
-    {automata.DEFAULT: 36, '\n': 28,
-     "'": 13, '\\': 30},
+    {automata.DEFAULT: 37, '\n': 29,
+     "'": 13, '\\': 31},
 
-    {automata.DEFAULT: 37, '\n': 28,
-     '"': 13, '\\': 32},
+    {automata.DEFAULT: 38, '\n': 29,
+     '"': 13, '\\': 33},
 
-    {'0': 39, '1': 39, '2': 39, '3': 39,
-     '4': 39, '5': 39, '6': 39, '7': 39,
-     '8': 39, '9': 39},
-
-    {'0': 39, '1': 39, '2': 39, '3': 39,
-     '4': 39, '5': 39, '6': 39, '7': 39,
-     '8': 39, '9': 39, 'J': 13,
+    {'0': 40, '1': 40, '2': 40, '3': 40,
+     '4': 40, '5': 40, '6': 40, '7': 40,
+     '8': 40, '9': 40},
+
+    {'0': 40, '1': 40, '2': 40, '3': 40,
+     '4': 40, '5': 40, '6': 40, '7': 40,
+     '8': 40, '9': 40, 'J': 13,
      'j': 13},
 
     ]

Modified: pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py	Tue Oct  5 20:00:56 2010
@@ -112,4 +112,10 @@
     def test_new_octal_literal(self):
         self.parse('0777')
         self.parse('0o777')
+        self.parse('0o777L')
         py.test.raises(SyntaxError, self.parse, "0o778")
+
+    def test_new_binary_literal(self):
+        self.parse('0b1101')
+        self.parse('0b0l')
+        py.test.raises(SyntaxError, self.parse, "0b112")



More information about the Pypy-commit mailing list