aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/case.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sexp/case.rs')
-rw-r--r--src/sexp/case.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/sexp/case.rs b/src/sexp/case.rs
index 40310e4..0c3d82d 100644
--- a/src/sexp/case.rs
+++ b/src/sexp/case.rs
@@ -1,5 +1,5 @@
-use crate::sexp::{SExp, SExp::*, SLeaf::*};
+use crate::sexp::{SExp, SLeaf, SExp::*, SLeaf::*, util::*};
impl SExp {
/**
@@ -20,7 +20,7 @@ impl SExp {
* scons(1, scons(scons(2, scons(3, Nil)), Nil))
* .matches_pat(&var("x")),
* Some(vec![(
- * "x".to_string(),
+ * Var("x".to_string()),
* scons(1, scons(scons(2, scons(3, Nil)), Nil))
* )])
* );
@@ -34,8 +34,8 @@ impl SExp {
* scons(1, scons(scons(2, scons(3, Nil)), Nil))
* .matches_pat(&scons(var("x"), scons(var("y"), Nil))),
* Some(vec![
- * ("x".to_string(), Atom(Int(1))),
- * ("y".to_string(), scons(2, scons(3, Nil)))
+ * (Var("x".to_string()), Atom(Int(1))),
+ * (Var("y".to_string()), scons(2, scons(3, Nil)))
* ])
* );
* ```
@@ -47,24 +47,24 @@ impl SExp {
* scons(1, scons(2, scons(3, Nil)))
* .matches_pat(&scons(var("x"), scons(RestPat("y".to_string()), Nil))),
* Some(vec![
- * ("x".to_string(), Atom(Int(1))),
- * ("y".to_string(), scons(2, scons(3, Nil)))
+ * (Var("x".to_string()), Atom(Int(1))),
+ * (RestPat("y".to_string()), scons(2, scons(3, Nil)))
* ])
* );
* ```
*/
- pub fn matches_pat(&self, pat: &SExp) -> Option<Vec<(String, SExp)>> {
+ pub fn matches_pat(&self, pat: &SExp) -> Option<Vec<(SLeaf, SExp)>> {
match (self, pat) {
(a, b) if a == b => Some(vec![]),
- (a, Atom(Var(name))) => Some(vec![(name.clone(), a.clone())]),
+ (a, Atom(Var(name))) => Some(vec![(Var(name.to_string()), a.clone())]),
(SCons(a1, a2), SCons(b1, b2)) => {
let lefthand = a1.matches_pat(b1);
let checkres = (*b2).check_res_pat();
let righthand = match checkres {
- Some(name) => Some(vec![(name, *a2.clone())]),
+ Some(name) => Some(vec![(RestPat(name.clone()), *a2.clone())]),
None => a2.matches_pat(b2),
};
lefthand.zip(righthand)