summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-13 17:44:14 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-13 17:45:08 +0100
commit17e9805b34562781d514ba6b0df31155c8d39824 (patch)
treec5c4761f59d6ffa57755660f51e88621ddcff689 /library
parent5233b1c50a4a671fdc38cf0d40868f8c075d9ed7 (diff)
Let `eval` take code instead of markup
Diffstat (limited to 'library')
-rw-r--r--library/src/compute/foundations.rs25
1 files changed, 9 insertions, 16 deletions
diff --git a/library/src/compute/foundations.rs b/library/src/compute/foundations.rs
index 33a90ae4..82270dd3 100644
--- a/library/src/compute/foundations.rs
+++ b/library/src/compute/foundations.rs
@@ -1,9 +1,5 @@
use crate::prelude::*;
-use comemo::Track;
-use typst::model;
-use typst::syntax::Source;
-
/// # Type
/// Determine a value's type.
///
@@ -92,32 +88,29 @@ pub fn assert(args: &mut Args) -> SourceResult<Value> {
}
/// # Evaluate
-/// Evaluate a string as Typst markup.
+/// Evaluate a string as Typst code.
///
-/// You shouldn't typically need this function, but it is there if you do.
+/// This function should only be used as a last resort.
///
/// ## Example
/// ```example
-/// #let markup = "= Heading\n _Emphasis_"
-/// #eval(markup)
+/// #eval("1 + 2") \
+/// #eval("[*Strong text*]") \
+/// #eval("(1, 2, 3)").len()
/// ```
///
/// ## Parameters
/// - source: `String` (positional, required)
-/// A string of Typst markup to evaluate.
+/// A string of Typst code to evaluate.
///
-/// The markup and code in the string cannot interact with the file system.
+/// The code in the string cannot interact with the file system.
///
-/// - returns: content
+/// - returns: any
///
/// ## Category
/// foundations
#[func]
pub fn eval(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: text, span } = args.expect::<Spanned<String>>("source")?;
- let source = Source::synthesized(text, span);
- let route = model::Route::default();
- let mut tracer = model::Tracer::default();
- let module = model::eval(vm.world(), route.track(), tracer.track_mut(), &source)?;
- Ok(Value::Content(module.content()))
+ typst::model::eval_code_str(vm.world(), &text, span)
}