summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/mod.rs4
-rw-r--r--src/eval/ops.rs3
-rw-r--r--src/eval/raw.rs2
-rw-r--r--src/eval/value.rs23
4 files changed, 26 insertions, 6 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index bb9eb2fb..5542de89 100644
--- a/src/eval/mod.rs
+++ b/src/eval/mod.rs
@@ -101,9 +101,9 @@ impl Eval for MarkupNode {
Ok(match self {
Self::Space => Content::Space,
Self::Parbreak => Content::Parbreak,
- Self::Linebreak(justified) => Content::Linebreak(*justified),
+ &Self::Linebreak { justified } => Content::Linebreak { justified },
Self::Text(text) => Content::Text(text.clone()),
- Self::Quote(double) => Content::Quote(*double),
+ &Self::Quote { double } => Content::Quote { double },
Self::Strong(strong) => strong.eval(ctx, scp)?,
Self::Emph(emph) => emph.eval(ctx, scp)?,
Self::Raw(raw) => raw.eval(ctx, scp)?,
diff --git a/src/eval/ops.rs b/src/eval/ops.rs
index 832bd354..56bfdf2e 100644
--- a/src/eval/ops.rs
+++ b/src/eval/ops.rs
@@ -316,9 +316,10 @@ pub fn compare(lhs: &Value, rhs: &Value) -> Option<Ordering> {
(Bool(a), Bool(b)) => a.partial_cmp(b),
(Int(a), Int(b)) => a.partial_cmp(b),
(Float(a), Float(b)) => a.partial_cmp(b),
- (Angle(a), Angle(b)) => a.partial_cmp(b),
(Length(a), Length(b)) => a.partial_cmp(b),
+ (Angle(a), Angle(b)) => a.partial_cmp(b),
(Ratio(a), Ratio(b)) => a.partial_cmp(b),
+ (Relative(a), Relative(b)) => a.partial_cmp(b),
(Fraction(a), Fraction(b)) => a.partial_cmp(b),
(Str(a), Str(b)) => a.partial_cmp(b),
diff --git a/src/eval/raw.rs b/src/eval/raw.rs
index 2d82fca8..6545ea5a 100644
--- a/src/eval/raw.rs
+++ b/src/eval/raw.rs
@@ -213,6 +213,8 @@ impl PartialOrd for RawLength {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.em.is_zero() && other.em.is_zero() {
self.length.partial_cmp(&other.length)
+ } else if self.length.is_zero() && other.length.is_zero() {
+ self.em.partial_cmp(&other.em)
} else {
None
}
diff --git a/src/eval/value.rs b/src/eval/value.rs
index 31287fa8..6ce815a4 100644
--- a/src/eval/value.rs
+++ b/src/eval/value.rs
@@ -408,12 +408,25 @@ macro_rules! dynamic {
/// Make a type castable from a value.
macro_rules! castable {
+ ($type:ty: $inner:ty) => {
+ impl $crate::eval::Cast<$crate::eval::Value> for $type {
+ fn is(value: &$crate::eval::Value) -> bool {
+ <$inner>::is(value)
+ }
+
+ fn cast(value: $crate::eval::Value) -> $crate::diag::StrResult<Self> {
+ <$inner>::cast(value).map(Self)
+ }
+ }
+ };
+
(
$type:ty,
Expected: $expected:expr,
$($pattern:pat => $out:expr,)*
$(@$dyn_in:ident: $dyn_type:ty => $dyn_out:expr,)*
) => {
+ #[allow(unreachable_patterns)]
impl $crate::eval::Cast<$crate::eval::Value> for $type {
fn is(value: &$crate::eval::Value) -> bool {
#[allow(unused_variables)]
@@ -602,10 +615,14 @@ castable! {
castable! {
NonZeroUsize,
Expected: "positive integer",
- Value::Int(int) => Value::Int(int)
- .cast::<usize>()?
+ Value::Int(int) => int
.try_into()
- .map_err(|_| "must be positive")?,
+ .and_then(|int: usize| int.try_into())
+ .map_err(|_| if int <= 0 {
+ "must be positive"
+ } else {
+ "number too large"
+ })?,
}
castable! {