From 65dc277fc5cd4603653e71905a004d63248fcb6c Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:39:38 -0300 Subject: [PATCH] minor decorator lexing improvements --- crates/typst-syntax/src/lexer.rs | 6 +++--- tests/suite/syntax/decorator.typ | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/typst-syntax/src/lexer.rs b/crates/typst-syntax/src/lexer.rs index 9bfc64cb4..ac6de18cb 100644 --- a/crates/typst-syntax/src/lexer.rs +++ b/crates/typst-syntax/src/lexer.rs @@ -265,7 +265,7 @@ impl Lexer<'_> { let mut current_start = self.s.cursor(); let mut expecting_comma = false; let mut finished = false; - while !self.s.peek().is_some_and(is_newline) { + while !self.s.at(is_newline) { let token = match self.s.eat() { Some(c) if c.is_whitespace() => { self.s.eat_while(is_inline_whitespace); @@ -277,10 +277,10 @@ impl Lexer<'_> { // After we finished specifying arguments, there must only // be whitespaces until the line ends. self.s.eat_until(char::is_whitespace); - self.error("expected whitespace") + self.error("expected end of decorator") } Some('"') if expecting_comma => { - self.s.eat_until(|c| c == ',' || is_newline(c)); + self.s.eat_until(|c| c == ',' || c == ')' || is_newline(c)); self.error("expected comma") } Some('"') => { diff --git a/tests/suite/syntax/decorator.typ b/tests/suite/syntax/decorator.typ index d9de2b636..fa503089b 100644 --- a/tests/suite/syntax/decorator.typ +++ b/tests/suite/syntax/decorator.typ @@ -57,11 +57,11 @@ this is ok // Error: 14 expected closing paren /! allow("abc -// Error: 17-20 expected whitespace +// Error: 17-20 expected end of decorator /! allow("abc") abc -// Error: 16-26 expected comma -// Error: 26 expected closing paren +// Error: 16-21 expected comma +// Error: 23-26 expected end of decorator /! allow("abc" "abc") abc // Error: 16-21 expected comma