summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-23 10:54:25 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-23 12:00:06 +0100
commitb2a3d3f235fb5a23322435b854460f52db772114 (patch)
tree441ded5e4fcc0a702fe877fc6a3e3fedaaacabb5 /library/src
parent65aa27014d090628cfef14b0679d86dd611188b9 (diff)
More general evaluation interface
Diffstat (limited to 'library/src')
-rw-r--r--library/src/base/mod.rs20
-rw-r--r--library/src/lib.rs2
2 files changed, 4 insertions, 18 deletions
diff --git a/library/src/base/mod.rs b/library/src/base/mod.rs
index f1fdd2b9..837a2f0e 100644
--- a/library/src/base/mod.rs
+++ b/library/src/base/mod.rs
@@ -11,7 +11,7 @@ pub use self::data::*;
pub use self::string::*;
use comemo::Track;
-use typst::model::{Eval, Route, Scopes, Vm};
+use typst::model::{self, Route, Vm};
use typst::syntax::Source;
use crate::prelude::*;
@@ -33,22 +33,8 @@ pub fn assert(_: &mut Vm, args: &mut Args) -> SourceResult<Value> {
/// 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().scope;
- 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?))
+ let module = model::eval(vm.world, route.track(), &source)?;
+ Ok(Value::Content(module.content))
}
diff --git a/library/src/lib.rs b/library/src/lib.rs
index 7a292c6d..e5e60968 100644
--- a/library/src/lib.rs
+++ b/library/src/lib.rs
@@ -154,7 +154,7 @@ pub fn styles() -> StyleMap {
/// Construct the standard lang item mapping.
pub fn items() -> LangItems {
LangItems {
- root: |content, world, styles| content.layout_root(world, styles),
+ layout: |content, world, styles| content.layout_root(world, styles),
em: |styles| styles.get(text::TextNode::SIZE),
dir: |styles| styles.get(text::TextNode::DIR),
space: || text::SpaceNode.pack(),