mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
parse suffixed statements as defs
This commit is contained in:
parent
3c3e523b45
commit
997284e113
8 changed files with 294 additions and 192 deletions
|
@ -353,14 +353,23 @@ pub fn is_loc_expr_suffixed(loc_expr: Loc<Expr>) -> bool {
|
|||
|
||||
// expression with arguments, `line! "Foo"`
|
||||
Expr::Apply(sub_loc_expr, _, _) => is_loc_expr_suffixed(*sub_loc_expr),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid_suffixed_statement(loc_expr: Loc<Expr>) -> bool {
|
||||
match loc_expr.extract_spaces().item {
|
||||
Expr::Var { suffixed, .. } => suffixed > 0,
|
||||
Expr::Apply(sub_loc_expr, _, _) => is_valid_suffixed_statement(*sub_loc_expr),
|
||||
// expression in a pipeline, `"hi" |> say!`
|
||||
Expr::BinOps(chain, sub_loc_expr) => {
|
||||
let sum: isize = chain
|
||||
.into_iter()
|
||||
.map(|(chain_loc_expr, _)| -> isize {
|
||||
if is_loc_expr_suffixed(*chain_loc_expr) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
})
|
||||
.sum();
|
||||
|
||||
is_loc_expr_suffixed(*sub_loc_expr) || sum > 0
|
||||
}
|
||||
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue