summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-09 21:35:36 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-09 21:35:36 +0100
commit3b2a28ca8edf61cb1376a095be36c7d006c92d76 (patch)
treec64cdaed32f8f45810f09ba8cfcf296971c21dff /src/parse
parent8275b186ba75b5e75a4108105c1ea3bfdbe6ada2 (diff)
Add angle data type 📐
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/tests.rs8
-rw-r--r--src/parse/tokens.rs21
2 files changed, 17 insertions, 12 deletions
diff --git a/src/parse/tests.rs b/src/parse/tests.rs
index 701d2a73..833d6661 100644
--- a/src/parse/tests.rs
+++ b/src/parse/tests.rs
@@ -5,7 +5,7 @@ use std::fmt::Debug;
use super::parse;
use crate::color::RgbaColor;
use crate::diag::{Diag, Level, Pass};
-use crate::geom::Unit;
+use crate::geom::LengthUnit;
use crate::syntax::*;
use BinOp::*;
@@ -549,7 +549,7 @@ fn test_parse_expressions() {
t!(r#"{"x"+"y"}"# Block(Binary(Str("x"), Add, Str("y"))));
t!("{1-2}" Block(Binary(Int(1), Sub, Int(2))));
t!("{a * b}" Block(Binary(Id("a"), Mul, Id("b"))));
- t!("{12pt/.4}" Block(Binary(Length(12.0, Unit::Pt), Div, Float(0.4))));
+ t!("{12pt/.4}" Block(Binary(Length(12.0, LengthUnit::Pt), Div, Float(0.4))));
// Associativity.
t!("{1+2+3}" Block(Binary(Binary(Int(1), Add, Int(2)), Add, Int(3))));
@@ -593,8 +593,8 @@ fn test_parse_values() {
t!("{1.0e-4}" Block(Float(1e-4)));
t!("{3.15}" Block(Float(3.15)));
t!("{50%}" Block(Percent(50.0)));
- t!("{4.5cm}" Block(Length(4.5, Unit::Cm)));
- t!("{12e1pt}" Block(Length(12e1, Unit::Pt)));
+ t!("{4.5cm}" Block(Length(4.5, LengthUnit::Cm)));
+ t!("{12e1pt}" Block(Length(12e1, LengthUnit::Pt)));
// Strings.
t!(r#"{"hi"}"# Block(Str("hi")));
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs
index 77c39a4c..1e49d1c6 100644
--- a/src/parse/tokens.rs
+++ b/src/parse/tokens.rs
@@ -1,7 +1,7 @@
use std::fmt::{self, Debug, Formatter};
use super::{is_newline, Scanner};
-use crate::geom::Unit;
+use crate::geom::LengthUnit;
use crate::syntax::*;
use TokenMode::*;
@@ -349,7 +349,7 @@ fn parse_percent(string: &str) -> Option<f64> {
string.strip_suffix('%').and_then(|prefix| prefix.parse::<f64>().ok())
}
-fn parse_length(string: &str) -> Option<(f64, Unit)> {
+fn parse_length(string: &str) -> Option<(f64, LengthUnit)> {
let len = string.len();
// We need at least some number and the unit.
@@ -362,10 +362,10 @@ fn parse_length(string: &str) -> Option<(f64, Unit)> {
let split = len - 2;
let bytes = string.as_bytes();
let unit = match &bytes[split ..] {
- b"pt" => Unit::Pt,
- b"mm" => Unit::Mm,
- b"cm" => Unit::Cm,
- b"in" => Unit::In,
+ b"pt" => LengthUnit::Pt,
+ b"mm" => LengthUnit::Mm,
+ b"cm" => LengthUnit::Cm,
+ b"in" => LengthUnit::In,
_ => return None,
};
@@ -378,9 +378,9 @@ mod tests {
use super::*;
use crate::parse::tests::check;
+ use LengthUnit::*;
use Option::None;
use Token::{Ident, *};
- use Unit::*;
fn Raw(text: &str, backticks: usize, terminated: bool) -> Token {
Token::Raw(TokenRaw { text, backticks, terminated })
@@ -737,7 +737,12 @@ mod tests {
}
// Test lengths.
- for &unit in &[Unit::Mm, Unit::Pt, Unit::Cm, Unit::In] {
+ for &unit in &[
+ LengthUnit::Mm,
+ LengthUnit::Pt,
+ LengthUnit::Cm,
+ LengthUnit::In,
+ ] {
for (s, v) in nums.clone() {
t!(Header[" /"]: format!("{}{}", s, unit) => Length(v, unit));
}