mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
refactor: Nil, more helpful help
This commit is contained in:
parent
9e8c9e72dd
commit
1859a9c4bb
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -3,5 +3,5 @@
|
|||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "vy"
|
||||
name = "vyc"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "vy"
|
||||
name = "vyc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -3,13 +3,24 @@ use std::{process::exit, fs::read_to_string};
|
|||
pub mod parser;
|
||||
|
||||
const EXECUTABLE_NAME: &str = env!("CARGO_PKG_NAME");
|
||||
const HELP_MESSAGE: &str = "\
|
||||
-h, --help
|
||||
Print this help message and exit.
|
||||
-v, --version
|
||||
Print version information and exit.
|
||||
-c FILE, --compile FILE
|
||||
Compile the given file and exit.\
|
||||
";
|
||||
|
||||
fn main() {
|
||||
let args = std::env::args().collect::<Vec<String>>();
|
||||
let mut args_index: usize = 0;
|
||||
match args.len() {
|
||||
// No argument provided
|
||||
1 => { display_help(1); },
|
||||
1 => {
|
||||
println!("No argument provided.");
|
||||
display_help(1);
|
||||
},
|
||||
_ => {
|
||||
while args.len() > args_index {
|
||||
let arg: &str = &args[args_index];
|
||||
|
@ -29,6 +40,7 @@ fn main() {
|
|||
println!("{:?}", node);
|
||||
}
|
||||
} else {
|
||||
println!("No file provided.");
|
||||
display_help(1);
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +52,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn display_help(exit_code: i32) {
|
||||
println!("Usage: {} <file>", EXECUTABLE_NAME);
|
||||
println!("Usage: {} [OPTIONS]", EXECUTABLE_NAME);
|
||||
println!("{}", HELP_MESSAGE);
|
||||
exit(exit_code);
|
||||
}
|
|
@ -10,6 +10,10 @@ pub struct List {
|
|||
pub value: Option<Rc<RefCell<Cons>>>,
|
||||
}
|
||||
|
||||
impl List {
|
||||
pub const NIL: List = List { value: None };
|
||||
}
|
||||
|
||||
/// Cons -> (car, [cdr])
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Cons {
|
||||
|
@ -26,10 +30,11 @@ pub enum Value {
|
|||
Int(i64), Float(f64),
|
||||
|
||||
String(String), Symbol(String),
|
||||
|
||||
List(List),
|
||||
}
|
||||
|
||||
Nil,
|
||||
impl Value {
|
||||
pub const NIL: Value = Value::List(List::NIL);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -261,7 +266,7 @@ fn read<'a>(
|
|||
if let Tree::List { vec, quote } = &finished {
|
||||
if vec.is_empty() {
|
||||
finished = Tree::Atom {
|
||||
atom: Value::Nil,
|
||||
atom: Value::NIL,
|
||||
quote: *quote,
|
||||
};
|
||||
}
|
||||
|
@ -300,7 +305,7 @@ fn read_atom(token: &str) -> Value {
|
|||
match lower.as_str() {
|
||||
"true" => Value::True,
|
||||
"false" => Value::False,
|
||||
"nil" => Value::Nil,
|
||||
"nil" => Value::NIL,
|
||||
_ => {
|
||||
// Parse number
|
||||
if let Ok(int) = token.parse::<i64>() { Value::Int(int) }
|
||||
|
|
Loading…
Reference in a new issue