]> Witch of Git - ivy/blob - src/main.rs
An s-expression parser and an example program
[ivy] / src / main.rs
1 use ess::{self, Sexp, parser::ParseError};
2 use std::io::{self, Read};
3
4 fn parse(input: &str) -> Result<Sexp, ParseError> {
5 let (sexp, rest) = ess::parse_one(input)?;
6 if !rest.trim().is_empty() {
7 return Err(ParseError::Unexpected('\0', sexp.get_loc().1));
8 }
9 Ok(sexp)
10 }
11
12 fn main() -> io::Result<()> {
13 let stdin = std::io::stdin();
14 let mut text = String::new();
15 stdin.lock().read_to_string(&mut text)?;
16 let item = match parse(&text) {
17 Ok(item) => item,
18 Err(err) => {
19 println!("{:?}", err);
20 std::process::exit(1);
21 }
22 };
23 println!("{:?}", item);
24 Ok(())
25 }