aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/step.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-16 02:04:09 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-16 02:04:09 +0300
commite35522189f5217987bc455d70c3b9056541ef8c6 (patch)
tree421bcca16938157268eb9bcd4ea181ce0d099133 /src/sexp/step.rs
parenta97fef6f099767924c5203782a2b04b1a559ac6b (diff)
downloadmyslip-e35522189f5217987bc455d70c3b9056541ef8c6.tar.gz
myslip-e35522189f5217987bc455d70c3b9056541ef8c6.zip
feat: type conversion from (Vec/Quote X) -> X and add vec/quote to rest pattern substitutions
Diffstat (limited to 'src/sexp/step.rs')
-rw-r--r--src/sexp/step.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/sexp/step.rs b/src/sexp/step.rs
index 99925ac..9077401 100644
--- a/src/sexp/step.rs
+++ b/src/sexp/step.rs
@@ -352,9 +352,10 @@ impl SExp {
return Ok(SExp::back_to_case(scrutinee.step()?, patarms));
}
- let scrutinee = match scrutinee {
- SCons(q, v) if *q == Atom(Quote) || *q == Atom(Vector) => *v,
- t => t,
+ let (scrutinee, rest_pat_struct) = match scrutinee {
+ SCons(q, v) if *q == Atom(Quote) => (*v, Some(Quote)),
+ SCons(q, v) if *q == Atom(Vector) => (*v, Some(Vector)),
+ t => (t, None),
};
for patarm in patarms {
@@ -369,7 +370,14 @@ impl SExp {
if let Some(ctx) = scrutinee.matches_pat(&pat) {
for (name, value) in ctx {
- arm = arm.subst(&name, &value);
+ arm = match name {
+ Var(name) => arm.subst(&name, &value),
+ RestPat(name) => match rest_pat_struct.clone() {
+ Some(kw) => arm.subst(&name, &scons(kw, value)),
+ None => arm.subst(&name, &value)
+ },
+ _ => panic!("unreachable")
+ };
}
return Ok(arm);
}