]>
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] = &["true", "false", "<", ">", "<=", ">=", "==", "!=", "+", "-", "*", "/", "%"];
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
) {
24 println
!("{:?}", err
);
25 std
::process
::exit(1);
28 let (ast
, builtins
) = match Ast
::parse(BUILTINS
, &sexp
) {
32 std
::process
::exit(1);
35 println
!("builtins: {:?}", builtins
);
36 println
!("{:#?}", ast
);