summaryrefslogtreecommitdiff
path: root/src/eval/capture.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-10-17 16:47:07 +0200
committerLaurenz <laurmaedje@gmail.com>2022-10-17 17:11:01 +0200
commit4fd031a256b2ecfe524859d5599fafb386395572 (patch)
tree14787137b5188666a2133525d10ac0b72357551c /src/eval/capture.rs
parent54b38c479060ac06213cb311f22b84bccdf88932 (diff)
More spans in AST
Diffstat (limited to 'src/eval/capture.rs')
-rw-r--r--src/eval/capture.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/eval/capture.rs b/src/eval/capture.rs
index b7570fe9..289d31e1 100644
--- a/src/eval/capture.rs
+++ b/src/eval/capture.rs
@@ -1,6 +1,6 @@
use super::{Scope, Scopes, Value};
-use crate::syntax::ast::{ClosureParam, Expr, Ident, Imports, TypedNode};
-use crate::syntax::SyntaxNode;
+use crate::syntax::ast::TypedNode;
+use crate::syntax::{ast, SyntaxNode};
/// A visitor that captures variable slots.
pub struct CapturesVisitor<'a> {
@@ -25,12 +25,12 @@ impl<'a> CapturesVisitor<'a> {
}
/// Bind a new internal variable.
- pub fn bind(&mut self, ident: Ident) {
+ pub fn bind(&mut self, ident: ast::Ident) {
self.internal.top.define(ident.take(), Value::None);
}
/// Capture a variable if it isn't internal.
- pub fn capture(&mut self, ident: Ident) {
+ pub fn capture(&mut self, ident: ast::Ident) {
if self.internal.get(&ident).is_err() {
if let Ok(value) = self.external.get(&ident) {
self.captures.define_captured(ident.take(), value.clone());
@@ -45,10 +45,10 @@ impl<'a> CapturesVisitor<'a> {
// Identifiers that shouldn't count as captures because they
// actually bind a new name are handled below (individually through
// the expressions that contain them).
- Some(Expr::Ident(ident)) => self.capture(ident),
+ Some(ast::Expr::Ident(ident)) => self.capture(ident),
// Code and content blocks create a scope.
- Some(Expr::Code(_) | Expr::Content(_)) => {
+ Some(ast::Expr::Code(_) | ast::Expr::Content(_)) => {
self.internal.enter();
for child in node.children() {
self.visit(child);
@@ -59,18 +59,18 @@ impl<'a> CapturesVisitor<'a> {
// A closure contains parameter bindings, which are bound before the
// body is evaluated. Care must be taken so that the default values
// of named parameters cannot access previous parameter bindings.
- Some(Expr::Closure(expr)) => {
+ Some(ast::Expr::Closure(expr)) => {
for param in expr.params() {
- if let ClosureParam::Named(named) = param {
+ if let ast::Param::Named(named) = param {
self.visit(named.expr().as_untyped());
}
}
for param in expr.params() {
match param {
- ClosureParam::Pos(ident) => self.bind(ident),
- ClosureParam::Named(named) => self.bind(named.name()),
- ClosureParam::Sink(ident) => self.bind(ident),
+ ast::Param::Pos(ident) => self.bind(ident),
+ ast::Param::Named(named) => self.bind(named.name()),
+ ast::Param::Sink(ident) => self.bind(ident),
}
}
@@ -79,7 +79,7 @@ impl<'a> CapturesVisitor<'a> {
// A let expression contains a binding, but that binding is only
// active after the body is evaluated.
- Some(Expr::Let(expr)) => {
+ Some(ast::Expr::Let(expr)) => {
if let Some(init) = expr.init() {
self.visit(init.as_untyped());
}
@@ -88,7 +88,7 @@ impl<'a> CapturesVisitor<'a> {
// A show rule contains a binding, but that binding is only active
// after the target has been evaluated.
- Some(Expr::Show(show)) => {
+ Some(ast::Expr::Show(show)) => {
self.visit(show.pattern().as_untyped());
if let Some(binding) = show.binding() {
self.bind(binding);
@@ -99,7 +99,7 @@ impl<'a> CapturesVisitor<'a> {
// A for loop contains one or two bindings in its pattern. These are
// active after the iterable is evaluated but before the body is
// evaluated.
- Some(Expr::For(expr)) => {
+ Some(ast::Expr::For(expr)) => {
self.visit(expr.iter().as_untyped());
let pattern = expr.pattern();
if let Some(key) = pattern.key() {
@@ -111,9 +111,9 @@ impl<'a> CapturesVisitor<'a> {
// An import contains items, but these are active only after the
// path is evaluated.
- Some(Expr::Import(expr)) => {
+ Some(ast::Expr::Import(expr)) => {
self.visit(expr.path().as_untyped());
- if let Imports::Items(items) = expr.imports() {
+ if let ast::Imports::Items(items) = expr.imports() {
for item in items {
self.bind(item);
}