aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/mod.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-30 17:27:15 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-30 17:27:15 +0300
commitcd68a2880db1400ae09ce0df64994b2bae33a3c1 (patch)
tree04893ee79ed16b920e7129b4eab1298a62814d65 /src/sexp/mod.rs
parent8e2ca4bbc356d87ff5a37f20bea4f5b3cc561041 (diff)
downloadmyslip-cd68a2880db1400ae09ce0df64994b2bae33a3c1.tar.gz
myslip-cd68a2880db1400ae09ce0df64994b2bae33a3c1.zip
Implemented evaluation according to tests. Quite a bit of changes were required, see rest of commit message.
SExp::Quote was added to let the interpreter know whether a list should be evaluated or treated as a literal list. It still needs code to be added for parsing it successfully. Some utility functions were needed: * SExp::is_value * SExp::consists_of_values * SExp::into_vec
Diffstat (limited to 'src/sexp/mod.rs')
-rw-r--r--src/sexp/mod.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs
index 3dbcbb5..f6c50d7 100644
--- a/src/sexp/mod.rs
+++ b/src/sexp/mod.rs
@@ -17,6 +17,7 @@ pub enum SLeaf {
Div,
Int(i32),
Var(String),
+ Quote,
Nil,
}
@@ -31,3 +32,23 @@ pub enum SExp {
SCons(Box<SExp>, Box<SExp>),
Atom(SLeaf),
}
+
+use SExp::*;
+use SLeaf::*;
+
+impl SExp {
+ pub fn is_value(&self) -> bool {
+ match self {
+ SCons(a, _) => **a == Atom(Quote),
+ Atom(Var(_)) => false,
+ Atom(_) => true,
+ }
+ }
+
+ pub fn consists_of_values(&self) -> bool {
+ self.is_value() || match self {
+ SCons(a, b) if (*a).is_value() => b.consists_of_values(),
+ _ => false
+ }
+ }
+}