Commits

Victor Kotseruba committed a1c5648

||= support

Comments (0)

Files changed (1)

         return func_def
     
     
+    def _globals_locals(self):
+        return self.ast.Call(func=self.ast.Name(id='dict', ctx=Load()),
+                             args=[self.ast.Call(func=self.ast.Name(id='globals', ctx=Load()),
+                                                 args=[], keywords=[], starargs=None, kwargs=None)],
+                             kwargs=self.ast.Call(func=self.ast.Name(id='locals', ctx=Load()),
+                                                  args=[], keywords=[], starargs=None, kwargs=None),
+                             keywords=[], starargs=None)
+    
+    
     def handle_var(self, data):
         data = _convert_s(data)
-        self._push(ast.parse(data).body[0])
+        _or = False
+        if '||=' in data:
+            _or = True
+            data = data.replace('||=', '=')
+        expr = ast.parse(data).body[0]
+        if _or:
+            """Compare(left=Num(n=1), ops=[In()], comparators=[Num(n=1)])"""
+            test = self.ast.If(test=self.ast.Compare(left=self.ast.Str(expr.targets[0].id),
+                                                     ops=[self.ast.NotIn()],
+                                                     comparators=[self._globals_locals()]),
+                               body=[expr], orelse=[])
+            self._push(test)
+        else:
+            self._push(expr)
+
     
     
     def convert_def_call(self, data):