This commit is contained in:
Folkert 2021-03-18 14:50:21 +01:00
parent e6aa0a557e
commit 3b647274dc
4 changed files with 41 additions and 49 deletions

View File

@ -1344,27 +1344,7 @@ fn assigned_expr_field_to_pattern_help<'a>(
})
}
/// A definition, consisting of one of these:
///
/// * A type alias using `:`
/// * A pattern followed by '=' and then an expression
/// * A type annotation
/// * A type annotation followed on the next line by a pattern, an `=`, and an expression
pub fn def<'a>(min_indent: u16) -> impl Parser<'a, Def<'a>, SyntaxError<'a>> {
move |arena, state: State<'a>| {
// specialize(|e, _, _| SyntaxError::Expr(e), def_help(min_indent))
match def_help_help(min_indent).parse(arena, state) {
Err((progress, fail, state)) => Err((progress, SyntaxError::Expr(fail), state)),
Ok((progress, mut loc_defs, state)) => match loc_defs.pop() {
Some(loc_def) => Ok((progress, loc_def.value, state)),
None => panic!(),
},
}
}
}
pub fn def_help_help<'a>(min_indent: u16) -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, EExpr<'a>> {
pub fn defs<'a>(min_indent: u16) -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, EExpr<'a>> {
move |arena, state: State<'a>| {
let def_state = DefState {
defs: Vec::new_in(arena),

View File

@ -15,6 +15,33 @@ use crate::type_annotation;
use bumpalo::collections::Vec;
use roc_region::all::Located;
fn end_of_file<'a>() -> impl Parser<'a, (), SyntaxError<'a>> {
|_arena, state: State<'a>| {
if state.has_reached_end() {
Ok((NoProgress, (), state))
} else {
Err((
NoProgress,
SyntaxError::NotEndOfFile(state.line, state.column),
state,
))
}
}
}
#[inline(always)]
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, SyntaxError<'a>> {
// force that we pare until the end of the input
let min_indent = 0;
skip_second!(
specialize(
|e, _, _| SyntaxError::Expr(e),
crate::expr::defs(min_indent),
),
end_of_file()
)
}
pub fn parse_header<'a>(
arena: &'a bumpalo::Bump,
state: State<'a>,
@ -249,32 +276,6 @@ fn platform_header<'a>() -> impl Parser<'a, PlatformHeader<'a>, EHeader<'a>> {
}
}
fn end_of_file<'a>() -> impl Parser<'a, (), SyntaxError<'a>> {
|_arena, state: State<'a>| {
if state.has_reached_end() {
Ok((NoProgress, (), state))
} else {
Err((
NoProgress,
SyntaxError::NotEndOfFile(state.line, state.column),
state,
))
}
}
}
#[inline(always)]
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, SyntaxError<'a>> {
// force that we pare until the end of the input
let min_indent = 0;
skip_second!(
specialize(
|e, _, _| SyntaxError::Expr(e),
crate::expr::def_help_help(min_indent),
),
end_of_file()
)
}
#[derive(Debug)]
struct ProvidesTo<'a> {
entries: Vec<'a, Located<ExposesEntry<'a, &'a str>>>,

View File

@ -28,7 +28,6 @@ mod test_parse {
AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
PackageName, PackageOrPath, PlatformHeader, To,
};
use roc_parse::module::module_defs;
use roc_parse::parser::{Parser, State, SyntaxError};
use roc_parse::test_helpers::parse_expr_with;
use roc_region::all::{Located, Region};

View File

@ -5656,7 +5656,6 @@ mod test_reporting {
}
#[test]
#[ignore]
fn argument_without_space() {
report_problem_as(
indoc!(
@ -5666,6 +5665,19 @@ mod test_reporting {
),
indoc!(
r#"
SYNTAX PROBLEM
I cannot find a `bar` value
1 [ "foo", bar("") ]
^^^
these names seem close though:
Nat
Str
U8
F64
"#
),
)