summaryrefslogtreecommitdiff
path: root/crates/typst-syntax/src/parser.rs
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2024-04-03 05:01:50 -0400
committerGitHub <noreply@github.com>2024-04-03 09:01:50 +0000
commit0619ae98a86ee5179663aad4ef0575e6b4a284cc (patch)
treefc2e86ee3b38c42503ab0d628c1dd79d9fd626ff /crates/typst-syntax/src/parser.rs
parent0b9878ed318d23e96a853ef025ea6b036673c2a8 (diff)
Fix newline parsing behavior in code mode (#3780)
Diffstat (limited to 'crates/typst-syntax/src/parser.rs')
-rw-r--r--crates/typst-syntax/src/parser.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/typst-syntax/src/parser.rs b/crates/typst-syntax/src/parser.rs
index 50032898..17f08153 100644
--- a/crates/typst-syntax/src/parser.rs
+++ b/crates/typst-syntax/src/parser.rs
@@ -1748,15 +1748,27 @@ impl<'s> Parser<'s> {
}
}
+ fn next_non_trivia(lexer: &mut Lexer<'s>) -> SyntaxKind {
+ loop {
+ let next = lexer.next();
+ // Loop is terminatable, because SyntaxKind::Eof is not a trivia.
+ if !next.is_trivia() {
+ break next;
+ }
+ }
+ }
+
fn lex(&mut self) {
self.current_start = self.lexer.cursor();
self.current = self.lexer.next();
+
+ // Special cases to handle newlines in code mode.
if self.lexer.mode() == LexMode::Code
&& self.lexer.newline()
&& match self.newline_modes.last() {
Some(NewlineMode::Continue) => false,
Some(NewlineMode::Contextual) => !matches!(
- self.lexer.clone().next(),
+ Self::next_non_trivia(&mut self.lexer.clone()),
SyntaxKind::Else | SyntaxKind::Dot
),
Some(NewlineMode::Stop) => true,