able-script/src/main.rs
Alexander Bethel eccc00ff81 Implement basic interpreter
Added code for interpreting parsed AbleScript expressions and
statements, and hooked it up to the REPL.
2021-05-20 18:18:01 -05:00

61 lines
1.5 KiB
Rust

#![forbid(unsafe_code)]
mod base_55;
mod brian;
mod error;
mod interpret;
mod lexer;
mod parser;
mod repl;
mod variables;
use clap::{App, Arg};
use logos::Source;
use parser::Parser;
fn main() {
// variables::test(); // NOTE(Able): Add this as a test case
let matches = App::new("AbleScript")
.version(env!("CARGO_PKG_VERSION"))
.author("Able <abl3theabove@gmail.com>")
.about("AbleScript interpreter")
.arg(
Arg::with_name("file")
.short("f")
.long("file")
.value_name("FILE")
.help("Set the path to interpret from")
.takes_value(true),
)
.get_matches();
match matches.value_of("file") {
Some(file_path) => {
// Read file
let source = std::fs::read_to_string(file_path).unwrap();
// Parse
let mut parser = Parser::new(&source);
let ast = parser.init();
match ast {
Ok(ast) => println!("{:#?}", ast),
Err(e) => {
println!(
"Error `{:?}` occured at span: {:?} = `{:?}`",
e.kind,
e.position.clone(),
source.slice(e.position)
);
}
}
}
None => {
println!(
"Hi [AbleScript {}] - AST Printer & Interpreter",
env!("CARGO_PKG_VERSION")
);
repl::repl();
}
}
}