diff --git a/src/bin/main.rs b/src/bin/main.rs index e0b3fc7..c91bb4f 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -62,7 +62,7 @@ fn main() { match user_doc { Ok(line) => { rl.add_history_entry(line.as_str()); - let l = line.as_str().to_owned(); + let l = line.as_str().to_owned(); match lex(&l) { Ok(a) => match eval(&a, &mut syms) { diff --git a/src/config.rs b/src/config.rs index 8b563d1..ee0e95e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -30,18 +30,18 @@ fn prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result { /* loads defaults, evaluates config script */ pub fn configure(filename: String, syms: &mut SymTable) -> Result<(), String> { /*syms.insert( - "CFG_RELISH_POSIX".to_string(), - Symbol { - name: String::from("CFG_RELISH_POSIX"), - args: Args::None, - conditional_branches: false, - docs: "variable holding whether or not POSIX job control functions are to be loaded. -checked at shell startup by configuration daemon. not used afterwards. + "CFG_RELISH_POSIX".to_string(), + Symbol { + name: String::from("CFG_RELISH_POSIX"), + args: Args::None, + conditional_branches: false, + docs: "variable holding whether or not POSIX job control functions are to be loaded. + checked at shell startup by configuration daemon. not used afterwards. -default value: not set".to_string(), - value: ValueType::VarForm(Box::new(Ctr::String("0".to_string()))), - }, - );*/ + default value: not set".to_string(), + value: ValueType::VarForm(Box::new(Ctr::String("0".to_string()))), + }, + );*/ syms.insert( "CFG_RELISH_ENV".to_string(), @@ -66,7 +66,8 @@ default value: 1 (set) args: Args::None, conditional_branches: false, docs: "function called to output prompt. this function is called with no arguments. -default value ()".to_string(), +default value ()" + .to_string(), value: ValueType::Internal(Rc::new(prompt_default_callback)), }, ); diff --git a/src/stl.rs b/src/stl.rs index 9c011cb..b3587fa 100644 --- a/src/stl.rs +++ b/src/stl.rs @@ -89,7 +89,8 @@ example: (let ((step1 'hello') In this example step1, step2, and step3 are created sequentially. Then, the echo form is evaluated, printing 'hello-world'. Finally, the some-func form is evaluated. -Since the call to some-func is the final form, its value is returned.".to_string(), +Since the call to some-func is the final form, its value is returned." + .to_string(), value: ValueType::Internal(Rc::new(control::let_callback)), }, ); @@ -126,7 +127,8 @@ example: (circuit (eq? (do-operation) myresult) false (do-another-operation)) -in this example, do-another-operation will not be called".to_string(), +in this example, do-another-operation will not be called" + .to_string(), value: ValueType::Internal(Rc::new(control::circuit_callback)), }, ); @@ -139,7 +141,8 @@ in this example, do-another-operation will not be called".to_string(), conditional_branches: false, docs: "traverses a list of N arguments, all of which are expected to be boolean. starts with arg1 AND arg2, and then calculates prev_result AND next_arg. -returns final result.".to_string(), +returns final result." + .to_string(), value: ValueType::Internal(Rc::new(boolean::bool_and_callback)), }, ); @@ -152,7 +155,8 @@ returns final result.".to_string(), conditional_branches: false, docs: "traverses a list of N arguments, all of which are expected to be boolean. starts with arg1 OR arg2, and then calculates prev_result OR next_arg. -returns final result.".to_string(), +returns final result." + .to_string(), value: ValueType::Internal(Rc::new(boolean::bool_or_callback)), }, ); @@ -164,7 +168,8 @@ returns final result.".to_string(), args: Args::Strict(vec![Type::Bool]), conditional_branches: false, docs: "takes a single argument (expects a boolean). -returns false if arg is true or true if arg is false.".to_string(), +returns false if arg is true or true if arg is false." + .to_string(), value: ValueType::Internal(Rc::new(boolean::bool_not_callback)), }, ); @@ -177,7 +182,8 @@ returns false if arg is true or true if arg is false.".to_string(), conditional_branches: false, docs: "traverses a list of N arguments. returns true if all arguments hold the same value. -NOTE: 1 and 1.0 are the same, but '1' 'one' or one (symbol) aren't".to_string(), +NOTE: 1 and 1.0 are the same, but '1' 'one' or one (symbol) aren't" + .to_string(), value: ValueType::Internal(Rc::new(boolean::bool_iseq_callback)), }, ); @@ -190,7 +196,8 @@ NOTE: 1 and 1.0 are the same, but '1' 'one' or one (symbol) aren't".to_string(), conditional_branches: true, docs: "switches a boolean symbol between true or false. Takes a single argument (a symbol). Looks it up in the variable table. -Either sets the symbol to true if it is currently false, or vice versa.".to_string(), +Either sets the symbol to true if it is currently false, or vice versa." + .to_string(), value: ValueType::Internal(Rc::new(boolean::bool_toggle_callback)), }, ); @@ -237,7 +244,8 @@ pub fn dynamic_stdlib(syms: &mut SymTable) -> Result<(), String> { (def myfunc 'does a thing' (myarg1 myarg2) (dothing myarg1 myarg2) (add myarg1 myarg2)) 3. symbol un-definition: Takes just a name. Removes variable from table. - (def useless-var)".to_string(), + (def useless-var)" + .to_string(), value: ValueType::Internal(Rc::new( move |ast: &Seg, syms: &mut SymTable| -> Result { _store_callback(ast, syms, env_cfg_user_form) @@ -261,7 +269,7 @@ fn _echo_callback(ast: &Seg, _syms: &mut SymTable) -> Result { fn _help_callback(ast: &Seg, syms: &mut SymTable) -> Result { if ast.len() != 1 { - return Err("help only takes a single argument".to_string()) + return Err("help only takes a single argument".to_string()); } if let Ctr::Symbol(ref symbol) = *ast.car { if let Some(ref sym) = syms.get(symbol) { @@ -271,17 +279,20 @@ fn _help_callback(ast: &Seg, syms: &mut SymTable) -> Result { } else { args_str = sym.args.to_string(); } - println!("NAME: {0}\n + println!( + "NAME: {0}\n ARGS: {1}\n DOCUMENTATION:\n {2}\n CURRENT VALUE AND/OR BODY: -(TODO)", sym.name, args_str, sym.docs); +(TODO)", + sym.name, args_str, sym.docs + ); } else { - return Err("undefined symbol".to_string()) + return Err("undefined symbol".to_string()); } } else { - return Err("help should only be called on a symbol".to_string()) + return Err("help should only be called on a symbol".to_string()); } Ok(Ctr::None) @@ -293,7 +304,7 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result { - if let Ctr::String(ref doc) = *doc_tree.car { + if let Ctr::String(ref doc) = *doc_tree.car { match &*doc_tree.cdr { // define a variable Ctr::Seg(data_tree) if is_var => match eval(&Box::new(data_tree), syms) { @@ -336,7 +347,8 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result Result return Err("have name and doc string, but no body.".to_string()) + _ => return Err("have name and doc string, but no body.".to_string()), } } else { - return Err("doc string is a required argument".to_string()) + return Err("doc string is a required argument".to_string()); } - }, + } // undefine a symbol Ctr::None => { @@ -379,12 +393,12 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result return Err("arguments not in standard form".to_string()), } } else { - return Err("first argument to export must be a symbol".to_string()) + return Err("first argument to export must be a symbol".to_string()); } Ok(Ctr::None) } diff --git a/src/sym.rs b/src/sym.rs index 748ec54..034e8b8 100644 --- a/src/sym.rs +++ b/src/sym.rs @@ -18,8 +18,8 @@ use crate::eval::eval; use crate::segment::{Ctr, Seg, Type}; use std::collections::HashMap; -use std::rc::Rc; use std::fmt; +use std::rc::Rc; #[derive(Clone)] pub struct SymTable(HashMap); diff --git a/tests/test_eval.rs b/tests/test_eval.rs index 44a4593..0f147cd 100644 --- a/tests/test_eval.rs +++ b/tests/test_eval.rs @@ -7,7 +7,7 @@ mod eval_tests { let test_doc = "(1 2)".to_string(); let mut syms = SymTable::new(); let doc_tree = lex(&test_doc).unwrap(); - let reduced = *eval(&doc_tree, &mut syms).unwrap(); + let reduced = *eval(&doc_tree, &mut syms).unwrap(); assert_eq!(reduced.to_string(), test_doc); } @@ -16,9 +16,8 @@ mod eval_tests { let test_doc = "(1 (1 2 3 4 5) 5)".to_string(); let mut syms = SymTable::new(); let doc_tree = lex(&test_doc).unwrap(); - let reduced = *eval(&doc_tree, &mut syms).unwrap(); + let reduced = *eval(&doc_tree, &mut syms).unwrap(); assert_eq!(reduced.to_string(), test_doc); - } #[test] @@ -43,7 +42,7 @@ mod eval_tests { syms.insert(String::from("echo"), test_external_func); let doc_tree = lex(&test_doc).unwrap(); - let reduced = *eval(&doc_tree, &mut syms).unwrap(); + let reduced = *eval(&doc_tree, &mut syms).unwrap(); assert_eq!(reduced.to_string(), output); } @@ -69,7 +68,7 @@ mod eval_tests { syms.insert(String::from("echo"), test_external_func); let doc_tree = lex(&test_doc).unwrap(); - let reduced = *eval(&doc_tree, &mut syms).unwrap(); + let reduced = *eval(&doc_tree, &mut syms).unwrap(); assert_eq!(reduced.to_string(), output); } diff --git a/tests/test_func.rs b/tests/test_func.rs index 43f1545..f0d2e7c 100644 --- a/tests/test_func.rs +++ b/tests/test_func.rs @@ -25,7 +25,10 @@ mod func_tests { }; let args = Seg::from(Box::new(Ctr::Bool(true)), Box::new(Ctr::None)); syms.insert(String::from("test_func_in"), test_internal_func); - if let Ctr::Bool(b) = *syms.call_symbol(&"test_func_in".to_string(), &args, true).unwrap() { + if let Ctr::Bool(b) = *syms + .call_symbol(&"test_func_in".to_string(), &args, true) + .unwrap() + { assert!(b) } } @@ -51,7 +54,10 @@ mod func_tests { ); syms.insert(String::from("test_func_in"), test_external_func); - if let Ctr::Bool(b) = *syms.call_symbol(&"test_func_in".to_string(), &args, true).unwrap() { + if let Ctr::Bool(b) = *syms + .call_symbol(&"test_func_in".to_string(), &args, true) + .unwrap() + { assert!(b) } } @@ -77,10 +83,13 @@ mod func_tests { ); syms.insert(String::from("echo_2"), test_external_func); - assert_eq!(*syms.call_symbol(&"echo_2".to_string(), &args, true) - .unwrap() - .to_string(), - "'test'".to_string()); + assert_eq!( + *syms + .call_symbol(&"echo_2".to_string(), &args, true) + .unwrap() + .to_string(), + "'test'".to_string() + ); } #[test] @@ -122,10 +131,12 @@ mod func_tests { let args = Seg::from(Box::new(Ctr::Bool(true)), Box::new(Ctr::None)); syms.insert(String::from("test_inner"), inner_func); syms.insert(String::from("test_outer"), outer_func); - assert_eq!(syms.call_symbol(&"test_outer".to_string(), &args, true) - .unwrap() - .to_string(), - "'test'".to_string()); + assert_eq!( + syms.call_symbol(&"test_outer".to_string(), &args, true) + .unwrap() + .to_string(), + "'test'".to_string() + ); } #[test] @@ -241,8 +252,7 @@ mod func_tests { syms.call_symbol(&"test_func_in".to_string(), &args, true) .err() .unwrap(), - "error in call to undefined-symbol: undefined symbol: undefined-symbol" - .to_string(), + "error in call to undefined-symbol: undefined symbol: undefined-symbol".to_string(), ); } } diff --git a/tests/test_lex.rs b/tests/test_lex.rs index faa1e4a..5b01bae 100644 --- a/tests/test_lex.rs +++ b/tests/test_lex.rs @@ -4,86 +4,59 @@ mod lex_tests { #[test] fn test_lex_basic_pair() { let document = String::from("(hello 'world')"); - assert_eq!( - lex(&document).unwrap().to_string(), - document - ); + assert_eq!(lex(&document).unwrap().to_string(), document); } #[test] fn test_lex_basic_list() { let document = String::from("(hello 'world' 1 2 3)"); - assert_eq!( - lex(&document).unwrap().to_string(), - document - ); + assert_eq!(lex(&document).unwrap().to_string(), document); } #[test] fn test_lex_complex_list() { let document = String::from("(hello 'world' (1 2 (1 2 3)) 1 2 3)"); - assert_eq!( - lex(&document).unwrap().to_string(), - document - ); + assert_eq!(lex(&document).unwrap().to_string(), document); } #[test] fn test_bad_symbol() { let document = String::from("(as;dd)"); let output: &str = "Problem lexing document: \"Unparsable token: as;dd\""; - assert_eq!( - lex(&document).err().unwrap(), - output.to_string(), - ); + assert_eq!(lex(&document).err().unwrap(), output.to_string(),); } #[test] fn test_list_delim_in_str() { let document = String::from("('(')"); - assert_eq!( - lex(&document).unwrap().to_string(), - document - ); + assert_eq!(lex(&document).unwrap().to_string(), document); } #[test] fn test_empty_string() { let document = String::from("('')"); - assert_eq!( - lex(&document).unwrap().to_string(), - document - ); + assert_eq!(lex(&document).unwrap().to_string(), document); } #[test] fn test_unmatched_list_delim_flat() { let document = String::from("(one two"); let output: &str = "Problem lexing document: \"Unmatched list delimiter in input\""; - assert_eq!( - lex(&document).err().unwrap(), - output.to_string(), - ); + assert_eq!(lex(&document).err().unwrap(), output.to_string(),); } #[test] fn test_unmatched_list_delim_complex() { let document = String::from("(one two (three)"); let output: &str = "Problem lexing document: \"Unmatched list delimiter in input\""; - assert_eq!( - lex(&document).err().unwrap(), - output.to_string(), - ); + assert_eq!(lex(&document).err().unwrap(), output.to_string(),); } #[test] fn test_comment() { let document = String::from("#!/bin/relish\n(one two)"); let output: &str = "(one two)"; - assert_eq!( - lex(&document).unwrap().to_string(), - output.to_string(), - ); + assert_eq!(lex(&document).unwrap().to_string(), output.to_string(),); } #[test] @@ -91,30 +64,20 @@ mod lex_tests { let document = String::from("#!/bin/relish\n((one two)# another doc comment\n(three four))"); let output: &str = "((one two) (three four))"; - assert_eq!( - lex(&document).unwrap().to_string(), - output.to_string(), - ); + assert_eq!(lex(&document).unwrap().to_string(), output.to_string(),); } #[test] fn test_inline_comment() { let document = String::from("#!/bin/relish\n((one two)\n# another doc comment\nthree)"); let output: &str = "((one two) three)"; - assert_eq!( - lex(&document).unwrap().to_string(), - output.to_string(), - ); - + assert_eq!(lex(&document).unwrap().to_string(), output.to_string(),); } #[test] fn test_bad_token_list() { let document = String::from("(one t(wo)"); let output: &str = "Problem lexing document: \"list started in middle of another token\""; - assert_eq!( - lex(&document).err().unwrap(), - output.to_string(), - ); + assert_eq!(lex(&document).err().unwrap(), output.to_string(),); } } diff --git a/tests/test_lib_append.rs b/tests/test_lib_append.rs index 0b83366..919ea68 100644 --- a/tests/test_lib_append.rs +++ b/tests/test_lib_append.rs @@ -11,7 +11,9 @@ mod append_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -26,7 +28,9 @@ mod append_lib_tests { dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -41,7 +45,9 @@ mod append_lib_tests { dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -56,7 +62,9 @@ mod append_lib_tests { dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -71,7 +79,9 @@ mod append_lib_tests { dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } diff --git a/tests/test_lib_bools.rs b/tests/test_lib_bools.rs index 10eb09b..87b9ea8 100644 --- a/tests/test_lib_bools.rs +++ b/tests/test_lib_bools.rs @@ -10,7 +10,9 @@ mod bool_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -23,7 +25,9 @@ mod bool_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -36,7 +40,9 @@ mod bool_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -49,10 +55,11 @@ mod bool_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); - } #[test] @@ -63,10 +70,11 @@ mod bool_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); - } #[test] @@ -77,7 +85,9 @@ mod bool_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -90,7 +100,9 @@ mod bool_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } diff --git a/tests/test_lib_control.rs b/tests/test_lib_control.rs index 5e6d563..5e852d2 100644 --- a/tests/test_lib_control.rs +++ b/tests/test_lib_control.rs @@ -10,7 +10,9 @@ mod control_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -23,7 +25,9 @@ mod control_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -35,8 +39,10 @@ mod control_lib_tests { let mut syms = SymTable::new(); static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); - assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + assert_eq!( + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -52,7 +58,9 @@ mod control_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -65,7 +73,9 @@ mod control_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); } @@ -83,7 +93,9 @@ mod control_lib_tests { static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(), + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), result.to_string(), ); }