mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-16 16:55:00 +00:00
Correct indentation for when expressions
... and simultaneously remove the need for State::indent_column field / multiline tracking in blankspace.rs. Fixes #2889
This commit is contained in:
parent
19436cc58a
commit
ada8af25cc
8 changed files with 151 additions and 54 deletions
|
@ -1992,9 +1992,10 @@ mod when {
|
|||
/// Parsing when with indentation.
|
||||
fn when_with_indent<'a>() -> impl Parser<'a, u32, EWhen<'a>> {
|
||||
move |arena, state: State<'a>| {
|
||||
let min_indent = state.column();
|
||||
parser::keyword_e(keyword::WHEN, EWhen::When)
|
||||
.parse(arena, state)
|
||||
.map(|(progress, (), state)| (progress, state.indent_column, state))
|
||||
.map(|(progress, (), state)| (progress, min_indent, state))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2003,14 +2004,12 @@ mod when {
|
|||
options: ExprParseOptions,
|
||||
) -> impl Parser<'a, Vec<'a, &'a WhenBranch<'a>>, EWhen<'a>> {
|
||||
move |arena, state: State<'a>| {
|
||||
let when_indent = state.indent_column;
|
||||
|
||||
let mut branches: Vec<'a, &'a WhenBranch<'a>> = Vec::with_capacity_in(2, arena);
|
||||
|
||||
// 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 (_, ((pattern_indent_level, loc_first_patterns), loc_first_guard), mut state): (
|
||||
let (_, ((pattern_indent_level, loc_first_patterns), loc_first_guard), state): (
|
||||
_,
|
||||
((_, _), _),
|
||||
State<'a>,
|
||||
|
@ -2018,8 +2017,6 @@ mod when {
|
|||
|
||||
let original_indent = pattern_indent_level;
|
||||
|
||||
state.indent_column = pattern_indent_level;
|
||||
|
||||
// Parse the first "->" and the expression after it.
|
||||
let (_, loc_first_expr, mut state) =
|
||||
branch_result(original_indent + 1).parse(arena, state)?;
|
||||
|
@ -2078,9 +2075,6 @@ mod when {
|
|||
}
|
||||
}
|
||||
|
||||
let mut state = state;
|
||||
state.indent_column = when_indent;
|
||||
|
||||
Ok((MadeProgress, branches, state))
|
||||
}
|
||||
}
|
||||
|
@ -2382,7 +2376,7 @@ where
|
|||
E: 'a,
|
||||
{
|
||||
move |arena, state: State<'a>| {
|
||||
let indent_column = state.indent_column;
|
||||
let indent_column = state.column();
|
||||
|
||||
let (progress, _, state) = parser.parse(arena, state)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue