summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/expr.rs6
-rw-r--r--src/syntax/token.rs4
2 files changed, 7 insertions, 3 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs
index 78f4feee..268e6209 100644
--- a/src/syntax/expr.rs
+++ b/src/syntax/expr.rs
@@ -1,6 +1,6 @@
use super::*;
use crate::color::RgbaColor;
-use crate::geom::LengthUnit;
+use crate::geom::{AngularUnit, LengthUnit};
/// An expression.
#[derive(Debug, Clone, PartialEq)]
@@ -17,6 +17,8 @@ pub enum Expr {
Float(f64),
/// A length literal: `12pt`, `3cm`.
Length(f64, LengthUnit),
+ /// An angle literal: `1.5rad`, `90deg`.
+ Angle(f64, AngularUnit),
/// A percent literal: `50%`.
///
/// _Note_: `50%` is stored as `50.0` here, but as `0.5` in the
@@ -49,6 +51,7 @@ impl Pretty for Expr {
Self::Int(v) => write!(p, "{}", v).unwrap(),
Self::Float(v) => write!(p, "{}", v).unwrap(),
Self::Length(v, u) => write!(p, "{}{}", v, u).unwrap(),
+ Self::Angle(v, u) => write!(p, "{}{}", v, u).unwrap(),
Self::Percent(v) => write!(p, "{}%", v).unwrap(),
Self::Color(v) => write!(p, "{}", v).unwrap(),
Self::Str(s) => write!(p, "{:?}", &s).unwrap(),
@@ -331,6 +334,7 @@ mod tests {
test_pretty("{2.50}", "{2.5}");
test_pretty("{1e2}", "{100}");
test_pretty("{12pt}", "{12pt}");
+ test_pretty("{90.0deg}", "{90deg}");
test_pretty("{50%}", "{50%}");
test_pretty("{#fff}", "{#ffffff}");
test_pretty(r#"{"hi\n"}"#, r#"{"hi\n"}"#);
diff --git a/src/syntax/token.rs b/src/syntax/token.rs
index 261f2104..7055d61a 100644
--- a/src/syntax/token.rs
+++ b/src/syntax/token.rs
@@ -117,13 +117,13 @@ pub enum Token<'s> {
Float(f64),
/// A length: `12pt`, `3cm`.
Length(f64, LengthUnit),
+ /// An angle: `90deg`.
+ Angle(f64, AngularUnit),
/// A percentage: `50%`.
///
/// _Note_: `50%` is stored as `50.0` here, as in the corresponding
/// [literal](super::Expr::Percent).
Percent(f64),
- /// An angle: `90deg`.
- Angle(f64, AngularUnit),
/// A hex value: `#20d82a`.
Hex(&'s str),
/// A quoted string: `"..."`.