Add fuzzing to the parser.

As part of this, todos and panics where moved outside of this module
to elsewhere when they would cause fuzzing to fail.
This commit is contained in:
Brendan Hansknecht 2020-10-30 22:04:54 -07:00
parent ad31975b97
commit d00189530a
16 changed files with 314 additions and 32 deletions

View file

@ -0,0 +1,22 @@
use crate::ast::{self, Attempting};
use crate::blankspace::space0_before;
use crate::expr::expr;
use crate::parser::{loc, Fail, Parser, State};
use bumpalo::Bump;
use roc_region::all::Located;
#[allow(dead_code)]
pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>, Fail> {
parse_loc_with(arena, input).map(|loc_expr| loc_expr.value)
}
#[allow(dead_code)]
pub fn parse_loc_with<'a>(arena: &'a Bump, input: &'a str) -> Result<Located<ast::Expr<'a>>, Fail> {
let state = State::new(input.trim().as_bytes(), Attempting::Module);
let parser = space0_before(loc(expr(0)), 0);
let answer = parser.parse(&arena, state);
answer
.map(|(loc_expr, _)| loc_expr)
.map_err(|(fail, _)| fail)
}