mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
refactor
This commit is contained in:
parent
e6aa0a557e
commit
3b647274dc
@ -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),
|
||||
|
@ -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>>>,
|
||||
|
@ -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};
|
||||
|
@ -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
|
||||
"#
|
||||
),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user