progress on setting up def parser for top level defs

This commit is contained in:
Anton-4 2021-08-16 20:05:21 +02:00
parent 435789b807
commit 5023fa3e75
8 changed files with 107 additions and 21 deletions

View file

@ -1,8 +1,11 @@
use crate::ast;
use crate::module::module_defs;
// use crate::module::module_defs;
use crate::parser::{State, SyntaxError};
use bumpalo::Bump;
use bumpalo::collections::Vec as BumpVec;
use roc_region::all::Located;
use crate::parser::Parser;
pub fn parse_expr_with<'a>(
arena: &'a Bump,
@ -23,3 +26,15 @@ pub fn parse_loc_with<'a>(
Err(fail) => Err(SyntaxError::Expr(fail)),
}
}
pub fn parse_defs_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<BumpVec<'a, Located<ast::Def<'a>>>, SyntaxError<'a>> {
let state = State::new(input.trim().as_bytes());
match module_defs().parse(arena, state) {
Ok(tuple) => Ok(tuple.1),
Err(tuple) => Err(tuple.1),
}
}