mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
Relax argument indentation requirements in closures
This commit is contained in:
parent
ede015517a
commit
51f2cdccf7
7 changed files with 70 additions and 21 deletions
|
@ -2340,16 +2340,18 @@ pub fn parse_top_level_defs<'a>(
|
|||
|
||||
fn closure_help<'a>(check_for_arrow: CheckForArrow) -> impl Parser<'a, Expr<'a>, EClosure<'a>> {
|
||||
one_of!(
|
||||
closure_new_syntax_help(),
|
||||
closure_new_syntax_help(check_for_arrow),
|
||||
closure_old_syntax_help(check_for_arrow),
|
||||
)
|
||||
}
|
||||
|
||||
fn closure_new_syntax_help<'a>() -> impl Parser<'a, Expr<'a>, EClosure<'a>> {
|
||||
fn closure_new_syntax_help<'a>(
|
||||
check_for_arrow: CheckForArrow,
|
||||
) -> impl Parser<'a, Expr<'a>, EClosure<'a>> {
|
||||
map_with_arena(
|
||||
indented_seq_skip_first(
|
||||
skip_first(
|
||||
error_on_pizza(byte_indent(b'|', EClosure::Bar), EClosure::Start),
|
||||
and(
|
||||
reset_min_indent(and(
|
||||
sep_by1_e(
|
||||
byte_indent(b',', EClosure::Comma),
|
||||
space0_around_ee(
|
||||
|
@ -2363,14 +2365,9 @@ fn closure_new_syntax_help<'a>() -> impl Parser<'a, Expr<'a>, EClosure<'a>> {
|
|||
// Parse the -> which separates params from body
|
||||
byte(b'|', EClosure::Bar),
|
||||
// Parse the body
|
||||
block(
|
||||
CheckForArrow(false),
|
||||
true,
|
||||
EClosure::IndentBody,
|
||||
EClosure::Body,
|
||||
),
|
||||
block(check_for_arrow, true, EClosure::IndentBody, EClosure::Body),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
|arena: &'a Bump, (params, body)| {
|
||||
let params: Vec<'a, Loc<Pattern<'a>>> = params;
|
||||
|
@ -2386,12 +2383,12 @@ fn closure_old_syntax_help<'a>(
|
|||
// closure_help_help(options)
|
||||
map_with_arena(
|
||||
// After the first token, all other tokens must be indented past the start of the line
|
||||
indented_seq_skip_first(
|
||||
skip_first(
|
||||
// All closures start with a '\' - e.g. (\x -> x + 1)
|
||||
byte_indent(b'\\', EClosure::Start),
|
||||
// Once we see the '\', we're committed to parsing this as a closure.
|
||||
// It may turn out to be malformed, but it is definitely a closure.
|
||||
and(
|
||||
reset_min_indent(and(
|
||||
// Parse the params
|
||||
// Params are comma-separated
|
||||
sep_by1_e(
|
||||
|
@ -2409,7 +2406,7 @@ fn closure_old_syntax_help<'a>(
|
|||
// Parse the body
|
||||
block(check_for_arrow, true, EClosure::IndentBody, EClosure::Body),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
|arena: &'a Bump, (params, body)| {
|
||||
let params: Vec<'a, Loc<Pattern<'a>>> = params;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue