Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "Wave"
version = "0.1.0"
name = "wave"
version = "0.0.2-pre-alpha"
edition = "2021"

[dependencies]
33 changes: 30 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,42 @@ fn format_ast(ast: &AST) -> String {
}
*/

const VERSION: &str = env!("CARGO_PKG_VERSION");

fn main() {
let args: Vec<String> = env::args().collect();

if args.len() < 2 {
eprintln!("Usage: {} <path_to_wave_file>", args[0]);
eprintln!("Usage: wave <command> [arguments]");
eprintln!("Commands:");
eprintln!(" run <file> Execute the specified Wave file");
eprintln!(" --version Show the CLI version");
process::exit(1);
}

let file_path = &args[1];
match args[1].as_str() {
"--version" => {
println!("v{}", VERSION);
return;
}
"run" => {
if args.len() < 3 {
eprintln!("Usage: wave run <file>");
process::exit(1);
}

let file_path = &args[2];
run_wave_file(file_path);
}
_ => {
eprintln!("Unknown command: {}", args[1]);
eprintln!("Use 'wave --version' or 'wave run <file>'");
process::exit(1);
}
}
}

fn run_wave_file(file_path: &str) {
let code = match fs::read_to_string(file_path) {
Ok(content) => content,
Err(err) => {
Expand All @@ -64,7 +90,8 @@ fn main() {
let tokens = lexer.tokenize();
eprintln!("Tokens: {}", format_tokens(&tokens));

let function_name = tokens.iter()
let function_name = tokens
.iter()
.find(|token| matches!(token.token_type, TokenType::IDENTIFIER(_)))
.map(|token| token.lexeme.clone())
.unwrap_or_default();
Expand Down
Loading