diff options
Diffstat (limited to 'src/sexp')
-rw-r--r-- | src/sexp/display.rs | 1 | ||||
-rw-r--r-- | src/sexp/mod.rs | 1 | ||||
-rw-r--r-- | src/sexp/step.rs | 21 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/sexp/display.rs b/src/sexp/display.rs index e2f4ffc..ec1b421 100644 --- a/src/sexp/display.rs +++ b/src/sexp/display.rs @@ -28,6 +28,7 @@ impl fmt::Display for SLeaf { RestPat(s) => format!("..{s}"), Quote => "quote".to_string(), Vector => "vector".to_string(), + Concat => "<>".to_string(), Print => "print".to_string(), Let => "let".to_string(), Fun => "fn".to_string(), diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs index aa51811..1a90f52 100644 --- a/src/sexp/mod.rs +++ b/src/sexp/mod.rs @@ -30,6 +30,7 @@ pub enum SLeaf { Or, Not, Xor, + Concat, Quote, Vector, diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 9077401..59b201c 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -441,6 +441,27 @@ impl SExp { }, + // Concatenation + SCons(op, l) if *op == Atom(Concat) => { + let ls = l.parts(); + let firstvec = ls.get(0).unwrap(); + let secondvec = ls.get(1).unwrap(); + let firstvec = match firstvec { + SCons(a, b) if **a == Atom(Vector) => *b.clone(), + t => t.clone(), + }; + let secondvec = match secondvec { + SCons(a, b) if **a == Atom(Vector) => *b.clone(), + t => t.clone(), + }; + let mut res = Atom(Nil); + for exp in firstvec.parts().into_iter().chain(secondvec.parts()).rev() { + res = scons(exp, res); + } + Ok(scons(Vector, res)) + }, + + // Arithmetic |