mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Get Switch running on Crane
This commit is contained in:
parent
750a9f9ca3
commit
e49b608157
6 changed files with 568 additions and 281 deletions
|
@ -769,7 +769,7 @@ fn loc_pattern<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<'a>>> {
|
|||
loc!(ident_pattern()),
|
||||
loc!(record_destructure(min_indent)),
|
||||
loc!(string_pattern()),
|
||||
loc!(int_pattern())
|
||||
loc!(number_pattern())
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -781,7 +781,7 @@ fn loc_parenthetical_pattern<'a>(min_indent: u16) -> impl Parser<'a, Located<Pat
|
|||
)
|
||||
}
|
||||
|
||||
fn int_pattern<'a>() -> impl Parser<'a, Pattern<'a>> {
|
||||
fn number_pattern<'a>() -> impl Parser<'a, Pattern<'a>> {
|
||||
map_with_arena!(number_literal(), |arena, expr| {
|
||||
expr_to_pattern(arena, &expr).unwrap()
|
||||
})
|
||||
|
@ -1016,49 +1016,61 @@ fn unary_negate_function_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<Exp
|
|||
then(
|
||||
// Spaces, then '-', then *not* more spaces.
|
||||
not_followed_by(
|
||||
and!(space1(min_indent), loc!(char('-'))),
|
||||
and!(
|
||||
space1(min_indent),
|
||||
either!(
|
||||
// Try to parse a number literal *before* trying to parse unary negate,
|
||||
// because otherwise (foo -1) will parse as (foo (Num.neg 1))
|
||||
loc!(number_literal()),
|
||||
loc!(char('-'))
|
||||
)
|
||||
),
|
||||
one_of!(char(' '), char('#'), char('\n')),
|
||||
),
|
||||
move |arena, state, (spaces, loc_minus_char)| {
|
||||
let region = loc_minus_char.region;
|
||||
let loc_op = Located {
|
||||
region,
|
||||
value: UnaryOp::Negate,
|
||||
};
|
||||
move |arena, state, (spaces, num_or_minus_char)| {
|
||||
match num_or_minus_char {
|
||||
Either::First(loc_num_literal) => Ok((loc_num_literal, state)),
|
||||
Either::Second(Located { region, .. }) => {
|
||||
let loc_op = Located {
|
||||
region,
|
||||
value: UnaryOp::Negate,
|
||||
};
|
||||
|
||||
// Continue parsing the function arg as normal.
|
||||
let (loc_expr, state) = loc_function_arg(min_indent).parse(arena, state)?;
|
||||
let region = Region {
|
||||
start_col: loc_op.region.start_col,
|
||||
start_line: loc_op.region.start_line,
|
||||
end_col: loc_expr.region.end_col,
|
||||
end_line: loc_expr.region.end_line,
|
||||
};
|
||||
let value = Expr::UnaryOp(arena.alloc(loc_expr), loc_op);
|
||||
let loc_expr = Located {
|
||||
// Start from where the unary op started,
|
||||
// and end where its argument expr ended.
|
||||
// This is relevant in case (for example)
|
||||
// we have an expression involving parens,
|
||||
// for example `-(foo bar)`
|
||||
region,
|
||||
value,
|
||||
};
|
||||
// Continue parsing the function arg as normal.
|
||||
let (loc_expr, state) = loc_function_arg(min_indent).parse(arena, state)?;
|
||||
let region = Region {
|
||||
start_col: loc_op.region.start_col,
|
||||
start_line: loc_op.region.start_line,
|
||||
end_col: loc_expr.region.end_col,
|
||||
end_line: loc_expr.region.end_line,
|
||||
};
|
||||
let value = Expr::UnaryOp(arena.alloc(loc_expr), loc_op);
|
||||
let loc_expr = Located {
|
||||
// Start from where the unary op started,
|
||||
// and end where its argument expr ended.
|
||||
// This is relevant in case (for example)
|
||||
// we have an expression involving parens,
|
||||
// for example `-(foo bar)`
|
||||
region,
|
||||
value,
|
||||
};
|
||||
|
||||
// spaces can be empy if it's all space characters (no newlines or comments).
|
||||
let value = if spaces.is_empty() {
|
||||
loc_expr.value
|
||||
} else {
|
||||
Expr::SpaceBefore(arena.alloc(loc_expr.value), spaces)
|
||||
};
|
||||
// spaces can be empy if it's all space characters (no newlines or comments).
|
||||
let value = if spaces.is_empty() {
|
||||
loc_expr.value
|
||||
} else {
|
||||
Expr::SpaceBefore(arena.alloc(loc_expr.value), spaces)
|
||||
};
|
||||
|
||||
Ok((
|
||||
Located {
|
||||
region: loc_expr.region,
|
||||
value,
|
||||
},
|
||||
state,
|
||||
))
|
||||
Ok((
|
||||
Located {
|
||||
region: loc_expr.region,
|
||||
value,
|
||||
},
|
||||
state,
|
||||
))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue