mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
parse statements correctly
This commit is contained in:
parent
ba22527e29
commit
fac52f7408
2 changed files with 14 additions and 17 deletions
|
@ -596,10 +596,12 @@ pub fn desugar_expr<'a>(
|
|||
let loc_ret = desugar_expr(arena, loc_ret, src, line_info, module_path);
|
||||
|
||||
// Desugar any Suffixed nodes
|
||||
desugar_defs_node_suffixed(
|
||||
arena,
|
||||
arena.alloc(Loc::at(loc_expr.region, Defs(arena.alloc(defs), loc_ret))),
|
||||
)
|
||||
// desugar_defs_node_suffixed(
|
||||
// arena,
|
||||
// arena.alloc(Loc::at(loc_expr.region, Defs(arena.alloc(defs), loc_ret))),
|
||||
// )
|
||||
|
||||
arena.alloc(Loc::at(loc_ret.region, Defs(arena.alloc(defs), loc_ret)))
|
||||
}
|
||||
Apply(loc_fn, loc_args, called_via) => {
|
||||
let mut desugared_args = Vec::with_capacity_in(loc_args.len(), arena);
|
||||
|
|
|
@ -333,7 +333,7 @@ fn expr_operator_chain<'a>(options: ExprParseOptions) -> impl Parser<'a, Expr<'a
|
|||
min_indent
|
||||
};
|
||||
|
||||
match space0_e(EExpr::IndentEnd).parse(arena, state.clone(), min_indent) {
|
||||
match space0_e(EExpr::IndentEnd).parse(arena, state.clone(), new_indent) {
|
||||
Err((_, _)) => Ok((MadeProgress, expr.value, state)),
|
||||
Ok((_, spaces_before_op, state)) => {
|
||||
let expr_state = ExprState {
|
||||
|
@ -344,7 +344,7 @@ fn expr_operator_chain<'a>(options: ExprParseOptions) -> impl Parser<'a, Expr<'a
|
|||
end,
|
||||
};
|
||||
|
||||
parse_expr_end(min_indent, options, expr_state, arena, state, initial_state)
|
||||
parse_expr_end(new_indent, options, expr_state, arena, state, initial_state)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -618,7 +618,6 @@ pub fn parse_single_def<'a>(
|
|||
}
|
||||
}
|
||||
Err((MadeProgress, _)) => {
|
||||
|
||||
// Try to parse as a Statement
|
||||
match parse_statement_inside_def(
|
||||
arena,
|
||||
|
@ -630,7 +629,6 @@ pub fn parse_single_def<'a>(
|
|||
// TODO figure out why including spaces_before_current here doubles things up
|
||||
&[],
|
||||
|_, loc_def_expr| -> ValueDef<'a> { ValueDef::Stmt(arena.alloc(loc_def_expr)) },
|
||||
print_debug,
|
||||
) {
|
||||
Ok((_, Some(single_def), state)) => match single_def.type_or_value {
|
||||
Either::Second(ValueDef::Stmt(loc_expr)) if is_loc_expr_suffixed(*loc_expr) => {
|
||||
|
@ -728,7 +726,6 @@ pub fn parse_single_def<'a>(
|
|||
operator_result_state,
|
||||
loc_pattern,
|
||||
spaces_before_current,
|
||||
print_debug,
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -938,15 +935,13 @@ pub fn parse_single_def_assignment<'a>(
|
|||
);
|
||||
|
||||
// Try to parse the rest of the expression as multipls defs, which may contain sub-assignments
|
||||
match parse_defs_expr(options, min_indent, defs, arena, state.clone(), print_debug) {
|
||||
match parse_defs_expr(options, min_indent, defs, arena, state.clone()) {
|
||||
Ok((new_progress, expr, new_state)) => {
|
||||
progress = new_progress;
|
||||
loc_def_expr = Loc::at(region, expr);
|
||||
state = new_state;
|
||||
|
||||
}
|
||||
Err(_) => {
|
||||
progress = new_progress;
|
||||
loc_def_expr = Loc::at(region, expr);
|
||||
state = new_state;
|
||||
}
|
||||
Err(err) => {}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1251,7 +1246,7 @@ fn parse_defs_expr<'a>(
|
|||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Expr<'a>, EExpr<'a>> {
|
||||
match parse_defs_end(options, min_indent, defs, arena, state) {
|
||||
match dbg!(parse_defs_end(options, min_indent, defs, arena, state)) {
|
||||
Err(bad) => Err(bad),
|
||||
Ok((_, def_state, state)) => {
|
||||
// this is no def, because there is no `=` or `:`; parse as an expr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue