diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-13 16:27:44 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-13 16:27:44 +0200 |
| commit | 05c27a581ece00e27c16be3d9ac69f3eefedcd4b (patch) | |
| tree | ddd1dfb9598d0b629ce90bb963d194dceb0b4b97 | |
| parent | 11f1f0818b990be1ed4a16652b7f30bf11159237 (diff) | |
Automatically display value in more places
| -rw-r--r-- | src/eval/mod.rs | 16 | ||||
| -rw-r--r-- | src/library/layout/page.rs | 2 | ||||
| -rw-r--r-- | src/library/structure/list.rs | 2 | ||||
| -rw-r--r-- | src/model/recipe.rs | 4 | ||||
| -rw-r--r-- | tests/ref/structure/enum.png | bin | 25686 -> 28037 bytes | |||
| -rw-r--r-- | tests/ref/style/show-node.png | bin | 22014 -> 23385 bytes | |||
| -rw-r--r-- | tests/ref/style/wrap.png | bin | 24733 -> 24846 bytes | |||
| -rw-r--r-- | tests/typ/structure/enum.typ | 10 | ||||
| -rw-r--r-- | tests/typ/style/show-node.typ | 1 | ||||
| -rw-r--r-- | tests/typ/style/wrap.typ | 2 |
10 files changed, 14 insertions, 23 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs index db50ee82..d39c3c2c 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -354,7 +354,7 @@ fn eval_code( break; } - let tail = to_content(eval_code(ctx, scp, exprs)?).at(span)?; + let tail = eval_code(ctx, scp, exprs)?.display(); Value::Content(tail.styled_with_map(styles)) } Expr::Show(show) => { @@ -364,12 +364,12 @@ fn eval_code( break; } - let tail = to_content(eval_code(ctx, scp, exprs)?).at(span)?; + let tail = eval_code(ctx, scp, exprs)?.display(); Value::Content(tail.styled_with_entry(entry)) } Expr::Wrap(wrap) => { - let tail = to_content(eval_code(ctx, scp, exprs)?).at(span)?; - scp.top.def_mut(wrap.binding().take(), Value::Content(tail)); + let tail = eval_code(ctx, scp, exprs)?; + scp.top.def_mut(wrap.binding().take(), tail); wrap.body().eval(ctx, scp)? } @@ -386,14 +386,6 @@ fn eval_code( Ok(output) } -/// Extract content from a value. -fn to_content(value: Value) -> StrResult<Content> { - let ty = value.type_name(); - value - .cast() - .map_err(|_| format!("expected remaining block to yield content, found {ty}")) -} - impl Eval for ContentBlock { type Output = Content; diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs index 324ac285..ed9a03a4 100644 --- a/src/library/layout/page.rs +++ b/src/library/layout/page.rs @@ -159,7 +159,7 @@ impl Marginal { Self::Content(content) => Some(content.clone()), Self::Func(func, span) => { let args = Args::from_values(*span, [Value::Int(page as i64)]); - func.call(ctx, args)?.cast().at(*span)? + Some(func.call(ctx, args)?.display()) } }) } diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs index 6bcc9f3e..7686a3f4 100644 --- a/src/library/structure/list.rs +++ b/src/library/structure/list.rs @@ -217,7 +217,7 @@ impl Label { Self::Content(content) => content.clone(), Self::Func(func, span) => { let args = Args::from_values(*span, [Value::Int(number as i64)]); - func.call(ctx, args)?.cast().at(*span)? + func.call(ctx, args)?.display() } }) } diff --git a/src/model/recipe.rs b/src/model/recipe.rs index 905e035e..3404a384 100644 --- a/src/model/recipe.rs +++ b/src/model/recipe.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Debug, Formatter}; use super::{Content, Interruption, NodeId, Show, ShowNode, StyleChain, StyleEntry}; -use crate::diag::{At, TypResult}; +use crate::diag::TypResult; use crate::eval::{Args, Func, Regex, Value}; use crate::library::structure::{EnumNode, ListNode}; use crate::syntax::Span; @@ -87,7 +87,7 @@ impl Recipe { Args::from_values(self.span, [arg()]) }; - self.func.call(ctx, args)?.cast().at(self.span) + Ok(self.func.call(ctx, args)?.display()) } /// What kind of structure the property interrupts. diff --git a/tests/ref/structure/enum.png b/tests/ref/structure/enum.png Binary files differindex a9111f57..0fcae99d 100644 --- a/tests/ref/structure/enum.png +++ b/tests/ref/structure/enum.png diff --git a/tests/ref/style/show-node.png b/tests/ref/style/show-node.png Binary files differindex 3cb3539c..63be751a 100644 --- a/tests/ref/style/show-node.png +++ b/tests/ref/style/show-node.png diff --git a/tests/ref/style/wrap.png b/tests/ref/style/wrap.png Binary files differindex 82d1c34d..7fb8dfc5 100644 --- a/tests/ref/style/wrap.png +++ b/tests/ref/style/wrap.png diff --git a/tests/typ/structure/enum.typ b/tests/typ/structure/enum.typ index b1045ee2..7bd6fa88 100644 --- a/tests/typ/structure/enum.typ +++ b/tests/typ/structure/enum.typ @@ -46,6 +46,11 @@ ) --- +#set enum(label: n => n > 1) +. A +. B + +--- // Lone dot is not a list. . @@ -56,8 +61,3 @@ --- // Error: 18-24 invalid pattern #set enum(label: "(())") - ---- -// Error: 18-28 expected content, found boolean -#set enum(label: n => false) -. A diff --git a/tests/typ/style/show-node.typ b/tests/typ/style/show-node.typ index 678ff151..33895add 100644 --- a/tests/typ/style/show-node.typ +++ b/tests/typ/style/show-node.typ @@ -76,7 +76,6 @@ Another text. } --- -// Error: 18-22 expected content, found integer #show heading as 1234 = Heading diff --git a/tests/typ/style/wrap.typ b/tests/typ/style/wrap.typ index 57f21f99..e37c4bc9 100644 --- a/tests/typ/style/wrap.typ +++ b/tests/typ/style/wrap.typ @@ -25,8 +25,8 @@ A [_B #wrap c in [*#c*]; C_] D Forest --- +// Ok, whatever. { - // Error: 3-24 expected remaining block to yield content, found integer wrap body in 2 * body 2 } |
