mirror of
https://github.com/MorizzG/rlox.git
synced 2026-02-04 11:54:48 +00:00
rustfmt with nightly options
also some other minor formatting changes
This commit is contained in:
parent
671f7d5306
commit
f8b59e6034
17 changed files with 91 additions and 291 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -19,44 +19,11 @@ struct CliArgs {
|
|||
debug: bool,
|
||||
}
|
||||
|
||||
/*
|
||||
let source_code = std::fs::read_to_string(script_path).unwrap_or_else(|err| {
|
||||
eprintln!("Reading script file {script_path} failed: {err}");
|
||||
std::process::exit(66);
|
||||
}); */
|
||||
|
||||
fn main() {
|
||||
let cli_args = CliArgs::parse();
|
||||
|
||||
if cli_args.vm {
|
||||
unimplemented!()
|
||||
/* use rlox2_vm::LoxError;
|
||||
|
||||
let mut vm = rlox2_vm::VM::default();
|
||||
|
||||
if let Some(file_name) = cli_args.file_name {
|
||||
let source = std::fs::read_to_string(&file_name).unwrap_or_else(|err| {
|
||||
eprintln!("Reading script file {file_name} failed: {err}");
|
||||
std::process::exit(66);
|
||||
});
|
||||
|
||||
if let Err(err) = rlox2_vm::run(&source, &mut vm) {
|
||||
eprintln!("{err}");
|
||||
match err {
|
||||
LoxError::LexerError { .. } | LoxError::CompileError { .. } => {
|
||||
std::process::exit(65)
|
||||
}
|
||||
LoxError::RuntimeError { .. } => std::process::exit(70),
|
||||
LoxError::Exit { exit_code } => std::process::exit(exit_code),
|
||||
}
|
||||
}
|
||||
|
||||
if !cli_args.interactive {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rlox2_vm::run_repl(&mut vm); */
|
||||
} else {
|
||||
use rlox2_interpreter::LoxError;
|
||||
|
||||
|
|
|
|||
33
src/repl.rs
33
src/repl.rs
|
|
@ -151,36 +151,7 @@ pub fn run_repl<F: FnMut(&str) -> LoxResult<E>, E: Error>(mut run: F) {
|
|||
}
|
||||
};
|
||||
|
||||
/* 'inner: loop {
|
||||
let num_open_braces =
|
||||
(input_buf.matches('{').count() as i64) - (input_buf.matches('}').count() as i64);
|
||||
let num_open_parens =
|
||||
(input_buf.matches('(').count() as i64) - (input_buf.matches(')').count() as i64);
|
||||
let num_open_brackets =
|
||||
(input_buf.matches('[').count() as i64) - (input_buf.matches(']').count() as i64);
|
||||
|
||||
// all braces/parens/brackets closed => break
|
||||
if num_open_braces == 0 && num_open_parens == 0 && num_open_brackets == 0 {
|
||||
break 'inner;
|
||||
}
|
||||
|
||||
// any braces/parens/brackets more closing than opening => break (will be parse error)
|
||||
if num_open_braces < 0 || num_open_parens < 0 || num_open_brackets < 0 {
|
||||
break 'inner;
|
||||
}
|
||||
|
||||
match readline.readline("< ") {
|
||||
Ok(line) => {
|
||||
input_buf += &line;
|
||||
}
|
||||
Err(ReadlineError::Interrupted) => continue 'outer,
|
||||
Err(ReadlineError::Eof) => break 'outer,
|
||||
Err(err) => {
|
||||
println!("Error: {:?}", err);
|
||||
continue 'outer;
|
||||
}
|
||||
};
|
||||
} */
|
||||
readline.save_history("/tmp/rlox_history.txt").unwrap();
|
||||
|
||||
if input_buf.is_empty() || input_buf == "exit\n" || input_buf == "quit\n" {
|
||||
std::process::exit(0);
|
||||
|
|
@ -194,6 +165,4 @@ pub fn run_repl<F: FnMut(&str) -> LoxResult<E>, E: Error>(mut run: F) {
|
|||
LoxResult::Exit(exit_code) => std::process::exit(exit_code),
|
||||
}
|
||||
}
|
||||
|
||||
readline.save_history("/tmp/rlox_history.txt").unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue