feat(parser): desugar AugAssign statements
This commit is contained in:
@@ -64,6 +64,9 @@ class PythonParser:
|
|||||||
case ast.Assign():
|
case ast.Assign():
|
||||||
return self.parse_assign(node)
|
return self.parse_assign(node)
|
||||||
|
|
||||||
|
case ast.AugAssign():
|
||||||
|
return self.parse_aug_assign(node)
|
||||||
|
|
||||||
case ast.FunctionDef():
|
case ast.FunctionDef():
|
||||||
return self.parse_function(node)
|
return self.parse_function(node)
|
||||||
|
|
||||||
@@ -129,6 +132,21 @@ class PythonParser:
|
|||||||
value=value,
|
value=value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def parse_aug_assign(self, node: ast.AugAssign) -> AssignStmt:
|
||||||
|
location: Location = Location.from_ast(node)
|
||||||
|
target: Expr = self.parse_expr(node.target)
|
||||||
|
value: Expr = self.parse_expr(node.value)
|
||||||
|
return AssignStmt(
|
||||||
|
location=location,
|
||||||
|
targets=[target],
|
||||||
|
value=BinaryExpr(
|
||||||
|
location=location,
|
||||||
|
left=target,
|
||||||
|
operator=node.op,
|
||||||
|
right=value,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
def parse_function(self, node: ast.FunctionDef) -> Function:
|
def parse_function(self, node: ast.FunctionDef) -> Function:
|
||||||
loc: Location = Location.from_ast(node)
|
loc: Location = Location.from_ast(node)
|
||||||
match node:
|
match node:
|
||||||
|
|||||||
Reference in New Issue
Block a user