mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
format cases
This commit is contained in:
parent
33e9a545fc
commit
4ac5d11e62
3 changed files with 58 additions and 18 deletions
|
@ -870,12 +870,8 @@ pub fn case_branches<'a>(
|
|||
// 1. Parse the first branch and get its indentation level. (It must be >= min_indent.)
|
||||
// 2. Parse the other branches. Their indentation levels must be == the first branch's.
|
||||
|
||||
let (mut loc_first_pattern, state) = sep_by1(
|
||||
// TODO maybe remove these spaces
|
||||
map!(and!(space1(min_indent), char('|')), |_| ()),
|
||||
space1_before(loc!(pattern(min_indent)), min_indent),
|
||||
)
|
||||
.parse(arena, state)?;
|
||||
let (mut loc_first_pattern, state) =
|
||||
alternative_patterns(min_indent).parse(arena, state)?;
|
||||
let original_indent = state.indent_col;
|
||||
let indented_more = original_indent + 1;
|
||||
let (spaces_before_arrow, state) = space0(min_indent).parse(arena, state)?;
|
||||
|
@ -904,10 +900,7 @@ pub fn case_branches<'a>(
|
|||
|
||||
let branch_parser = and!(
|
||||
then(
|
||||
sep_by1(
|
||||
char('|'),
|
||||
space1_around(loc!(pattern(min_indent)), min_indent),
|
||||
),
|
||||
alternative_patterns(min_indent),
|
||||
move |_arena, state, loc_pattern| {
|
||||
if state.indent_col == original_indent {
|
||||
Ok((loc_pattern, state))
|
||||
|
@ -919,7 +912,7 @@ pub fn case_branches<'a>(
|
|||
},
|
||||
),
|
||||
skip_first!(
|
||||
string("->"),
|
||||
and!(space1(min_indent), string("->")),
|
||||
space1_before(
|
||||
loc!(move |arena, state| parse_expr(min_indent, arena, state)),
|
||||
min_indent,
|
||||
|
@ -945,6 +938,12 @@ pub fn case_branches<'a>(
|
|||
Ok((branches, state))
|
||||
}
|
||||
}
|
||||
fn alternative_patterns<'a>(min_indent: u16) -> impl Parser<'a, Vec<'a, Located<Pattern<'a>>>> {
|
||||
sep_by1(
|
||||
map!(and!(space1(min_indent), char('|')), |_| ()),
|
||||
space1_before(loc!(pattern(min_indent)), min_indent),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn if_expr<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> {
|
||||
map_with_arena!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue