mirror of
https://github.com/typst/typst
synced 2025-08-15 15:38:33 +08:00
Add TrackedMut<Sink> as an argument
This commit is contained in:
parent
9682d40c32
commit
562c3c31e1
@ -2,6 +2,7 @@ use comemo::Track;
|
||||
use ecow::{eco_format, EcoString};
|
||||
use serde::Serialize;
|
||||
use typst::diag::{bail, HintedStrResult, StrResult, Warned};
|
||||
use typst::engine::Sink;
|
||||
use typst::foundations::{Content, IntoValue, LocatableSelector, Scope};
|
||||
use typst::layout::PagedDocument;
|
||||
use typst::syntax::Span;
|
||||
@ -62,9 +63,9 @@ fn retrieve(
|
||||
Span::detached(),
|
||||
EvalMode::Code,
|
||||
Scope::default(),
|
||||
// TODO: propagate warnings
|
||||
Sink::new().track_mut(),
|
||||
)
|
||||
// TODO: propagate warnings
|
||||
.map(|(result, _sink)| result)
|
||||
.map_err(|errors| {
|
||||
let mut message = EcoString::from("failed to evaluate selector");
|
||||
for (i, error) in errors.into_iter().enumerate() {
|
||||
|
@ -105,7 +105,8 @@ pub fn eval_string(
|
||||
span: Span,
|
||||
mode: EvalMode,
|
||||
scope: Scope,
|
||||
) -> SourceResult<(Value, Sink)> {
|
||||
sink: TrackedMut<Sink>,
|
||||
) -> SourceResult<Value> {
|
||||
let mut root = match mode {
|
||||
EvalMode::Code => parse_code(string),
|
||||
EvalMode::Markup => parse(string),
|
||||
@ -121,7 +122,6 @@ pub fn eval_string(
|
||||
}
|
||||
|
||||
// Prepare the engine.
|
||||
let mut sink = Sink::new();
|
||||
let introspector = Introspector::default();
|
||||
let traced = Traced::default();
|
||||
let engine = Engine {
|
||||
@ -129,7 +129,7 @@ pub fn eval_string(
|
||||
world,
|
||||
introspector: introspector.track(),
|
||||
traced: traced.track(),
|
||||
sink: sink.track_mut(),
|
||||
sink,
|
||||
route: Route::default(),
|
||||
};
|
||||
|
||||
@ -158,7 +158,7 @@ pub fn eval_string(
|
||||
bail!(flow.forbidden());
|
||||
}
|
||||
|
||||
Ok((output, sink))
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
/// Evaluate an expression.
|
||||
|
@ -68,6 +68,7 @@ pub use self::target_::*;
|
||||
pub use self::ty::*;
|
||||
pub use self::value::*;
|
||||
pub use self::version::*;
|
||||
use comemo::Track;
|
||||
pub use typst_macros::{scope, ty};
|
||||
|
||||
#[rustfmt::skip]
|
||||
@ -82,6 +83,7 @@ use typst_syntax::Spanned;
|
||||
|
||||
use crate::diag::{bail, SourceResult, StrResult};
|
||||
use crate::engine::Engine;
|
||||
use crate::engine::Sink;
|
||||
use crate::routines::EvalMode;
|
||||
use crate::{Feature, Features};
|
||||
|
||||
@ -297,13 +299,15 @@ pub fn eval(
|
||||
for (key, value) in dict {
|
||||
scope.bind(key.into(), Binding::new(value, span));
|
||||
}
|
||||
let (result, sink) = (engine.routines.eval_string)(
|
||||
let mut sink = Sink::new();
|
||||
let result = (engine.routines.eval_string)(
|
||||
engine.routines,
|
||||
engine.world,
|
||||
&text,
|
||||
span,
|
||||
mode,
|
||||
scope,
|
||||
sink.track_mut(),
|
||||
)?;
|
||||
|
||||
for warning in sink.warnings() {
|
||||
|
@ -6,7 +6,7 @@ use std::num::NonZeroUsize;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
use comemo::Tracked;
|
||||
use comemo::{Track, Tracked};
|
||||
use ecow::{eco_format, EcoString, EcoVec};
|
||||
use hayagriva::archive::ArchivedStyle;
|
||||
use hayagriva::io::BibLaTeXError;
|
||||
@ -20,7 +20,7 @@ use typst_syntax::{Span, Spanned};
|
||||
use typst_utils::{Get, ManuallyHash, NonZeroExt, PicoStr};
|
||||
|
||||
use crate::diag::{bail, error, At, FileError, HintedStrResult, SourceResult, StrResult};
|
||||
use crate::engine::Engine;
|
||||
use crate::engine::{Engine, Sink};
|
||||
use crate::foundations::{
|
||||
elem, Bytes, CastInfo, Content, Derived, FromValue, IntoValue, Label, NativeElement,
|
||||
OneOrMultiple, Packed, Reflect, Scope, Show, ShowSet, Smart, StyleChain, Styles,
|
||||
@ -1003,9 +1003,10 @@ impl ElemRenderer<'_> {
|
||||
self.span,
|
||||
EvalMode::Math,
|
||||
Scope::new(),
|
||||
// TODO: propagate warnings
|
||||
Sink::new().track_mut(),
|
||||
)
|
||||
// TODO: propagate warnings
|
||||
.map(|(result, _sink)| Value::display(result))
|
||||
.map(Value::display)
|
||||
.unwrap_or_else(|_| TextElem::packed(math).spanned(self.span))
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,8 @@ routines! {
|
||||
span: Span,
|
||||
mode: EvalMode,
|
||||
scope: Scope,
|
||||
) -> SourceResult<(Value, Sink)>
|
||||
sink: TrackedMut<Sink>,
|
||||
) -> SourceResult<Value>
|
||||
|
||||
/// Call the closure in the context with the arguments.
|
||||
fn eval_closure(
|
||||
|
Loading…
x
Reference in New Issue
Block a user