whenever_parser/lib.rs
1pub mod lexer;
2pub mod ast;
3pub mod parser;
4
5/// Turn the input into an AST.
6///
7/// Returns the root of the AST, an `ast::Line` struct.
8///
9/// # Errors
10///
11/// Will return an description of the error and a slice of the input where the
12/// error happened:
13/// * input could not be tokenized (see `lexer::eat`)
14/// * a token that was not expected in that context was found
15/// * an `ast::Line` could have been built but there were remaining tokens
16pub fn parse_line<'a>(line: &'a str)
17 -> Result<ast::Line<'a>, (String, &'a str)>
18{
19 let cursor0 = line;
20
21 let (line, cursor1) = parser::eat_line(cursor0)?;
22
23 let (token1, _) = lexer::eat(cursor1)?;
24 match token1.variant
25 {
26 lexer::TokenVariant::EOI => Ok(line),
27 _ => Err((String::from("Expected end of input"), token1.tok))
28 }
29}