support line continuation character

This commit is contained in:
blueloveTH 2023-08-10 01:49:37 +08:00
parent d493d74cde
commit 31850d3f29
2 changed files with 38 additions and 0 deletions

View File

@ -315,6 +315,13 @@ static bool is_unicode_Lo_char(uint32_t c) {
case '[': add_token(TK("[")); return true;
case ']': add_token(TK("]")); return true;
case '@': add_token(TK("@")); return true;
case '\\': {
// line continuation character
char c = eatchar_include_newline();
if (c != '\n') SyntaxError("expected newline after line continuation character");
eat_spaces();
return true;
}
case '$': {
for(int i=TK("$goto"); i<=TK("$label"); i++){
// +1 to skip the '$'

31
tests/04_line_continue.py Normal file
View File

@ -0,0 +1,31 @@
a = 1 + 2 \
+ 3
assert a == 6
assert 1 + 2 \
+ 3 == 6
assert 1 + 2 + \
3 + \
4 == 10
assert 1 + 2 + \
3 + \
4 + 5 + 6 \
== 21
if 1 and 2 \
and 3 \
and 4 \
and 5:
assert True
else:
assert False
1 and 2 \
and 3 \
and 4
a = 1
assert a == 1