forked from AbleScript/ablescript
Add --debug
option for printing AST
This commit is contained in:
parent
151564b718
commit
e45df2efe7
19
src/main.rs
19
src/main.rs
|
@ -31,8 +31,15 @@ fn main() {
|
|||
.help("Set the path to interpret from")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("debug")
|
||||
.long("debug")
|
||||
.help("Enable debug AST printing"),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let ast_print = matches.is_present("debug");
|
||||
|
||||
match matches.value_of("file") {
|
||||
Some(file_path) => {
|
||||
// Read file
|
||||
|
@ -46,10 +53,12 @@ fn main() {
|
|||
|
||||
// Parse & evaluate
|
||||
let mut parser = Parser::new(&source);
|
||||
if let Err(e) = parser
|
||||
.init()
|
||||
.and_then(|ast| ExecEnv::new().eval_stmts(&ast))
|
||||
{
|
||||
if let Err(e) = parser.init().and_then(|ast| {
|
||||
if ast_print {
|
||||
println!("{:#?}", ast);
|
||||
}
|
||||
ExecEnv::new().eval_stmts(&ast)
|
||||
}) {
|
||||
println!(
|
||||
"Error `{:?}` occurred at span: {:?} = `{:?}`",
|
||||
e.kind,
|
||||
|
@ -60,7 +69,7 @@ fn main() {
|
|||
}
|
||||
None => {
|
||||
println!("Hi [AbleScript {}]", env!("CARGO_PKG_VERSION"));
|
||||
repl::repl();
|
||||
repl::repl(ast_print);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use rustyline::Editor;
|
|||
|
||||
use crate::{interpret::ExecEnv, parser::Parser};
|
||||
|
||||
pub fn repl() {
|
||||
pub fn repl(ast_print: bool) {
|
||||
let mut rl = Editor::<()>::new();
|
||||
let mut env = ExecEnv::new();
|
||||
loop {
|
||||
|
@ -16,7 +16,9 @@ pub fn repl() {
|
|||
}
|
||||
let mut parser = Parser::new(&line);
|
||||
let value = parser.init().and_then(|ast| {
|
||||
// println!("{:?}", &ast);
|
||||
if ast_print {
|
||||
println!("{:#?}", &ast);
|
||||
}
|
||||
env.eval_stmts(&ast)
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue