summaryrefslogtreecommitdiff
path: root/src/library/utility/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-03 11:44:53 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-03 13:35:39 +0100
commit37a7afddfaffd44cb9bc013c9506599267e08983 (patch)
tree20e7d62d3c5418baff01a21d0406b91bf3096214 /src/library/utility/mod.rs
parent56342bd972a13ffe21beaf2b87ab7eb1597704b4 (diff)
Split crates
Diffstat (limited to 'src/library/utility/mod.rs')
-rw-r--r--src/library/utility/mod.rs54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/library/utility/mod.rs b/src/library/utility/mod.rs
deleted file mode 100644
index 2d637d29..00000000
--- a/src/library/utility/mod.rs
+++ /dev/null
@@ -1,54 +0,0 @@
-//! Computational utility functions.
-
-mod color;
-mod data;
-mod math;
-mod string;
-
-pub use color::*;
-pub use data::*;
-pub use math::*;
-pub use string::*;
-
-use comemo::Track;
-
-use crate::library::prelude::*;
-use crate::model::{Eval, Route, Scopes, Vm};
-use crate::syntax::Source;
-
-/// The name of a value's type.
-pub fn type_(_: &mut Vm, args: &mut Args) -> SourceResult<Value> {
- Ok(args.expect::<Value>("value")?.type_name().into())
-}
-
-/// Ensure that a condition is fulfilled.
-pub fn assert(_: &mut Vm, args: &mut Args) -> SourceResult<Value> {
- let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
- if !v {
- bail!(span, "assertion failed");
- }
- Ok(Value::None)
-}
-
-/// Evaluate a string as Typst markup.
-pub fn eval(vm: &mut Vm, args: &mut Args) -> SourceResult<Value> {
- let Spanned { v: text, span } = args.expect::<Spanned<String>>("source")?;
-
- // Parse the source and set a synthetic span for all nodes.
- let source = Source::synthesized(text, span);
- let ast = source.ast()?;
-
- // Evaluate the source.
- let std = &vm.world.config().std;
- let scopes = Scopes::new(Some(std));
- let route = Route::default();
- let mut sub = Vm::new(vm.world, route.track(), None, scopes);
- let result = ast.eval(&mut sub);
-
- // Handle control flow.
- if let Some(flow) = sub.flow {
- bail!(flow.forbidden());
- }
-
- Ok(Value::Content(result?))
-}