From 3b647274dcf5cd9e5d1fad096569783f8ea28a53 Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 18 Mar 2021 14:50:21 +0100 Subject: [PATCH] refactor --- compiler/parse/src/expr.rs | 22 +-------- compiler/parse/src/module.rs | 53 +++++++++++----------- compiler/parse/tests/test_parse.rs | 1 - compiler/reporting/tests/test_reporting.rs | 14 +++++- 4 files changed, 41 insertions(+), 49 deletions(-) diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 46d2d3436e..c3750e9654 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -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>>, EExpr<'a>> { +pub fn defs<'a>(min_indent: u16) -> impl Parser<'a, Vec<'a, Located>>, EExpr<'a>> { move |arena, state: State<'a>| { let def_state = DefState { defs: Vec::new_in(arena), diff --git a/compiler/parse/src/module.rs b/compiler/parse/src/module.rs index 4158fd8a62..3e6b80da4d 100644 --- a/compiler/parse/src/module.rs +++ b/compiler/parse/src/module.rs @@ -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>>, 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>>, 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>>, diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index d9256de1e3..3582c97485 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -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}; diff --git a/compiler/reporting/tests/test_reporting.rs b/compiler/reporting/tests/test_reporting.rs index fb57b228c1..23ca7b188f 100644 --- a/compiler/reporting/tests/test_reporting.rs +++ b/compiler/reporting/tests/test_reporting.rs @@ -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 "# ), )