diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/casual.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/bin/casual.rs b/src/bin/casual.rs new file mode 100644 index 0000000..828c4b6 --- /dev/null +++ b/src/bin/casual.rs @@ -0,0 +1,65 @@ +use std::env; +use std::path::Path; + +use casual::{repl, sexpr_parse_file}; + +fn usage() { + println!("usage:\tcasual [-h] [-v] [--no-repl] [<files>]"); + println!(""); + println!("Files will be loaded in order, then drop to REPL (unless \"--no-repl\" is passed)."); + println!( + "Verbose flag (\"-v\") will result in lexed tokens and parsed AST \ + being dumped to stdout (when on REPL)." + ); +} + +fn main() { + let mut verbose: bool = false; + let mut no_repl: bool = false; + + let mut file_list = Vec::<String>::new(); + + for arg in env::args().skip(1) { + match &*arg { + "-v" | "--verbose" => { + verbose = true; + } + "--no-repl" => { + no_repl = true; + } + "-h" | "--help" => { + usage(); + return; + } + _ if arg.starts_with("-") => { + println!("Unknown option: {}", arg); + println!(""); + usage(); + return; + } + _ => { + file_list.push(arg.clone()); + } + } + } + + for fname in file_list { + let fpath = Path::new(&fname); + if !fpath.is_file() { + println!("File not found (or not file): {}", fname); + return; + } + println!("Loading {}...", fname); + match sexpr_parse_file(&fpath) { + Err(e) => { + println!("Error loading file: {}\n {}", fname, e); + return; + } + Ok(_) => (), + } + } + + if !no_repl { + repl(verbose); + } +} |