unary minus is at end not in front
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 18:44:48 +0000 (19:44 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 18:44:48 +0000 (19:44 +0100)
src/soc/decoder/pseudo/parser.py

index ff66e01a844c80c2dff2358bfe19c4a581bd3a70..68551b5cddc1a4dd3c7fb09084c6e17c0e906f4b 100644 (file)
@@ -346,7 +346,7 @@ class PowerParser:
                       | comparison BITOR comparison
                       | comparison BITAND comparison
                       | PLUS comparison
-                      | MINUS comparison
+                      | comparison MINUS
                       | INVERT comparison
                       | comparison APPEND comparison
                       | power"""
@@ -364,7 +364,10 @@ class PowerParser:
             else:
                 p[0] = ast.BinOp(p[1], binary_ops[p[2]], p[3])
         elif len(p) == 3:
-            p[0] = ast.UnaryOp(unary_ops[p[1]], p[2])
+            if isinstance(p[2], str) and p[2] == '-':
+                p[0] = ast.UnaryOp(unary_ops[p[2]], p[1])
+            else:
+                p[0] = ast.UnaryOp(unary_ops[p[1]], p[2])
         else:
             p[0] = p[1]