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/capture.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/capture.rs')
| -rw-r--r-- | src/eval/capture.rs | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/src/eval/capture.rs b/src/eval/capture.rs index 74da4747..64275e93 100644 --- a/src/eval/capture.rs +++ b/src/eval/capture.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use super::{Scope, Scopes, Value}; use crate::syntax::visit::{visit_expr, Visit}; -use crate::syntax::{Expr, Ident, Node}; +use crate::syntax::{Expr, Ident}; /// A visitor that captures variable slots. #[derive(Debug)] @@ -26,37 +26,20 @@ impl<'a> CapturesVisitor<'a> { pub fn finish(self) -> Scope { self.captures } - - /// Find out whether the name is not locally defined and if so if it can be - /// captured. - fn process(&mut self, name: &str) { - if self.internal.get(name).is_none() { - if let Some(slot) = self.external.get(name) { - self.captures.def_slot(name, Rc::clone(slot)); - } - } - } } impl<'ast> Visit<'ast> for CapturesVisitor<'_> { - fn visit_node(&mut self, node: &'ast Node) { - match node { - Node::Text(_) => {} - Node::Space => {} - Node::Linebreak(_) => self.process(Node::LINEBREAK), - Node::Parbreak(_) => self.process(Node::PARBREAK), - Node::Strong(_) => self.process(Node::STRONG), - Node::Emph(_) => self.process(Node::EMPH), - Node::Heading(_) => self.process(Node::HEADING), - Node::Raw(_) => self.process(Node::RAW), - Node::Expr(expr) => self.visit_expr(expr), - } - } - fn visit_expr(&mut self, node: &'ast Expr) { - match node { - Expr::Ident(ident) => self.process(ident), - expr => visit_expr(self, expr), + if let Expr::Ident(ident) = node { + // Find out whether the name is not locally defined and if so if it + // can be captured. + if self.internal.get(ident).is_none() { + if let Some(slot) = self.external.get(ident) { + self.captures.def_slot(ident.as_str(), Rc::clone(slot)); + } + } + } else { + visit_expr(self, node); } } |
