]>
Witch of Git - ivy/blob - src/main.rs
1 use ess
::{self, parser
::ParseError
, Sexp
};
2 use std
::io
::{self, Read
};
10 fn parse(input
: &str) -> Result
<Sexp
, ParseError
> {
11 let (sexp
, rest
) = ess
::parse_one(input
)?
;
12 if !rest
.trim().is
_empty
() {
13 return Err(ParseError
::Unexpected('
\0'
, sexp
.get_loc().1));
18 static BUILTINS
: &[&str] = &[
19 "debug", "true", "false", "<", ">", "<=", ">=", "==", "!=", "+", "-", "*", "/", "%",
22 fn main() -> io
::Result
<()> {
23 let stdin
= std
::io
::stdin();
24 let mut text
= String
::new();
25 stdin
.lock().read_to_string(&mut text
)?
;
26 let sexp
= match parse(&text
) {
29 println
!("{:?}", err
);
30 std
::process
::exit(1);
33 let (ast
, builtins
) = match Ast
::parse(BUILTINS
, &sexp
) {
37 std
::process
::exit(1);
40 let code
= match translate(&ast
) {
44 std
::process
::exit(1);
47 println
!("{:#?}", code
);