aboutsummaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-27 16:50:48 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-27 16:50:48 +0300
commit1bd9d5bbd304926f464cf23870b17a46385b9f7a (patch)
tree1fcdfb06601db88b9b8daa8aec73c48406125a50 /src/parse
parent794df40494e8c83532aed39153088697aca2f57b (diff)
downloadmyslip-1bd9d5bbd304926f464cf23870b17a46385b9f7a.tar.gz
myslip-1bd9d5bbd304926f464cf23870b17a46385b9f7a.zip
Created parse_token and added tests for it
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/mod.rs3
-rw-r--r--src/parse/parsetree.rs40
-rw-r--r--src/parse/util.rs11
3 files changed, 54 insertions, 0 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
new file mode 100644
index 0000000..0da7a30
--- /dev/null
+++ b/src/parse/mod.rs
@@ -0,0 +1,3 @@
+
+pub mod parsetree;
+pub mod util;
diff --git a/src/parse/parsetree.rs b/src/parse/parsetree.rs
new file mode 100644
index 0000000..8887200
--- /dev/null
+++ b/src/parse/parsetree.rs
@@ -0,0 +1,40 @@
+
+use nom::{
+ IResult,
+ Parser,
+};
+
+
+#[derive(Debug,PartialEq)]
+pub enum Token {
+ ParOpen,
+ ParClose,
+ Num(i32),
+ Sym(String),
+ Whitespace(String),
+}
+
+fn parse_token(s: &str) -> IResult<&str, Token> {
+ todo!()
+}
+
+#[cfg(test)]
+mod private_parsing_tests {
+ use super::{*, Token::*};
+ use crate::parse::util::*;
+
+ #[test]
+ fn test_parse_token() {
+ assert_eq!(parse_token("()"), Ok((")", ParOpen)));
+ assert_eq!(parse_token(")"), Ok(("", ParClose)));
+
+ assert_eq!(parse_token(" \t\n"), Ok(("", whitespace(" \t\n"))));
+
+ assert_eq!(parse_token("1 23"), Ok((" 23", Num(1))));
+ assert_eq!(parse_token("23"), Ok(("", Num(23))));
+
+ assert_eq!(parse_token("Nil a"), Ok((" a", sym("Nil"))));
+ assert_eq!(parse_token("a"), Ok(("", sym("a"))));
+ }
+
+}
diff --git a/src/parse/util.rs b/src/parse/util.rs
new file mode 100644
index 0000000..864005a
--- /dev/null
+++ b/src/parse/util.rs
@@ -0,0 +1,11 @@
+
+use crate::parse::parsetree::Token::*;
+use crate::parse::parsetree::Token;
+
+pub fn sym(s: &str) -> Token {
+ Sym(s.to_string())
+}
+
+pub fn whitespace(s: &str) -> Token {
+ Whitespace(s.to_string())
+}