mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
feat: args handling
This commit is contained in:
parent
252a8aae33
commit
9e8c9e72dd
1
example/hello_world.vy
Normal file
1
example/hello_world.vy
Normal file
|
@ -0,0 +1 @@
|
||||||
|
(print '(Hello, World!))
|
48
src/main.rs
48
src/main.rs
|
@ -1,13 +1,45 @@
|
||||||
|
use std::{process::exit, fs::read_to_string};
|
||||||
|
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
|
|
||||||
fn main() {
|
const EXECUTABLE_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
let src = r#"
|
|
||||||
(print "Hello, World!")
|
|
||||||
(print '(hello, world!))
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let parsed = parser::parse(src);
|
fn main() {
|
||||||
for result in parsed {
|
let args = std::env::args().collect::<Vec<String>>();
|
||||||
println!("{:?}", result);
|
let mut args_index: usize = 0;
|
||||||
|
match args.len() {
|
||||||
|
// No argument provided
|
||||||
|
1 => { display_help(1); },
|
||||||
|
_ => {
|
||||||
|
while args.len() > args_index {
|
||||||
|
let arg: &str = &args[args_index];
|
||||||
|
match arg {
|
||||||
|
"-h" | "--help" => { display_help(0); },
|
||||||
|
"-v" | "--version" => {
|
||||||
|
println!("{} version {}", EXECUTABLE_NAME, env!("CARGO_PKG_VERSION"));
|
||||||
|
exit(0);
|
||||||
|
},
|
||||||
|
"-c" | "--compile" => {
|
||||||
|
args_index += 1;
|
||||||
|
if args_index < args.len() {
|
||||||
|
let file_path: &str = &args[args_index];
|
||||||
|
let file_content: String = read_to_string(file_path).unwrap();
|
||||||
|
let ast = parser::parse(&file_content);
|
||||||
|
for node in ast {
|
||||||
|
println!("{:?}", node);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
display_help(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => { args_index += 1; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn display_help(exit_code: i32) {
|
||||||
|
println!("Usage: {} <file>", EXECUTABLE_NAME);
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
Loading…
Reference in a new issue