Skip to content

Commit ca8aebe

Browse files
committed
init
0 parents  commit ca8aebe

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

Diff for: Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "rlox"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

Diff for: src/lib.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use ::std::{error::Error, fs, process};
2+
3+
pub fn handle_error(err: String) {
4+
eprintln!("{}", err);
5+
process::exit(1);
6+
}
7+
8+
pub fn run_prompt() {
9+
todo!();
10+
}
11+
12+
pub fn run_file(arg: &str) -> Result<(), Box<dyn Error>> {
13+
let content = fs::read_to_string(arg)?;
14+
dbg!(content);
15+
Ok(())
16+
}

Diff for: src/main.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::env;
2+
3+
use rlox::{handle_error, run_file, run_prompt};
4+
5+
fn main() {
6+
let arg: Vec<String> = env::args().collect();
7+
8+
match arg.len() {
9+
1 => run_prompt(),
10+
2 => run_file(&arg[1]).unwrap_or_else(|err| {
11+
handle_error(err.to_string());
12+
}),
13+
_ => {
14+
handle_error("Usage: rlox [script]".to_string());
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)