The top-level parser for a PRQL file
()
| 18 | |
| 19 | /// The top-level parser for a PRQL file |
| 20 | pub fn source<'a, I>() -> impl Parser<'a, I, Vec<Stmt>, ParserError<'a>> + Clone |
| 21 | where |
| 22 | I: Input<'a, Token = lr::Token, Span = Span> + BorrowInput<'a> + chumsky::input::ValueInput<'a>, |
| 23 | { |
| 24 | with_doc_comment(query_def()) |
| 25 | .or_not() |
| 26 | .map(|opt| opt.into_iter().collect::<Vec<_>>()) |
| 27 | .then(module_contents()) |
| 28 | .map(|(mut first, mut second)| { |
| 29 | first.append(&mut second); |
| 30 | first |
| 31 | }) |
| 32 | // This is the only instance we can consume newlines at the end of something, since |
| 33 | // this is the end of the file |
| 34 | .then_ignore(new_line().repeated().collect::<Vec<_>>()) |
| 35 | .then_ignore(end()) |
| 36 | .boxed() |
| 37 | } |
| 38 | |
| 39 | fn module_contents<'a, I>() -> impl Parser<'a, I, Vec<Stmt>, ParserError<'a>> + Clone |
| 40 | where |