]>
Witch of Git - ivy/blob - src/main.rs
1 use ess
::{self, parser
::ParseError
, Sexp
};
2 use std
::io
::{self, Read
};
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));
15 static BUILTINS
: &[&str] = &[
16 "true", "false", "<", ">", "<=", ">=", "==", "!=", "+", "-", "*", "/", "%",
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
) {
26 println
!("{:?}", err
);
27 std
::process
::exit(1);
30 let (ast
, builtins
) = match Ast
::parse(BUILTINS
, &sexp
) {
34 std
::process
::exit(1);
37 println
!("builtins: {:?}", builtins
);
38 println
!("{}", ast
.to_doc().pretty(80));