Initial commit

This commit is contained in:
2024-03-26 22:32:37 +01:00
parent 2e5c7a4803
commit 873c1261d3
3 changed files with 56 additions and 0 deletions

47
src/main.rs Normal file
View File

@@ -0,0 +1,47 @@
use std::env;
use std::fs;
use std::io;
use std::io::Write;
fn main() {
let args: Vec<String> = env::args().collect();
match args.len() {
1 => run_prompt(),
2 => run_file(&args[1]),
_ => {
println!("Usage : rlox [script]");
}
}
}
fn run_file( file_path: &str ) {
let contents = fs::read_to_string(file_path)
.expect(&format!("Should have been able to read the file {file_path}"));
run(contents);
}
fn run_prompt() {
loop {
print!("> ");
io::stdout().flush().expect("Unable to flush stdout");
let mut line = String::new();
io::stdin()
.read_line(&mut line)
.expect("Failed to read line");
if line.trim().is_empty() {
break;
}
run(line);
}
}
fn run( _script: String ) {
}
// http://www.craftinginterpreters.com/scanning.html#error-handling