Parse multi-character numbers consistently in math (#5996)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
Ian Wrzesinski 2025-04-02 05:30:04 -04:00 committed by GitHub
parent 96dd67e011
commit 12699eb7f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 7 deletions

View File

@ -271,11 +271,9 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
}
SyntaxKind::Text | SyntaxKind::MathText | SyntaxKind::MathShorthand => {
continuable = !p.at(SyntaxKind::MathShorthand)
&& matches!(
math_class(p.current_text()),
None | Some(MathClass::Alphabetic)
);
// `a(b)/c` parses as `(a(b))/c` if `a` is continuable.
continuable = math_class(p.current_text()) == Some(MathClass::Alphabetic)
|| p.current_text().chars().all(char::is_alphabetic);
if !maybe_delimited(p) {
p.eat();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -37,8 +37,8 @@ $ 1/2/3 = (1/2)/3 = 1/(2/3) $
// Test precedence.
$ a_1/b_2, 1/f(x), zeta(x)/2, "foo"[|x|]/2 \
1.2/3.7, 2.3^3.4 \
🏳️‍🌈[x]/2, f [x]/2, phi [x]/2, 🏳️‍🌈 [x]/2 \
+[x]/2, 1(x)/2, 2[x]/2 \
f [x]/2, phi [x]/2 \
+[x]/2, 1(x)/2, 2[x]/2, 🏳️‍🌈[x]/2 \
(a)b/2, b(a)[b]/2 \
n!/2, 5!/2, n !/2, 1/n!, 1/5! $

View File

@ -28,6 +28,10 @@ $ dot \ dots \ ast \ tilde \ star $
$floor(phi.alt.)$
$floor(phi.alt. )$
--- issue-4828-math-number-multi-char ---
// Numbers should parse the same regardless of number of characters.
$1/2(x)$ vs. $1/10(x)$
--- math-unclosed ---
// Error: 1-2 unclosed delimiter
$a