Skip to content

Commit decadaa

Browse files
authored
Merge pull request #46 from LunaStev/feature/ast
Add Basic CLI Functionality and Semicolon Support
2 parents de7d66c + 3b7e435 commit decadaa

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod lexer;
22
mod parser;
33
mod error;
44

5-
use std::fs;
5+
use std::{env, fs, process};
66
use lexer::{Lexer, Token};
77
use crate::lexer::TokenType;
88
use crate::parser::{extract_body, extract_parameters, function};
@@ -42,7 +42,22 @@ fn format_ast(ast: &AST) -> String {
4242
*/
4343

4444
fn main() {
45-
let code = fs::read_to_string("test/test.wave").expect("Failed to read the file");
45+
let args: Vec<String> = env::args().collect();
46+
47+
if args.len() < 2 {
48+
eprintln!("Usage: {} <path_to_wave_file>", args[0]);
49+
process::exit(1);
50+
}
51+
52+
let file_path = &args[1];
53+
54+
let code = match fs::read_to_string(file_path) {
55+
Ok(content) => content,
56+
Err(err) => {
57+
eprintln!("Error reading file {}: {}", file_path, err);
58+
process::exit(1);
59+
}
60+
};
4661

4762
let mut lexer = Lexer::new(code.as_str());
4863

@@ -61,5 +76,5 @@ fn main() {
6176

6277
let ast = function(function_name, params, body);
6378

64-
eprintln!("AST: {:?}", &ast)
79+
eprintln!("AST: {:?}", &ast);
6580
}

0 commit comments

Comments
 (0)