8000 Properly parse blank lines at the start of the document · lezer-parser/python@841ff6e · GitHub
[go: up one dir, main page]

Skip to content

Commit 841ff6e

Browse files
committed
Properly parse blank lines at the start of the document
FIX: Fix parsing of blank lines at the start of the document. Closes #14
1 parent ee33316 commit 841ff6e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/tokens.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ function isLineBreak(ch) {
2828
}
2929

3030
export const newlines = new ExternalTokenizer((input, stack) => {
31+
let prev
3132
if (input.next < 0) {
3233
input.acceptToken(eof)
3334
} else if (stack.context.depth < 0) {
3435
if (isLineBreak(input.next)) input.acceptToken(newlineBracketed, 1)
35-
} else if (isLineBreak(input.peek(-1)) && stack.canShift(blankLineStart)) {
36+
} else if (((prev = input.peek(-1)) < 0 || isLineBreak(prev)) &&
37+
stack.canShift(blankLineStart)) {
3638
let spaces = 0
3739
while (input.next == space || input.next == tab) { input.advance(); spaces++ }
3840
if (input.next == newline || input.next == carriageReturn || input.next == hash)

0 commit comments

Comments
 (0)
0