Fix incorrect handling of blank and comment lines before 'else', 'except', etc.

This commit is contained in:
K. Lange 2022-02-17 09:49:24 +09:00
parent c1f2c7d9f3
commit e24ea3d32c
3 changed files with 35 additions and 2 deletions

View File

@ -97,9 +97,10 @@ static KrkToken makeIndentation() {
}
KrkToken out = makeToken(TOKEN_INDENTATION);
if (reject == ' ') out.length *= 8;
if (peek() == '#') {
/* Skip the entirety of the comment but not the line feed */
if (peek() == '#' || peek() == '\n') {
while (!isAtEnd() && peek() != '\n') advance();
scanner.startOfLine = 1;
return makeToken(TOKEN_RETRY);
}
return out;
}

View File

@ -0,0 +1,28 @@
if True:
if False:
print("fail")
else:
print("pass")
if True:
if False:
print("fail")
# test
else:
print("pass")
if True:
if False:
print("fail")
# test
else:
print("pass")
if True:
if False:
print("fail")
#test
else:
print("pass")

View File

@ -0,0 +1,4 @@
pass
pass
pass
pass