Automatically display value in more places
This commit is contained in:
parent
11f1f0818b
commit
05c27a581e
@ -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;
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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.
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 27 KiB |
Binary file not shown.
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 23 KiB |
Binary file not shown.
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
@ -45,6 +45,11 @@
|
||||
[Red], [Green], [Blue],
|
||||
)
|
||||
|
||||
---
|
||||
#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
|
||||
|
@ -76,7 +76,6 @@ Another text.
|
||||
}
|
||||
|
||||
---
|
||||
// Error: 18-22 expected content, found integer
|
||||
#show heading as 1234
|
||||
= Heading
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user