diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-09 00:37:13 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-09 00:37:13 +0200 |
| commit | 5afb42ad89abb518a01a09051f0f9b6f75bd383e (patch) | |
| tree | b12368a287f22de711df8d759c20ee742ed5b4c2 /src/eval/mod.rs | |
| parent | d69dfa84ec957ac4037f60a3335416a9f73b97c8 (diff) | |
Lists with indent-based parsing
- Unordered lists with indent-based parsing and basic layout using stacks
- Headings are now also indent based
- Removes syntax functions since they will be superseded by select & transform
Diffstat (limited to 'src/eval/mod.rs')
| -rw-r--r-- | src/eval/mod.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs index c480ddfe..d1307b6d 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -218,24 +218,23 @@ pub trait Eval { } impl Eval for Tree { - type Output = NodeMap; + type Output = ExprMap; fn eval(&self, ctx: &mut EvalContext) -> Self::Output { - let mut map = NodeMap::new(); - - for node in self { - let value = if let Some(call) = node.desugar() { - call.eval(ctx) - } else if let Node::Expr(expr) = node { - expr.eval(ctx) - } else { - continue; - }; + struct ExprVisitor<'a, 'b> { + ctx: &'a mut EvalContext<'b>, + map: ExprMap, + } - map.insert(node as *const _, value); + impl<'ast> Visit<'ast> for ExprVisitor<'_, '_> { + fn visit_expr(&mut self, node: &'ast Expr) { + self.map.insert(node as *const _, node.eval(self.ctx)); + } } - map + let mut visitor = ExprVisitor { ctx, map: ExprMap::new() }; + visitor.visit_tree(self); + visitor.map } } |
