Big referencing refactor

- RC+RefCell pattern used... everywhere
- Ast type implemented
- unit tests for func_call
- more changes, but this commit scope has grown significantly and I
cannot list them all
This commit is contained in:
Aidan 2021-03-14 16:14:57 -07:00
parent 76b12a8214
commit 3434a49cc1
No known key found for this signature in database
GPG key ID: 327711E983899316
9 changed files with 446 additions and 391 deletions

View file

@ -1,12 +1,12 @@
mod lex_tests {
use relish::ast::{lex};
use relish::ast::{lex, ast_to_string};
#[test]
fn test_lex_basic_pair() {
let document: &str = "(hello 'world')";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), document);
Ok(tree) => {
assert_eq!(ast_to_string(tree), document);
},
Err(s) => {
print!("{}\n", s);
@ -19,8 +19,8 @@ mod lex_tests {
fn test_lex_basic_list() {
let document: &str = "(hello 'world' 1 2 3)";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), document);
Ok(tree) => {
assert_eq!(ast_to_string(tree), document);
},
Err(s) => {
print!("{}\n", s);
@ -33,8 +33,8 @@ mod lex_tests {
fn test_lex_complex_list() {
let document: &str = "(hello 'world' (1 2 (1 2 3)) 1 2 3)";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), document);
Ok(tree) => {
assert_eq!(ast_to_string(tree), document);
},
Err(s) => {
print!("{}\n", s);
@ -48,8 +48,8 @@ mod lex_tests {
let document: &str = "(as;dd)";
let output: &str = "Problem lexing document: \"Unparsable token:as;dd\"";
match lex(document.to_string()) {
Ok(box_cell) => {
print!("Bad token yielded: {}\n", *box_cell);
Ok(tree) => {
print!("Bad token yielded: {}\n", ast_to_string(tree));
assert!(false);
},
Err(s) => {
@ -63,8 +63,8 @@ mod lex_tests {
let document: &str = "(one two";
let output: &str = "Problem lexing document: \"Unmatched list delimiter in input\"";
match lex(document.to_string()) {
Ok(box_cell) => {
print!("Bad token yielded: {}\n", *box_cell);
Ok(tree) => {
print!("Bad token yielded: {}\n", ast_to_string(tree));
assert!(false);
},
Err(s) => {
@ -78,8 +78,8 @@ mod lex_tests {
let document: &str = "(one two (three)";
let output: &str = "Problem lexing document: \"Unmatched list delimiter in input\"";
match lex(document.to_string()) {
Ok(box_cell) => {
print!("Bad token yielded: {}\n", *box_cell);
Ok(tree) => {
print!("Bad token yielded: {}\n", ast_to_string(tree));
assert!(false);
},
Err(s) => {
@ -93,8 +93,8 @@ mod lex_tests {
let document: &str = "#!/bin/relish\n(one two)";
let output: &str = "(one two)";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), output.to_string());
Ok(tree) => {
assert_eq!(ast_to_string(tree), output.to_string());
},
Err(s) => {
print!("{}\n", s);
@ -108,8 +108,8 @@ mod lex_tests {
let document: &str = "#!/bin/relish\n((one two)# another doc comment\n(three four))";
let output: &str = "((one two) (three four))";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), output.to_string());
Ok(tree) => {
assert_eq!(ast_to_string(tree), output.to_string());
},
Err(s) => {
print!("{}\n", s);
@ -123,8 +123,8 @@ mod lex_tests {
let document: &str = "#!/bin/relish\n((one two)\n# another doc comment\nthree)";
let output: &str = "((one two) three)";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), output.to_string());
Ok(tree) => {
assert_eq!(ast_to_string(tree), output.to_string());
},
Err(s) => {
print!("{}\n", s);
@ -138,8 +138,8 @@ mod lex_tests {
let document: &str = "(one t(wo)";
let output: &str = "Problem lexing document: \"list started in middle of another token\"";
match lex(document.to_string()) {
Ok(box_cell) => {
print!("Bad token yielded: {}\n", *box_cell);
Ok(tree) => {
print!("Bad token yielded: {}\n", ast_to_string(tree));
assert!(false);
},
Err(s) => {