summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-27 12:50:00 +0200
committerLaurenz <laurmaedje@gmail.com>2023-03-27 12:50:00 +0200
commit2c7f2c005a214e8b0c1afbe9f4dab29dead8dfb0 (patch)
treee9f07740b19730f1ab5e2a26417e7e4763d10b54
parent2bbd8040c8f0f33b8abccd9d1c1c8b8dfad16b11 (diff)
Parse decimals as a unit
Fixes #257.
-rw-r--r--src/syntax/lexer.rs4
-rw-r--r--tests/ref/math/frac.pngbin23154 -> 24948 bytes
-rw-r--r--tests/typ/math/frac.typ1
3 files changed, 5 insertions, 0 deletions
diff --git a/src/syntax/lexer.rs b/src/syntax/lexer.rs
index c46fa37b..43a4872b 100644
--- a/src/syntax/lexer.rs
+++ b/src/syntax/lexer.rs
@@ -430,6 +430,10 @@ impl Lexer<'_> {
// Keep numbers and grapheme clusters together.
if c.is_numeric() {
self.s.eat_while(char::is_numeric);
+ let mut s = self.s;
+ if s.eat_if('.') && !s.eat_while(char::is_numeric).is_empty() {
+ self.s = s;
+ }
} else {
let len = self
.s
diff --git a/tests/ref/math/frac.png b/tests/ref/math/frac.png
index fc8789b3..58d8ef89 100644
--- a/tests/ref/math/frac.png
+++ b/tests/ref/math/frac.png
Binary files differ
diff --git a/tests/typ/math/frac.typ b/tests/typ/math/frac.typ
index 2e915de2..15b5da33 100644
--- a/tests/typ/math/frac.typ
+++ b/tests/typ/math/frac.typ
@@ -27,6 +27,7 @@ $ 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 \
(a)b/2, b(a)[b]/2 $