diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-14 12:17:41 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-14 12:17:41 +0300 |
commit | 0975bff6ddcf48de4072561adea67a5c1cd4456f (patch) | |
tree | f77291d0430079d6927bf896c133e97a6e59c684 /src/sexp/step.rs | |
parent | 189d06730ae23770fbb970bf37eb0993edb8cd2d (diff) | |
download | myslip-0975bff6ddcf48de4072561adea67a5c1cd4456f.tar.gz myslip-0975bff6ddcf48de4072561adea67a5c1cd4456f.zip |
fix: step scrutinee of case & can instantiate empty vec
Diffstat (limited to 'src/sexp/step.rs')
-rw-r--r-- | src/sexp/step.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 97675fa..bae47a5 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -286,6 +286,20 @@ impl SExp { /// ); /// ``` /// + /// **Pattern matching** + /// ```rust + /// use myslip::{sexp::{SExp::*, SLeaf::*, util::*}, r#type::{Type::*, util::*}}; + /// use myslip::parse::parsetree::parse_to_ast; + /// + /// let exp = "case (+ 1 2) (3 true) (_ false)"; + /// let exp = parse_to_ast(exp); + /// let exp = exp.and_then(|e| e.step()); + /// let expshould = parse_to_ast("case 3 (3 true) (_ false)"); + /// assert_eq!(exp, expshould); + /// let exp = exp.and_then(|e| e.step()); + /// assert_eq!(exp, Ok(Atom(True))); + /// ``` + /// /// Shadowing: /// ```rust /// use myslip::sexp::{SExp::*, SLeaf::*, util::*}; @@ -352,6 +366,10 @@ impl SExp { // case expressions SCons(op, l) if scons(op.clone(), l.clone()).check_case().is_some() => { let (scrutinee, patarms) = scons(op, l).check_case().unwrap(); + if !scrutinee.is_value() { + return Ok(SExp::back_to_case(scrutinee.step()?, patarms)); + // return scons(Case, scons(scrutinee.step()?)) + } let scrutinee = match scrutinee { SCons(q, v) if *q == Atom(Quote) || *q == Atom(Vector) => *v, @@ -627,6 +645,11 @@ impl SExp { } }, + // Nil in list + SCons(op, l) if *op == Atom(Nil) => { + Ok(scons(Vector, Nil)) + }, + // Print SCons(op, l) if *op == Atom(Print) => { println!("{}", *l); |