2021-04-18 09:39:43 -05:00
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
|
2021-04-11 13:22:59 -05:00
|
|
|
mod base_55;
|
2021-05-04 22:23:17 -05:00
|
|
|
mod brian;
|
2021-04-18 15:33:55 -05:00
|
|
|
mod error;
|
2021-05-20 18:18:01 -05:00
|
|
|
mod interpret;
|
2021-04-28 15:52:19 -05:00
|
|
|
mod lexer;
|
2021-04-11 15:11:23 -05:00
|
|
|
mod parser;
|
2021-05-01 06:44:58 -05:00
|
|
|
mod repl;
|
2021-04-13 18:01:19 -05:00
|
|
|
mod variables;
|
2021-04-11 17:22:06 -05:00
|
|
|
|
2021-04-13 10:43:54 -05:00
|
|
|
use clap::{App, Arg};
|
2021-05-25 13:26:01 -05:00
|
|
|
use interpret::ExecEnv;
|
2021-05-02 08:43:25 -05:00
|
|
|
use logos::Source;
|
2021-04-18 09:39:43 -05:00
|
|
|
use parser::Parser;
|
2021-05-03 19:33:21 -05:00
|
|
|
|
2021-04-08 16:11:20 -05:00
|
|
|
fn main() {
|
2021-05-05 07:33:40 -05:00
|
|
|
// variables::test(); // NOTE(Able): Add this as a test case
|
2021-04-11 14:11:39 -05:00
|
|
|
let matches = App::new("AbleScript")
|
|
|
|
.version(env!("CARGO_PKG_VERSION"))
|
2021-04-11 11:47:35 -05:00
|
|
|
.author("Able <abl3theabove@gmail.com>")
|
2021-05-01 06:44:58 -05:00
|
|
|
.about("AbleScript interpreter")
|
2021-04-11 11:47:35 -05:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("file")
|
|
|
|
.short("f")
|
|
|
|
.long("file")
|
|
|
|
.value_name("FILE")
|
2021-04-11 15:11:23 -05:00
|
|
|
.help("Set the path to interpret from")
|
2021-04-11 11:47:35 -05:00
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.get_matches();
|
2021-04-13 18:01:19 -05:00
|
|
|
|
2021-04-11 11:47:35 -05:00
|
|
|
match matches.value_of("file") {
|
|
|
|
Some(file_path) => {
|
2021-04-12 13:20:45 -05:00
|
|
|
// Read file
|
|
|
|
let source = std::fs::read_to_string(file_path).unwrap();
|
|
|
|
|
2021-04-18 09:39:43 -05:00
|
|
|
// Parse
|
|
|
|
let mut parser = Parser::new(&source);
|
2021-04-26 03:44:42 -05:00
|
|
|
let ast = parser.init();
|
2021-05-02 08:43:25 -05:00
|
|
|
match ast {
|
2021-05-20 18:24:18 -05:00
|
|
|
Ok(ast) => {
|
|
|
|
println!("{:#?}", ast);
|
2021-05-25 13:26:01 -05:00
|
|
|
let mut env = ExecEnv::new();
|
|
|
|
println!("{:?}", env.eval_items(&ast));
|
2021-05-20 18:24:18 -05:00
|
|
|
}
|
2021-05-02 08:43:25 -05:00
|
|
|
Err(e) => {
|
|
|
|
println!(
|
2021-06-05 08:50:20 -05:00
|
|
|
"Error `{:?}` occurred at span: {:?} = `{:?}`",
|
2021-05-02 08:43:25 -05:00
|
|
|
e.kind,
|
|
|
|
e.position.clone(),
|
|
|
|
source.slice(e.position)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-04-11 11:47:35 -05:00
|
|
|
}
|
|
|
|
None => {
|
2021-05-01 17:39:08 -05:00
|
|
|
println!(
|
2021-05-20 18:18:01 -05:00
|
|
|
"Hi [AbleScript {}] - AST Printer & Interpreter",
|
2021-05-01 17:39:08 -05:00
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
);
|
2021-05-01 06:44:58 -05:00
|
|
|
repl::repl();
|
2021-04-11 11:47:35 -05:00
|
|
|
}
|
2021-04-08 16:11:20 -05:00
|
|
|
}
|
|
|
|
}
|