From 665b4d2aca81af48b8e0eaca4e709ef2e7825844 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 13 Dec 2019 23:59:01 +0100 Subject: =?UTF-8?q?More=20consistent=20library=20code=20and=20functions=20?= =?UTF-8?q?=F0=9F=8E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/parsing.rs | 11 ++++++++++- src/syntax/tokens.rs | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/syntax') diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index d887d898..41a8728b 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -250,7 +250,16 @@ impl<'s> Parser<'s> { } else if let Ok(size) = text.parse::() { Expression::Size(size) } else { - Expression::Ident(Ident::new(text.to_string())?) + // This loop does not actually loop, but is used for breaking. + loop { + if text.ends_with('%') { + if let Ok(percent) = text[..text.len() - 1].parse::() { + break Expression::Num(percent / 100.0); + } + } + + break Expression::Ident(Ident::new(text.to_string())?); + } } } _ => error!("expected expression"), diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs index cca8bee3..ab6bc315 100644 --- a/src/syntax/tokens.rs +++ b/src/syntax/tokens.rs @@ -1,3 +1,5 @@ +//! Tokenization of source code. + use std::str::CharIndices; use smallvec::SmallVec; -- cgit v1.2.3