diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-12-13 23:59:01 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-12-13 23:59:01 +0100 |
| commit | 665b4d2aca81af48b8e0eaca4e709ef2e7825844 (patch) | |
| tree | 4ada33f607455f14b6a170fe4b7fbe173056567b /src/syntax | |
| parent | 971ff3a2dcff1e68bf7e19017113469aad5a30c2 (diff) | |
More consistent library code and functions 🎄
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/parsing.rs | 11 | ||||
| -rw-r--r-- | src/syntax/tokens.rs | 2 |
2 files changed, 12 insertions, 1 deletions
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::<Size>() { 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::<f64>() { + 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; |
