summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--library/src/layout/page.rs2
-rw-r--r--library/src/structure/list.rs2
-rw-r--r--src/model/eval.rs6
-rw-r--r--src/model/func.rs4
-rw-r--r--src/model/styles.rs2
-rw-r--r--src/model/value.rs23
-rw-r--r--tests/ref/code/call.pngbin2624 -> 2337 bytes
-rw-r--r--tests/ref/code/repr.pngbin30668 -> 29799 bytes
-rw-r--r--tests/typ/code/repr.typ10
9 files changed, 22 insertions, 27 deletions
diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs
index b0e3ff6d..3901740c 100644
--- a/library/src/layout/page.rs
+++ b/library/src/layout/page.rs
@@ -179,7 +179,7 @@ impl Marginal {
Self::Content(content) => Some(content.clone()),
Self::Func(func, span) => {
let args = Args::new(*span, [Value::Int(page as i64)]);
- Some(func.call_detached(world, args)?.display(world))
+ Some(func.call_detached(world, args)?.display())
}
})
}
diff --git a/library/src/structure/list.rs b/library/src/structure/list.rs
index 3f73386c..2a3f3035 100644
--- a/library/src/structure/list.rs
+++ b/library/src/structure/list.rs
@@ -252,7 +252,7 @@ impl Label {
Self::Content(content) => content.clone(),
Self::Func(func, span) => {
let args = Args::new(*span, [Value::Int(number as i64)]);
- func.call_detached(world, args)?.display(world)
+ func.call_detached(world, args)?.display()
}
})
}
diff --git a/src/model/eval.rs b/src/model/eval.rs
index eb6b8ddb..79ad0815 100644
--- a/src/model/eval.rs
+++ b/src/model/eval.rs
@@ -183,7 +183,7 @@ impl Eval for ast::MarkupNode {
Self::Desc(v) => v.eval(vm)?,
Self::Label(_) => unimplemented!("handled above"),
Self::Ref(v) => v.eval(vm)?,
- Self::Expr(v) => v.eval(vm)?.display(vm.world),
+ Self::Expr(v) => v.eval(vm)?.display(),
}
.spanned(self.span()))
}
@@ -474,7 +474,7 @@ fn eval_code(
break;
}
- let tail = eval_code(vm, exprs)?.display(vm.world);
+ let tail = eval_code(vm, exprs)?.display();
Value::Content(tail.styled_with_map(styles))
}
ast::Expr::Show(show) => {
@@ -483,7 +483,7 @@ fn eval_code(
break;
}
- let tail = eval_code(vm, exprs)?.display(vm.world);
+ let tail = eval_code(vm, exprs)?.display();
Value::Content(tail.styled_with_recipe(vm.world, recipe)?)
}
_ => expr.eval(vm)?,
diff --git a/src/model/func.rs b/src/model/func.rs
index 21e36784..cb4f5280 100644
--- a/src/model/func.rs
+++ b/src/model/func.rs
@@ -141,8 +141,8 @@ impl Func {
impl Debug for Func {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self.name() {
- Some(name) => f.write_str(name),
- None => f.write_str("(..) => {..}"),
+ Some(name) => write!(f, "<function {name}>"),
+ None => f.write_str("<function>"),
}
}
}
diff --git a/src/model/styles.rs b/src/model/styles.rs
index 324b52f5..4195d3e1 100644
--- a/src/model/styles.rs
+++ b/src/model/styles.rs
@@ -510,7 +510,7 @@ impl Transform {
let point = || Tracepoint::Apply(content.name().into());
result = result.trace(world, point, span);
}
- Ok(result?.display(world))
+ Ok(result?.display())
}
}
}
diff --git a/src/model/value.rs b/src/model/value.rs
index 9e6968fa..aec68ca1 100644
--- a/src/model/value.rs
+++ b/src/model/value.rs
@@ -4,14 +4,12 @@ use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
use std::sync::Arc;
-use comemo::Tracked;
use siphasher::sip128::{Hasher128, SipHasher};
use super::{format_str, ops, Args, Array, Cast, Content, Dict, Func, Str};
use crate::diag::StrResult;
use crate::geom::{Abs, Angle, Color, Em, Fr, Length, Ratio, Rel, RgbaColor};
use crate::util::{format_eco, EcoString};
-use crate::World;
/// A computational value.
#[derive(Clone)]
@@ -98,18 +96,15 @@ impl Value {
}
/// Return the display representation of the value.
- pub fn display(self, world: Tracked<dyn World>) -> Content {
- let items = &world.config().items;
+ pub fn display(self) -> Content {
match self {
- Value::None => Content::empty(),
- Value::Int(v) => (items.text)(format_eco!("{}", v)),
- Value::Float(v) => (items.text)(format_eco!("{}", v)),
- Value::Str(v) => (items.text)(v.into()),
- Value::Content(v) => v,
-
- // For values which can't be shown "naturally", we return the raw
- // representation with typst code syntax highlighting.
- v => (items.raw)(v.repr().into(), Some("typc".into()), false),
+ Self::None => Content::empty(),
+ Self::Int(v) => item!(text)(format_eco!("{}", v)),
+ Self::Float(v) => item!(text)(format_eco!("{}", v)),
+ Self::Str(v) => item!(text)(v.into()),
+ Self::Content(v) => v,
+ Self::Func(_) => Content::empty(),
+ _ => item!(raw)(self.repr().into(), Some("typc".into()), false),
}
}
}
@@ -425,7 +420,7 @@ mod tests {
test(dict!["two" => false, "one" => 1], "(one: 1, two: false)");
// Functions, content and dynamics.
- test(Func::from_fn("nil", |_, _| Ok(Value::None)), "nil");
+ test(Func::from_fn("nil", |_, _| Ok(Value::None)), "<function nil>");
test(Dynamic::new(1), "1");
}
}
diff --git a/tests/ref/code/call.png b/tests/ref/code/call.png
index eaf77ad6..f0f2e852 100644
--- a/tests/ref/code/call.png
+++ b/tests/ref/code/call.png
Binary files differ
diff --git a/tests/ref/code/repr.png b/tests/ref/code/repr.png
index b8beb09a..b81083f5 100644
--- a/tests/ref/code/repr.png
+++ b/tests/ref/code/repr.png
Binary files differ
diff --git a/tests/typ/code/repr.typ b/tests/typ/code/repr.typ
index 4d7a6cd5..bdea9c82 100644
--- a/tests/typ/code/repr.typ
+++ b/tests/typ/code/repr.typ
@@ -40,9 +40,9 @@
#raw(repr[*{"H" + "i"} there*])
---
-// Functions
+// Functions are invisible.
+Nothing
#let f(x) = x
-
-{f} \
-{rect} \
-{() => none} \
+{f}
+{rect}
+{() => none}