summaryrefslogtreecommitdiff
path: root/src/model/eval.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-01-20 14:05:17 +0100
committerLaurenz <laurmaedje@gmail.com>2023-01-20 14:05:35 +0100
commitdd331f007cb9c9968605f8d3eaef8fb498c21322 (patch)
treef1b1490758ec53fd204724a325158d16c980d131 /src/model/eval.rs
parent40561e57fbbc68becac07acd54a34f94f591f277 (diff)
Rewrite parser
Diffstat (limited to 'src/model/eval.rs')
-rw-r--r--src/model/eval.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/model/eval.rs b/src/model/eval.rs
index 8e8c93c5..0469649b 100644
--- a/src/model/eval.rs
+++ b/src/model/eval.rs
@@ -261,9 +261,10 @@ impl Eval for ast::Expr {
};
match self {
+ Self::Text(v) => v.eval(vm).map(Value::Content),
Self::Space(v) => v.eval(vm).map(Value::Content),
Self::Linebreak(v) => v.eval(vm).map(Value::Content),
- Self::Text(v) => v.eval(vm).map(Value::Content),
+ Self::Parbreak(v) => v.eval(vm).map(Value::Content),
Self::Escape(v) => v.eval(vm).map(Value::Content),
Self::Shorthand(v) => v.eval(vm).map(Value::Content),
Self::Symbol(v) => v.eval(vm).map(Value::Content),
@@ -330,14 +331,19 @@ impl ast::Expr {
}
}
+impl Eval for ast::Text {
+ type Output = Content;
+
+ fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
+ Ok((vm.items.text)(self.get().clone()))
+ }
+}
+
impl Eval for ast::Space {
type Output = Content;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok(match self.newlines() {
- 0..=1 => (vm.items.space)(),
- _ => (vm.items.parbreak)(),
- })
+ Ok((vm.items.space)())
}
}
@@ -349,11 +355,11 @@ impl Eval for ast::Linebreak {
}
}
-impl Eval for ast::Text {
+impl Eval for ast::Parbreak {
type Output = Content;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok((vm.items.text)(self.get().clone()))
+ Ok((vm.items.parbreak)())
}
}
@@ -438,7 +444,7 @@ impl Eval for ast::Link {
type Output = Content;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok((vm.items.link)(self.url().clone()))
+ Ok((vm.items.link)(self.get().clone()))
}
}
@@ -1231,13 +1237,17 @@ impl Eval for ast::ModuleImport {
}
}
Some(ast::Imports::Items(idents)) => {
+ let mut errors = vec![];
for ident in idents {
if let Some(value) = module.scope().get(&ident) {
vm.scopes.top.define(ident.take(), value.clone());
} else {
- bail!(ident.span(), "unresolved import");
+ errors.push(error!(ident.span(), "unresolved import"));
}
}
+ if errors.len() > 0 {
+ return Err(Box::new(errors));
+ }
}
}