]> 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 7f1c5648e2640499cdcb5eb25c1aec4a8cabec0a..b4481d1891a2c3acd523fd0bb2667faac09fe84c 100644 (file)
@@ -149,6 +149,7 @@ opmap_raw = """
 { LBRACE
 } RBRACE
 @ AT
+@= ATEQUAL
 == EQEQUAL
 != NOTEQUAL
 <> NOTEQUAL
index 6a6d0b6b65022f0d6dbbd6f5c3724906f63032f4..7599396611b232af2bd1ba60f4f6823f8161184f 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 1bb931e9db3127d35ac0f2cee15d839f57e996d6..3dd1ee99680a162a4f6d288d9359539acb10d160 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 a383a14e30edb64db898a9b95f4877d75412c425..83682b7dc5398027764a8f635e712e00a2a83fa5 100644 (file)
@@ -48,6 +48,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 25ee8d6f6b9ec49e309b03e3eae4cfef811b4997..9e49e0694204ebd1a6ba8f935cf7b455de85a651 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -168,6 +168,8 @@ Tests
 Tools/Demos
 -----------
 
+- Add support for the PEP 465 matrix multiplication operator to 2to3.
+
 - Issue #16047: Fix module exception list and __file__ handling in freeze.
   Patch by Meador Inge.