]> Witch of Git - ivy/blob - src/main.rs
Add support for globals which don't get captured
[ivy] / src / main.rs
1 use ess::{self, parser::ParseError, Sexp};
2 use std::io::{self, Read};
3
4 mod ast;
5 use ast::Ast;
6
7 fn parse(input: &str) -> Result<Sexp, ParseError> {
8 let (sexp, rest) = ess::parse_one(input)?;
9 if !rest.trim().is_empty() {
10 return Err(ParseError::Unexpected('\0', sexp.get_loc().1));
11 }
12 Ok(sexp)
13 }
14
15 static BUILTINS: &[&str] = &["true", "false", "<", ">", "<=", ">=", "==", "!=", "+", "-", "*", "/", "%"];
16
17 fn main() -> io::Result<()> {
18 let stdin = std::io::stdin();
19 let mut text = String::new();
20 stdin.lock().read_to_string(&mut text)?;
21 let sexp = match parse(&text) {
22 Ok(item) => item,
23 Err(err) => {
24 println!("{:?}", err);
25 std::process::exit(1);
26 }
27 };
28 let (ast, builtins) = match Ast::parse(BUILTINS, &sexp) {
29 Ok(ast) => ast,
30 Err(err) => {
31 println!("{}", err);
32 std::process::exit(1);
33 }
34 };
35 println!("builtins: {:?}", builtins);
36 println!("{:#?}", ast);
37 Ok(())
38 }