summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorMarmare314 <49279081+Marmare314@users.noreply.github.com>2023-04-20 11:05:11 +0200
committerGitHub <noreply@github.com>2023-04-20 11:05:11 +0200
commit4524539c2bc5f3a9f53bc57a1902264fc894969b (patch)
tree578dcc6b82b0d40d88eb5d6a6f07cbdc38ef10d0 /src/eval
parentc505a0f5dccd120d97926f6ff5bbe0becf783aeb (diff)
forbid underscore as identifier closes #513 (#837)
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/func.rs5
-rw-r--r--src/eval/mod.rs4
2 files changed, 9 insertions, 0 deletions
diff --git a/src/eval/func.rs b/src/eval/func.rs
index faf2d696..29b85f7a 100644
--- a/src/eval/func.rs
+++ b/src/eval/func.rs
@@ -274,6 +274,8 @@ pub enum Param {
Named(Ident, Value),
/// An argument sink: `..args`.
Sink(Option<Ident>),
+ /// A placeholder: `_`.
+ Placeholder,
}
impl Closure {
@@ -334,6 +336,9 @@ impl Closure {
args.named::<Value>(ident)?.unwrap_or_else(|| default.clone());
vm.define(ident.clone(), value);
}
+ Param::Placeholder => {
+ args.eat::<Value>()?;
+ }
}
}
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index 797e1fef..0a963faf 100644
--- a/src/eval/mod.rs
+++ b/src/eval/mod.rs
@@ -1160,6 +1160,7 @@ impl Eval for ast::Closure {
params.push(Param::Named(named.name(), named.expr().eval(vm)?));
}
ast::Param::Sink(name) => params.push(Param::Sink(name)),
+ ast::Param::Placeholder => params.push(Param::Placeholder),
}
}
@@ -1184,6 +1185,7 @@ impl ast::Pattern {
vm.define(ident.clone(), value);
Ok(Value::None)
}
+ ast::Pattern::Placeholder => Ok(Value::None),
ast::Pattern::Destructuring(destruct) => {
match value {
Value::Array(value) => {
@@ -1215,6 +1217,7 @@ impl ast::Pattern {
"cannot destructure named elements from an array"
)
}
+ ast::DestructuringKind::Placeholder => i += 1,
}
}
if i < value.len() {
@@ -1243,6 +1246,7 @@ impl ast::Pattern {
vm.define(ident.clone(), v.clone());
used.insert(key.clone().take());
}
+ ast::DestructuringKind::Placeholder => {}
}
}