summaryrefslogtreecommitdiff
path: root/src/parse/tokens.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-08 19:12:07 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-08 19:12:07 +0200
commit5a500fb8a7c0ba4b8a59e2622c8cbafdc4ce1fe9 (patch)
tree5c22b012cf2c37a96735d6ec84ad19e852259e51 /src/parse/tokens.rs
parentc5635d8a3f45865619d66bc9e296da7d9e9efa5a (diff)
Range operator
Diffstat (limited to 'src/parse/tokens.rs')
-rw-r--r--src/parse/tokens.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs
index 522b3136..c9b7dc21 100644
--- a/src/parse/tokens.rs
+++ b/src/parse/tokens.rs
@@ -216,7 +216,7 @@ impl<'s> Tokens<'s> {
self.s.eat_assert(c);
Token::Text(&self.s.eaten_from(start))
}
- 'u' if self.s.peek_nth(1) == Some('{') => {
+ 'u' if self.s.starts_with("u{") => {
self.s.eat_assert('u');
self.s.eat_assert('{');
Token::UnicodeEscape(UnicodeEscapeToken {
@@ -366,7 +366,8 @@ impl<'s> Tokens<'s> {
self.s.eat_while(|c| c.is_ascii_digit());
// Read the fractional part if not already done.
- if c != '.' && self.s.eat_if('.') {
+ // Make sure not to confuse a range for the decimal separator.
+ if c != '.' && !self.s.starts_with("..") && self.s.eat_if('.') {
self.s.eat_while(|c| c.is_ascii_digit());
}
@@ -905,6 +906,11 @@ mod tests {
t!(Code[" /"]: format!("{}{}", s, suffix) => build(v));
}
}
+
+ // Multiple dots close the number.
+ t!(Code[" /"]: "1..2" => Int(1), Dots, Int(2));
+ t!(Code[" /"]: "1..2.3" => Int(1), Dots, Float(2.3));
+ t!(Code[" /"]: "1.2..3" => Float(1.2), Dots, Int(3));
}
#[test]