@@ -2,7 +2,7 @@ mod lexer;
22mod parser;
33mod error;
44
5- use std:: fs ;
5+ use std:: { env , fs , process } ;
66use lexer:: { Lexer , Token } ;
77use crate :: lexer:: TokenType ;
88use crate :: parser:: { extract_body, extract_parameters, function} ;
@@ -42,7 +42,22 @@ fn format_ast(ast: &AST) -> String {
4242 */
4343
4444fn 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