aboutsummaryrefslogtreecommitdiff
path: root/src/sexp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sexp')
-rw-r--r--src/sexp/display.rs12
-rw-r--r--src/sexp/mod.rs18
-rw-r--r--src/sexp/step.rs114
3 files changed, 143 insertions, 1 deletions
diff --git a/src/sexp/display.rs b/src/sexp/display.rs
index 238e8d4..96ce435 100644
--- a/src/sexp/display.rs
+++ b/src/sexp/display.rs
@@ -11,6 +11,18 @@ impl fmt::Display for SLeaf {
Sub => "-".to_string(),
Mul => "*".to_string(),
Div => "/".to_string(),
+ Gt => ">".to_string(),
+ Lt => "<".to_string(),
+ Ge => ">=".to_string(),
+ Le => "<=".to_string(),
+ Eq => "=".to_string(),
+ Neq => "!=".to_string(),
+ And => "and".to_string(),
+ Or => "or".to_string(),
+ Not => "not".to_string(),
+ Xor => "xor".to_string(),
+ True => "true".to_string(),
+ False => "false".to_string(),
Int(x) => x.to_string(),
Var(s) => s.to_string(),
Quote => "quote".to_string(),
diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs
index 0fb5e25..60dd3b0 100644
--- a/src/sexp/mod.rs
+++ b/src/sexp/mod.rs
@@ -12,13 +12,29 @@ pub mod display;
#[derive(PartialEq)]
#[derive(Clone)]
pub enum SLeaf {
+
Add,
Sub,
Mul,
Div,
+ Eq,
+ Neq,
+ Gt,
+ Lt,
+ Ge,
+ Le,
+ And,
+ Or,
+ Not,
+ Xor,
+ Quote,
+
Int(i32),
+ True,
+ False,
+
Var(String),
- Quote,
+
Nil,
}
diff --git a/src/sexp/step.rs b/src/sexp/step.rs
index ee76ebf..bb3ada5 100644
--- a/src/sexp/step.rs
+++ b/src/sexp/step.rs
@@ -44,6 +44,7 @@ impl SExp {
/// ```
///
/// Also, addition and multiplication can take more than two arguments:
+ /// (as of 2025-08-05 not allowed by the type system, might change)
/// ```rust
/// use myslip::sexp::{SExp::*, SLeaf::*, util::*};
///
@@ -84,6 +85,119 @@ impl SExp {
///
/// ```
///
+ /// **Integer comparisons**
+ ///
+ /// ```rust
+ /// use myslip::sexp::{SExp::*, SLeaf::*, util::*};
+ ///
+ /// assert_eq!(
+ /// scons(Lt, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Gt, scons(2, scons(1, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(1, scons(1, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Le, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Le, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(2, scons(1, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Ge, scons(2, scons(1, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Ge, scons(1, scons(1, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Eq, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// assert_eq!(
+ /// scons(Eq, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Neq, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Neq, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// ```
+ ///
+ /// **Boolean expressions**
+ ///
+ /// ```rust
+ /// use myslip::sexp::{SExp::*, SLeaf::*, util::*};
+ /// assert_eq!(
+ /// scons(And, scons(True, scons(True, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(And, scons(False, scons(True, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Or, scons(False, scons(True, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Or, scons(False, scons(False, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Xor, scons(False, scons(True, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Xor, scons(False, scons(False, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// assert_eq!(
+ /// scons(Xor, scons(True, scons(True, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Not, scons(True, Nil)).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// assert_eq!(
+ /// scons(Not, scons(False, Nil)).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// ```
+ ///
/// **Quotes**
/// If an s-expression should not be evaluated
/// as a function, but it is instead to be treated