Skip to content

Commit

Permalink
parse command-line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
generic-github-user committed Sep 26, 2022
1 parent ea940a1 commit be31f09
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 3 deletions.
154 changes: 154 additions & 0 deletions shell-1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions shell-1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"

[dependencies]
chrono = "0.4"
clap = { version = "3.2", features = ["derive"] }
23 changes: 21 additions & 2 deletions shell-1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::io;
use std::io::Write;
use std::env::args;
use std::time::SystemTime;
use chrono::{DateTime, Utc};
use clap::Parser;

mod lexer;
mod parser;
Expand All @@ -14,10 +16,23 @@ use lexer::lex;
use parser::parse;
use node::Node;

#[derive(Parser, Debug)]
#[clap(version, about)]
struct Args {
#[clap(short, long, value_parser, default_value="")]
path: String,

// #[clap(short, long, default_value_t=false)]
#[clap(short, long, action)]
debug: bool
}

fn main() {
let mut input = String::new();
// let now = SystemTime::now();
let now = Utc::now();
let args = Args::parse();
println!("{:#?}", args);
println!("shell-1 | {}", now);
loop {
print!("~ ");
Expand All @@ -26,10 +41,14 @@ fn main() {
io::stdin().read_line(&mut input).unwrap();

let tokens = lex(input.clone(), false).unwrap();
println!("{:?}", tokens);
if args.debug {
println!("{:#?}", tokens);
}

let tree: Node = parse(tokens, false);
println!("{:?}", tree);
if args.debug {
println!("{:#?}", tree);
}

println!("{}", tree.evaluate().unwrap());
}
Expand Down
2 changes: 1 addition & 1 deletion shell-1/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn parse(tokens: Vec<Token>, verbose: bool) -> Node {
"}" => {
stack.pop();
},
_ => todo!()
_ => todo!("{:?}", token.content)
}
}
CharType::Newline | CharType::Whitespace | CharType::None => (),
Expand Down

0 comments on commit be31f09

Please sign in to comment.