]> Witch of Git - ivy/blob - src/main.rs
Add a link to the etymology of the language name
[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] = &[
16 "true", "false", "<", ">", "<=", ">=", "==", "!=", "+", "-", "*", "/", "%",
17 ];
18
19 fn main() -> io::Result<()> {
20 let stdin = std::io::stdin();
21 let mut text = String::new();
22 stdin.lock().read_to_string(&mut text)?;
23 let sexp = match parse(&text) {
24 Ok(item) => item,
25 Err(err) => {
26 println!("{:?}", err);
27 std::process::exit(1);
28 }
29 };
30 let (ast, builtins) = match Ast::parse(BUILTINS, &sexp) {
31 Ok(ast) => ast,
32 Err(err) => {
33 println!("{}", err);
34 std::process::exit(1);
35 }
36 };
37 println!("builtins: {:?}", builtins);
38 println!("{}", ast.to_doc().pretty(80));
39 Ok(())
40 }