]> granicus.if.org Git - python/commitdiff
add matrix multiplication operator support to 2to3
authorBenjamin Peterson <benjamin@python.org>
Thu, 10 Apr 2014 04:12:47 +0000 (00:12 -0400)
committerBenjamin Peterson <benjamin@python.org>
Thu, 10 Apr 2014 04:12:47 +0000 (00:12 -0400)
Lib/lib2to3/Grammar.txt
Lib/lib2to3/pgen2/grammar.py
Lib/lib2to3/pgen2/token.py
Lib/lib2to3/pgen2/tokenize.py
Lib/lib2to3/tests/test_parser.py
Misc/NEWS

index 1e1f24cfbc7601ac57c570ad5036d977dc8af43e..bc084e97901f0aee582dd7436a583850c842e96f 100644 (file)
@@ -56,7 +56,7 @@ small_stmt: (expr_stmt | print_stmt  | del_stmt | pass_stmt | flow_stmt |
 expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
                      ('=' (yield_expr|testlist_star_expr))*)
 testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
-augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
+augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
             '<<=' | '>>=' | '**=' | '//=')
 # For normal assignments, additional restrictions enforced by the interpreter
 print_stmt: 'print' ( [ test (',' test)* [','] ] |
@@ -119,7 +119,7 @@ xor_expr: and_expr ('^' and_expr)*
 and_expr: shift_expr ('&' shift_expr)*
 shift_expr: arith_expr (('<<'|'>>') arith_expr)*
 arith_expr: term (('+'|'-') term)*
-term: factor (('*'|'/'|'%'|'//') factor)*
+term: factor (('*'|'@'|'/'|'%'|'//') factor)*
 factor: ('+'|'-'|'~') factor | power
 power: atom trailer* ['**' factor]
 atom: ('(' [yield_expr|testlist_gexp] ')' |
index 1aa5c4327803883c4a27f23eb6b64657856f9b64..8220b0aa5e14134ee31b1fa1be1bf77c08200af5 100644 (file)
@@ -151,6 +151,7 @@ opmap_raw = """
 { LBRACE
 } RBRACE
 @ AT
+@= ATEQUAL
 == EQEQUAL
 != NOTEQUAL
 <> NOTEQUAL
index 61468b313e7d0b60d4dd9f2d9522de4ee794f13a..5fac5ce3e6da73692c01967c22f50605914817b2 100755 (executable)
@@ -57,12 +57,13 @@ DOUBLESTAREQUAL = 47
 DOUBLESLASH = 48
 DOUBLESLASHEQUAL = 49
 AT = 50
-OP = 51
-COMMENT = 52
-NL = 53
-RARROW = 54
-ERRORTOKEN = 55
-N_TOKENS = 56
+ATEQUAL = 51
+OP = 52
+COMMENT = 53
+NL = 54
+RARROW = 55
+ERRORTOKEN = 56
+N_TOKENS = 57
 NT_OFFSET = 256
 #--end constants--
 
index a2ba96d78e3ce8b5dbf836595b270ac8e32c1842..4cb2a41262edf692ddef9d626cccb6458b46ae4d 100644 (file)
@@ -84,7 +84,7 @@ String = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'",
 # recognized as two instances of =).
 Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"<>", r"!=",
                  r"//=?", r"->",
-                 r"[+\-*/%&|^=<>]=?",
+                 r"[+\-*/%&@|^=<>]=?",
                  r"~")
 
 Bracket = '[][(){}]'
index 9626693acc9ce579af374f5b497cf56bdb296d5b..2e5af45399a6757349109789a633604d090ae492 100644 (file)
@@ -44,6 +44,12 @@ class GrammarTest(support.TestCase):
             raise AssertionError("Syntax shouldn't have been valid")
 
 
+class TestMatrixMultiplication(GrammarTest):
+    def test_matrix_multiplication_operator(self):
+        self.validate("a @ b")
+        self.validate("a @= b")
+
+
 class TestRaiseChanges(GrammarTest):
     def test_2x_style_1(self):
         self.validate("raise")
index 873c7b6a5d3abff39e93975167a93bd5f29c8e6e..fb06c015ba4510a3b102460722d70be697a0913b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -266,6 +266,8 @@ Library
 Tools/Demos
 -----------
 
+- Add support for the PEP 465 matrix multiplication operator to 2to3.
+
 - Issue #19936: Added executable bits or shebang lines to Python scripts which
   requires them.  Disable executable bits and shebang lines in test and
   benchmark files in order to prevent using a random system python, and in