diff options
Diffstat (limited to 'src/sexp')
-rw-r--r-- | src/sexp/util.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/sexp/util.rs b/src/sexp/util.rs index 70ac152..0818e6b 100644 --- a/src/sexp/util.rs +++ b/src/sexp/util.rs @@ -58,4 +58,16 @@ impl SExp { _ => Err("expected list, found atom".to_string()), } } + + pub fn parts(self) -> Vec<SExp> { + match self { + Atom(x) => vec![Atom(x)], + SCons(a, b) if *b == Atom(Nil) => vec![*a], + SCons(a, b) => { + let mut res = vec![*a]; + res.extend_from_slice(&(*b).parts()); + res + }, + } + } } |