Skip to content

Commit

Permalink
Fix while assignments tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
boozec committed Jul 13, 2024
1 parent e03777b commit 67687d9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
7 changes: 1 addition & 6 deletions progs/test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
n = int(input())
x = int(input())
y = int(input())
m = 1

if x == 10:
x = 1
while n > 2 * x - 3 * y + 5:
while n > 1:
tmp = 2 * x
m = m * tmp
n = n - 1

print(m + tmp)
6 changes: 6 additions & 0 deletions src/ast/Python3VisitorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ public Node visitWhile_stmt(While_stmtContext ctx) {
return whileStmt;
}

rewriter.insertAfter(ctx.COLON(0).getSymbol().getTokenIndex(), "\n");

int lineStart = ctx.getStart().getLine();
int lineStop = ctx.getStop().getLine();
int index = ctx.getStart().getTokenIndex();
Expand Down Expand Up @@ -429,6 +431,10 @@ private void optimizeBlock(BlockNode block, int lineStart, int lineStop, int ind
// int lastToken = ctx.expr().expr(counter).getStop().getTokenIndex();
// int firstToken = ctx.expr().expr(counter).getStart().getTokenIndex();
// rewriter.replace(firstToken, lastToken, newVar);
System.out.println("1 " + assignment.toPrint(""));
} else {

rewriter.insertBefore(assignment.getLhrIndex(), "\t");
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/2a.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
n = 1
x = 2
y = 3
n = int(input())
x = int(input())
m = 1
while n < (2 * x - 3 * y + 5):
m = m + n
n = n + 1

print(m)
tmp = 0
while n > 1:
m = m * tmp
tmp = 2 * x
n = n - 1
print(m + tmp)
9 changes: 9 additions & 0 deletions test/2b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
n = 1
x = 2
y = 3
m = 1
while n < 2 * x - 3 * y + 5:
m = m + n
n = n + 1

print(m)

0 comments on commit 67687d9

Please sign in to comment.