Skip to content

Commit

Permalink
Fix issues with assignments not formatting like value decls
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Sep 21, 2023
1 parent 61e33aa commit 2a1d8a2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/odin/printer/visit.odin
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,24 @@ is_value_decl_statement_ending_with_call :: proc(stmt: ^ast.Stmt) -> bool {
return false
}

@(private)
is_assign_statement_ending_with_call :: proc(stmt: ^ast.Stmt) -> bool {
if assign_stmt, ok := stmt.derived.(^ast.Assign_Stmt); ok {
if len(assign_stmt.rhs) == 0 {
return false
}

#partial switch v in
assign_stmt.rhs[len(assign_stmt.rhs) - 1].derived {
case ^ast.Call_Expr, ^ast.Selector_Call_Expr:
fmt.println("TRUE")
return true
}
}

return false
}

@(private)
is_value_expression_call :: proc(expr: ^ast.Expr) -> bool {
#partial switch v in expr.derived {
Expand Down Expand Up @@ -1041,6 +1059,7 @@ visit_stmt :: proc(


if v.init != nil && is_value_decl_statement_ending_with_call(v.init) ||
v.init != nil && is_assign_statement_ending_with_call(v.init) ||
v.cond != nil && v.init == nil && is_value_expression_call(v.cond) {
document = cons(
document,
Expand Down

0 comments on commit 2a1d8a2

Please sign in to comment.