Skip to content

Commit 10dda12

Browse files
Always emit non-logical newlines for 'empty' lines (#27)
1 parent 27e3873 commit 10dda12

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

parser/src/lexer.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ where
641641
}
642642
Some('\n' | '\r') => {
643643
// Empty line!
644+
let tok_start = self.get_pos();
644645
self.next_char();
646+
let tok_end = self.get_pos();
647+
self.emit((Tok::NonLogicalNewline, TextRange::new(tok_start, tok_end)));
645648
spaces = 0;
646649
tabs = 0;
647650
}
@@ -1139,7 +1142,7 @@ where
11391142
return Err(LexicalError {
11401143
error: LexicalErrorType::LineContinuationError,
11411144
location: self.get_pos(),
1142-
})
1145+
});
11431146
}
11441147
}
11451148

@@ -1521,6 +1524,7 @@ mod tests {
15211524
Tok::Return,
15221525
Tok::Int { value: BigInt::from(99) },
15231526
Tok::Newline,
1527+
Tok::NonLogicalNewline,
15241528
Tok::Dedent,
15251529
]
15261530
);
@@ -1560,10 +1564,12 @@ mod tests {
15601564
},
15611565
Tok::Colon,
15621566
Tok::Newline,
1567+
Tok::NonLogicalNewline,
15631568
Tok::Indent,
15641569
Tok::Return,
15651570
Tok::Int { value: BigInt::from(99) },
15661571
Tok::Newline,
1572+
Tok::NonLogicalNewline,
15671573
Tok::Dedent,
15681574
Tok::Dedent,
15691575
]
@@ -1598,10 +1604,12 @@ mod tests {
15981604
},
15991605
Tok::Colon,
16001606
Tok::Newline,
1607+
Tok::NonLogicalNewline,
16011608
Tok::Indent,
16021609
Tok::Return,
16031610
Tok::Int { value: BigInt::from(99) },
16041611
Tok::Newline,
1612+
Tok::NonLogicalNewline,
16051613
Tok::Dedent,
16061614
Tok::Dedent,
16071615
]
@@ -1722,15 +1730,15 @@ mod tests {
17221730
#[test]
17231731
#[cfg(feature = "full-lexer")]
17241732
fn test_logical_newline_line_comment() {
1725-
let source = "#Hello\n#World";
1733+
let source = "#Hello\n#World\n";
17261734
let tokens = lex_source(source);
17271735
assert_eq!(
17281736
tokens,
17291737
vec![
17301738
Tok::Comment("#Hello".to_owned()),
1731-
// tokenize.py does put an NL here...
1739+
Tok::NonLogicalNewline,
17321740
Tok::Comment("#World".to_owned()),
1733-
// ... and here, but doesn't seem very useful.
1741+
Tok::NonLogicalNewline,
17341742
]
17351743
);
17361744
}

0 commit comments

Comments
 (0)