mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Don't display functions
This commit is contained in:
parent
1d7e082d1d
commit
c28d2130dd
@ -179,7 +179,7 @@ impl Marginal {
|
|||||||
Self::Content(content) => Some(content.clone()),
|
Self::Content(content) => Some(content.clone()),
|
||||||
Self::Func(func, span) => {
|
Self::Func(func, span) => {
|
||||||
let args = Args::new(*span, [Value::Int(page as i64)]);
|
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())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ impl Label {
|
|||||||
Self::Content(content) => content.clone(),
|
Self::Content(content) => content.clone(),
|
||||||
Self::Func(func, span) => {
|
Self::Func(func, span) => {
|
||||||
let args = Args::new(*span, [Value::Int(number as i64)]);
|
let args = Args::new(*span, [Value::Int(number as i64)]);
|
||||||
func.call_detached(world, args)?.display(world)
|
func.call_detached(world, args)?.display()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ impl Eval for ast::MarkupNode {
|
|||||||
Self::Desc(v) => v.eval(vm)?,
|
Self::Desc(v) => v.eval(vm)?,
|
||||||
Self::Label(_) => unimplemented!("handled above"),
|
Self::Label(_) => unimplemented!("handled above"),
|
||||||
Self::Ref(v) => v.eval(vm)?,
|
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()))
|
.spanned(self.span()))
|
||||||
}
|
}
|
||||||
@ -474,7 +474,7 @@ fn eval_code(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tail = eval_code(vm, exprs)?.display(vm.world);
|
let tail = eval_code(vm, exprs)?.display();
|
||||||
Value::Content(tail.styled_with_map(styles))
|
Value::Content(tail.styled_with_map(styles))
|
||||||
}
|
}
|
||||||
ast::Expr::Show(show) => {
|
ast::Expr::Show(show) => {
|
||||||
@ -483,7 +483,7 @@ fn eval_code(
|
|||||||
break;
|
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)?)
|
Value::Content(tail.styled_with_recipe(vm.world, recipe)?)
|
||||||
}
|
}
|
||||||
_ => expr.eval(vm)?,
|
_ => expr.eval(vm)?,
|
||||||
|
@ -141,8 +141,8 @@ impl Func {
|
|||||||
impl Debug for Func {
|
impl Debug for Func {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self.name() {
|
match self.name() {
|
||||||
Some(name) => f.write_str(name),
|
Some(name) => write!(f, "<function {name}>"),
|
||||||
None => f.write_str("(..) => {..}"),
|
None => f.write_str("<function>"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ impl Transform {
|
|||||||
let point = || Tracepoint::Apply(content.name().into());
|
let point = || Tracepoint::Apply(content.name().into());
|
||||||
result = result.trace(world, point, span);
|
result = result.trace(world, point, span);
|
||||||
}
|
}
|
||||||
Ok(result?.display(world))
|
Ok(result?.display())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,12 @@ use std::fmt::{self, Debug, Formatter};
|
|||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use comemo::Tracked;
|
|
||||||
use siphasher::sip128::{Hasher128, SipHasher};
|
use siphasher::sip128::{Hasher128, SipHasher};
|
||||||
|
|
||||||
use super::{format_str, ops, Args, Array, Cast, Content, Dict, Func, Str};
|
use super::{format_str, ops, Args, Array, Cast, Content, Dict, Func, Str};
|
||||||
use crate::diag::StrResult;
|
use crate::diag::StrResult;
|
||||||
use crate::geom::{Abs, Angle, Color, Em, Fr, Length, Ratio, Rel, RgbaColor};
|
use crate::geom::{Abs, Angle, Color, Em, Fr, Length, Ratio, Rel, RgbaColor};
|
||||||
use crate::util::{format_eco, EcoString};
|
use crate::util::{format_eco, EcoString};
|
||||||
use crate::World;
|
|
||||||
|
|
||||||
/// A computational value.
|
/// A computational value.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -98,18 +96,15 @@ impl Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the display representation of the value.
|
/// Return the display representation of the value.
|
||||||
pub fn display(self, world: Tracked<dyn World>) -> Content {
|
pub fn display(self) -> Content {
|
||||||
let items = &world.config().items;
|
|
||||||
match self {
|
match self {
|
||||||
Value::None => Content::empty(),
|
Self::None => Content::empty(),
|
||||||
Value::Int(v) => (items.text)(format_eco!("{}", v)),
|
Self::Int(v) => item!(text)(format_eco!("{}", v)),
|
||||||
Value::Float(v) => (items.text)(format_eco!("{}", v)),
|
Self::Float(v) => item!(text)(format_eco!("{}", v)),
|
||||||
Value::Str(v) => (items.text)(v.into()),
|
Self::Str(v) => item!(text)(v.into()),
|
||||||
Value::Content(v) => v,
|
Self::Content(v) => v,
|
||||||
|
Self::Func(_) => Content::empty(),
|
||||||
// For values which can't be shown "naturally", we return the raw
|
_ => item!(raw)(self.repr().into(), Some("typc".into()), false),
|
||||||
// representation with typst code syntax highlighting.
|
|
||||||
v => (items.raw)(v.repr().into(), Some("typc".into()), false),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -425,7 +420,7 @@ mod tests {
|
|||||||
test(dict!["two" => false, "one" => 1], "(one: 1, two: false)");
|
test(dict!["two" => false, "one" => 1], "(one: 1, two: false)");
|
||||||
|
|
||||||
// Functions, content and dynamics.
|
// 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");
|
test(Dynamic::new(1), "1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 29 KiB |
@ -40,9 +40,9 @@
|
|||||||
#raw(repr[*{"H" + "i"} there*])
|
#raw(repr[*{"H" + "i"} there*])
|
||||||
|
|
||||||
---
|
---
|
||||||
// Functions
|
// Functions are invisible.
|
||||||
|
Nothing
|
||||||
#let f(x) = x
|
#let f(x) = x
|
||||||
|
{f}
|
||||||
{f} \
|
{rect}
|
||||||
{rect} \
|
{() => none}
|
||||||
{() => none} \
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user