From 9b9d279a490afe5ce7703847cc6b5d3c073ad4e5 Mon Sep 17 00:00:00 2001 From: Ian Wrzesinski Date: Thu, 27 Feb 2025 10:50:49 -0500 Subject: [PATCH] eat trailing percent signs in numbers --- crates/typst-syntax/src/lexer.rs | 6 +----- tests/ref/double-percent.png | Bin 496 -> 0 bytes tests/suite/layout/length.typ | 5 +++++ tests/suite/layout/relative.typ | 9 ++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) delete mode 100644 tests/ref/double-percent.png diff --git a/crates/typst-syntax/src/lexer.rs b/crates/typst-syntax/src/lexer.rs index a34b91add..e1b9c4999 100644 --- a/crates/typst-syntax/src/lexer.rs +++ b/crates/typst-syntax/src/lexer.rs @@ -871,11 +871,7 @@ impl Lexer<'_> { }; // Read the suffix. - let suffix_start = self.s.cursor(); - if !self.s.eat_if('%') { - self.s.eat_while(char::is_ascii_alphanumeric); - } - let suffix = self.s.from(suffix_start); + let suffix = self.s.eat_while(|c: char| c.is_ascii_alphanumeric() || c == '%'); let maybe_suffix_result = match suffix { "" => None, "pt" | "mm" | "cm" | "in" | "deg" | "rad" | "em" | "fr" | "%" => Some(Ok(())), diff --git a/tests/ref/double-percent.png b/tests/ref/double-percent.png deleted file mode 100644 index 61a0d6143cd1615b0fa0051d0442b32be6fd2491..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 496 zcmV+=2f`SbJhrlzKag@yFj3(}_~!2H?CkmK@#wC} z)^MQTk+#!kn$&BZ+=Z^zaiQj?#p$ujwY9a5j*hIXtmfwC)^eiSeW~fQ&FJXp>gwu| zk&(y8$MMbHoSdBU^75mjqwT@g;g-6}%F6cO>gu-7`||eg?(V$2yr7_<{{H@khK6)> zbh5It#KgqGDRSzy&iUx@&|Q?$VwdpA+xFh+_xJby`~2XNx8aw%>a@-K@b&-x{>PGM zX#fBKrb$FWRCwC$(?t%$KoCUHa+sN!nVFdxY~TMVk>bQRm`IWOt-g9ws|F#2{4FP1O>0000