eat trailing percent signs in numbers

This commit is contained in:
Ian Wrzesinski 2025-02-27 10:50:49 -05:00
parent dc54bf43ad
commit 9b9d279a49
4 changed files with 12 additions and 8 deletions

View File

@ -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(())),

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 B

View File

@ -107,7 +107,12 @@
#1.2e-0%
#0.0e0deg
#0.%
// Error: 2-6 invalid number suffix: in%
// Hint: 2-6 try adding a space after: `in`
#5in%
// Error: 2-6 invalid number suffix: %in
// Hint: 2-6 try adding a space after: `%`
#5%in
// Error: 2-8 invalid number suffix: hello
#1hello
// Error: 2-7 invalid number suffix: infr

View File

@ -6,10 +6,13 @@
#test((100% + 2pt - 2pt).length, 0pt)
#test((56% + 2pt - 56%).ratio, 0%)
--- double-percent ---
--- double-percent-embedded ---
// Test for two percent signs in a row.
// Error: 2-7 invalid number suffix: %%
// Hint: 2-7 try adding a space after: `%`
#3.1%%
--- double-percent-error ---
// Error: 7-8 the character `%` is not valid in code
--- double-percent-parens ---
// Error: 3-8 invalid number suffix: %%
// Hint: 3-8 try adding a space after: `%`
#(3.1%%)