summaryrefslogtreecommitdiff
path: root/src/syntax/ast
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-03 15:07:57 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-03 15:07:57 +0200
commit95bae5725cf6495644e2593f8492f1cd0e5bd3c1 (patch)
tree919dd90cac7623bcbbc09d9c92399eaa65e537f2 /src/syntax/ast
parent0fc25d732d7cbc37cf801645849d1060f2cec4a3 (diff)
Int, Float, Relative and Linear values 🍉
Diffstat (limited to 'src/syntax/ast')
-rw-r--r--src/syntax/ast/lit.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/syntax/ast/lit.rs b/src/syntax/ast/lit.rs
index bbdd0c81..ba7e7e4f 100644
--- a/src/syntax/ast/lit.rs
+++ b/src/syntax/ast/lit.rs
@@ -18,10 +18,15 @@ pub enum Lit {
Int(i64),
/// A floating-point literal: `1.2`, `10e-4`.
Float(f64),
- /// A percent literal: `50%`.
- Percent(f64),
/// A length literal: `12pt`, `3cm`.
Length(Length),
+ /// A percent literal: `50%`.
+ ///
+ /// Note: `50%` is represented as `50.0` here, but as `0.5` in the
+ /// corresponding [value].
+ ///
+ /// [value]: ../../eval/enum.Value.html#variant.Relative
+ Percent(f64),
/// A color literal: `#ffccee`.
Color(RgbaColor),
/// A string literal: `"hello!"`.
@@ -42,10 +47,10 @@ impl Lit {
match *self {
Lit::Ident(ref i) => Value::Ident(i.clone()),
Lit::Bool(b) => Value::Bool(b),
- Lit::Int(i) => Value::Number(i as f64),
- Lit::Float(f) => Value::Number(f as f64),
- Lit::Percent(p) => Value::Number(p as f64 / 100.0),
- Lit::Length(l) => Value::Length(l),
+ Lit::Int(i) => Value::Int(i),
+ Lit::Float(f) => Value::Float(f),
+ Lit::Length(l) => Value::Length(l.as_raw()),
+ Lit::Percent(p) => Value::Relative(p / 100.0),
Lit::Color(c) => Value::Color(c),
Lit::Str(ref s) => Value::Str(s.clone()),
Lit::Dict(ref d) => Value::Dict(d.eval(ctx, f).await),