mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Parse multi-character numbers consistently in math (#5996)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
96dd67e011
commit
12699eb7f4
@ -271,11 +271,9 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SyntaxKind::Text | SyntaxKind::MathText | SyntaxKind::MathShorthand => {
|
SyntaxKind::Text | SyntaxKind::MathText | SyntaxKind::MathShorthand => {
|
||||||
continuable = !p.at(SyntaxKind::MathShorthand)
|
// `a(b)/c` parses as `(a(b))/c` if `a` is continuable.
|
||||||
&& matches!(
|
continuable = math_class(p.current_text()) == Some(MathClass::Alphabetic)
|
||||||
math_class(p.current_text()),
|
|| p.current_text().chars().all(char::is_alphabetic);
|
||||||
None | Some(MathClass::Alphabetic)
|
|
||||||
);
|
|
||||||
if !maybe_delimited(p) {
|
if !maybe_delimited(p) {
|
||||||
p.eat();
|
p.eat();
|
||||||
}
|
}
|
||||||
|
BIN
tests/ref/issue-4828-math-number-multi-char.png
Normal file
BIN
tests/ref/issue-4828-math-number-multi-char.png
Normal file
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 |
@ -37,8 +37,8 @@ $ 1/2/3 = (1/2)/3 = 1/(2/3) $
|
|||||||
// Test precedence.
|
// Test precedence.
|
||||||
$ a_1/b_2, 1/f(x), zeta(x)/2, "foo"[|x|]/2 \
|
$ a_1/b_2, 1/f(x), zeta(x)/2, "foo"[|x|]/2 \
|
||||||
1.2/3.7, 2.3^3.4 \
|
1.2/3.7, 2.3^3.4 \
|
||||||
🏳️🌈[x]/2, f [x]/2, phi [x]/2, 🏳️🌈 [x]/2 \
|
f [x]/2, phi [x]/2 \
|
||||||
+[x]/2, 1(x)/2, 2[x]/2 \
|
+[x]/2, 1(x)/2, 2[x]/2, 🏳️🌈[x]/2 \
|
||||||
(a)b/2, b(a)[b]/2 \
|
(a)b/2, b(a)[b]/2 \
|
||||||
n!/2, 5!/2, n !/2, 1/n!, 1/5! $
|
n!/2, 5!/2, n !/2, 1/n!, 1/5! $
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ $ dot \ dots \ ast \ tilde \ star $
|
|||||||
$floor(phi.alt.)$
|
$floor(phi.alt.)$
|
||||||
$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 ---
|
--- math-unclosed ---
|
||||||
// Error: 1-2 unclosed delimiter
|
// Error: 1-2 unclosed delimiter
|
||||||
$a
|
$a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user