aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/util.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-26 10:52:03 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-26 10:52:03 +0300
commitbf4632c461508de5202db98d25cd7ec06787c8dd (patch)
treedab8ddb1b0dcb7a20b9ab2e7067e26344776db4c /src/sexp/util.rs
parentc810925fce7d5de1845e09538b6943f54f266cb0 (diff)
downloadmyslip-bf4632c461508de5202db98d25cd7ec06787c8dd.tar.gz
myslip-bf4632c461508de5202db98d25cd7ec06787c8dd.zip
Created necessary data structures and utilities for integers and their operations; added tests for them
Diffstat (limited to 'src/sexp/util.rs')
-rw-r--r--src/sexp/util.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/sexp/util.rs b/src/sexp/util.rs
new file mode 100644
index 0000000..a4e3ab4
--- /dev/null
+++ b/src/sexp/util.rs
@@ -0,0 +1,27 @@
+
+use crate::sexp::SExp;
+use crate::sexp::SLeaf;
+use crate::sexp::SExp::*;
+use crate::sexp::SLeaf::*;
+
+impl From<i32> for Box<SExp> {
+ fn from(int: i32) -> Self {
+ Box::new(Atom(Int(int)))
+ }
+}
+
+impl From<SLeaf> for Box<SExp> {
+ fn from(leaf: SLeaf) -> Self {
+ Box::new(Atom(leaf))
+ }
+}
+
+impl From<i32> for SLeaf {
+ fn from(int: i32) -> Self {
+ Int(int)
+ }
+}
+
+pub fn sexp(x: impl Into<Box<SExp>>, y: impl Into<Box<SExp>>) -> SExp {
+ SCons(x.into(), y.into())
+}