clean up helpers

This commit is contained in:
Folkert 2021-03-12 03:41:01 +01:00
parent b349ae7ab5
commit cba55734cb
8 changed files with 13 additions and 82 deletions

View file

@ -23,7 +23,7 @@ pub fn test_parse_expr<'a>(
min_indent: u16,
arena: &'a bumpalo::Bump,
state: State<'a>,
) -> Result<(Located<Expr<'a>>, State<'a>), EExpr<'a>> {
) -> Result<Located<Expr<'a>>, EExpr<'a>> {
let parser = space0_before_e(
loc!(|a, s| parse_expr_help(min_indent, a, s)),
min_indent,
@ -32,7 +32,7 @@ pub fn test_parse_expr<'a>(
);
match parser.parse(arena, state) {
Ok((_, expression, state)) => Ok((expression, state)),
Ok((_, expression, _)) => Ok(expression),
Err((_, fail, _)) => Err(fail),
}
}

View file

@ -4,7 +4,7 @@ use crate::ident::{lowercase_ident, parse_ident_help, Ident};
use crate::parser::Progress::{self, *};
use crate::parser::{
backtrackable, optional, specialize, specialize_ref, word1, EPattern, PInParens, PRecord,
ParseResult, Parser, State, SyntaxError,
ParseResult, Parser, State,
};
use bumpalo::collections::string::String;
use bumpalo::collections::Vec;
@ -290,10 +290,6 @@ fn loc_ident_pattern_help<'a>(
}
}
pub fn underscore_pattern<'a>() -> impl Parser<'a, Pattern<'a>, SyntaxError<'a>> {
specialize(|e, _, _| SyntaxError::Pattern(e), underscore_pattern_help())
}
fn underscore_pattern_help<'a>() -> impl Parser<'a, Pattern<'a>, EPattern<'a>> {
move |arena: &'a Bump, state: State<'a>| {
let (_, _, next_state) = word1(b'_', EPattern::Underscore).parse(arena, state)?;
@ -318,13 +314,6 @@ fn lowercase_ident_pattern<'a>(
specialize(move |_, _, _| EPattern::End(row, col), lowercase_ident()).parse(arena, state)
}
pub fn record_pattern<'a>(min_indent: u16) -> impl Parser<'a, Pattern<'a>, SyntaxError<'a>> {
specialize(
|e, r, c| SyntaxError::Pattern(EPattern::Record(e, r, c)),
record_pattern_help(min_indent),
)
}
#[inline(always)]
fn record_pattern_help<'a>(min_indent: u16) -> impl Parser<'a, Pattern<'a>, PRecord<'a>> {
move |arena, state| {

View file

@ -32,7 +32,7 @@ pub fn parse_loc_with<'a>(
let state = State::new(input.trim().as_bytes());
match crate::expr::test_parse_expr(0, arena, state) {
Ok((loc_expr, _state)) => Ok(loc_expr),
Ok(loc_expr) => Ok(loc_expr),
Err(fail) => Err(SyntaxError::Expr(fail)),
}
}

View file

@ -5,18 +5,12 @@ use crate::parser::{
allocated, backtrackable, optional, specialize, specialize_ref, word1, word2, ParseResult,
Parser,
Progress::{self, *},
State, SyntaxError, TApply, TInParens, TRecord, TTagUnion, Type,
State, TApply, TInParens, TRecord, TTagUnion, Type,
};
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use roc_region::all::{Located, Region};
pub fn located<'a>(
min_indent: u16,
) -> impl Parser<'a, Located<TypeAnnotation<'a>>, SyntaxError<'a>> {
specialize(|x, _, _| SyntaxError::Type(x), expression(min_indent))
}
pub fn located_help<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, Type<'a>> {
expression(min_indent)
}