Fix a bad indentation handling for if/try.

This commit is contained in:
K. Lange 2021-01-17 16:52:38 +09:00
parent fe737255ba
commit f97d8cd562
3 changed files with 31 additions and 7 deletions

View File

@ -1282,14 +1282,14 @@ static void ifStatement() {
block(blockWidth,"else"); block(blockWidth,"else");
endScope(); endScope();
} }
} else { } else if (!check(TOKEN_EOF) && !check(TOKEN_EOL)) {
if (!check(TOKEN_EOF) && !check(TOKEN_EOL)) { krk_ungetToken(parser.current);
krk_ungetToken(parser.current); parser.current = parser.previous;
parser.current = parser.previous; if (blockWidth) {
if (blockWidth) { parser.previous = previous;
parser.previous = previous;
}
} }
} else {
advance(); /* Ignore this blank indentation line */
} }
} }
@ -1519,6 +1519,8 @@ static void tryStatement() {
if (blockWidth) { if (blockWidth) {
parser.previous = previous; parser.previous = previous;
} }
} else {
advance(); /* Ignore this blank indentation line */
} }
} }

View File

@ -0,0 +1,17 @@
def test(val):
if val:
print("In if")
# Comment
# val -= int(val / max) * max
return val
print("Result:", test(True))
print("result:", test(False))
def test2(val):
try:
print("This has a comment on the next line.", val)
# That could have been an else.
return val
print("Result:", test2(True))

View File

@ -0,0 +1,5 @@
In if
Result: True
result: False
This has a comment on the next line. True
Result: True