generated from stackclass/interpreter
Initial commit
This commit is contained in:
35
src/main.rs
Normal file
35
src/main.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() < 3 {
|
||||
eprintln!("Usage: {} tokenize <filename>", args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
let command = &args[1];
|
||||
let filename = &args[2];
|
||||
|
||||
match command.as_str() {
|
||||
"tokenize" => {
|
||||
// You can use print statements as follows for debugging, they'll be visible when running tests.
|
||||
eprintln!("Logs from your program will appear here!");
|
||||
|
||||
let file_contents = fs::read_to_string(filename).unwrap_or_else(|_| {
|
||||
eprintln!("Failed to read file {filename}");
|
||||
String::new()
|
||||
});
|
||||
|
||||
// Uncomment this block to pass the first stage
|
||||
// if !file_contents.is_empty() {
|
||||
// panic!("Scanner not implemented");
|
||||
// } else {
|
||||
// println!("EOF null"); // Placeholder, replace this line when implementing the scanner
|
||||
// }
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Unknown command: {command}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user