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