Skip to content

Commit

Permalink
fix: Fixed line continuation, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
alinalihassan committed Mar 14, 2022
1 parent 7c908f0 commit 9f70bb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Frontend/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ Token Lexer::ScanOne(bool continuation) {
if (c != '\n')
Error(fmt::format("Newline expected after line continuation, found {}", c));

// Newline should be parsed next
Fallback();
loc.Line++;
loc.Col = 1;

return ScanOne(continuation);
case ' ':
case '\r':
Expand Down Expand Up @@ -166,10 +167,12 @@ bool Lexer::HandleIndentation(bool continuation) {
int col = 0, alt_col = 0;
char c = 0;
int changes = 0;
bool advanced = false;
for (;;) {
if (IsAtEnd())
break;
c = Advance();
advanced = true;
if (c == ' ') {
++col;
++alt_col;
Expand All @@ -180,7 +183,7 @@ bool Lexer::HandleIndentation(bool continuation) {
break;
}
}
if (!IsAtEnd())
if (!IsAtEnd() || advanced)
Fallback();

if (continuation || level_ != 0 || c == '#' || c == '\n' || c == '\r') {
Expand Down
10 changes: 10 additions & 0 deletions tests/lesma/line_continuation.les
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ret=101
def extern exit(x: int)

let x = \ # Hello world
100 + \
1

exit(
x
)

0 comments on commit 9f70bb2

Please sign in to comment.