mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Parse underscore patterns
This commit is contained in:
parent
9bf0d9477a
commit
02e8c4ffbc
1 changed files with 10 additions and 3 deletions
|
@ -29,7 +29,7 @@ use parse::blankspace::{space0, space0_around, space0_before, space1_before};
|
||||||
use parse::ident::{ident, Ident};
|
use parse::ident::{ident, Ident};
|
||||||
use parse::number_literal::number_literal;
|
use parse::number_literal::number_literal;
|
||||||
use parse::parser::{
|
use parse::parser::{
|
||||||
and, attempt, between, char, either, loc, map, map_with_arena, one_of3, one_of4, one_of9,
|
and, attempt, between, char, either, loc, map, map_with_arena, one_of4, one_of5, one_of9,
|
||||||
one_or_more, optional, sep_by0, skip_first, skip_second, string, then, unexpected,
|
one_or_more, optional, sep_by0, skip_first, skip_second, string, then, unexpected,
|
||||||
unexpected_eof, zero_or_more, Either, ParseResult, Parser, State,
|
unexpected_eof, zero_or_more, Either, ParseResult, Parser, State,
|
||||||
};
|
};
|
||||||
|
@ -317,9 +317,11 @@ fn parse_closure_param<'a>(
|
||||||
state: State<'a>,
|
state: State<'a>,
|
||||||
min_indent: u16,
|
min_indent: u16,
|
||||||
) -> ParseResult<'a, Located<Pattern<'a>>> {
|
) -> ParseResult<'a, Located<Pattern<'a>>> {
|
||||||
one_of4(
|
one_of5(
|
||||||
// An ident is the most common param, e.g. \foo -> ...
|
// An ident is the most common param, e.g. \foo -> ...
|
||||||
loc(ident_pattern()),
|
loc(ident_pattern()),
|
||||||
|
// Underscore is also common, e.g. \_ -> ...
|
||||||
|
loc(underscore_pattern()),
|
||||||
// You can destructure records in params, e.g. \{ x, y } -> ...
|
// You can destructure records in params, e.g. \{ x, y } -> ...
|
||||||
loc(record_destructure(min_indent)),
|
loc(record_destructure(min_indent)),
|
||||||
// If you wrap it in parens, you can match any arbitrary pattern at all.
|
// If you wrap it in parens, you can match any arbitrary pattern at all.
|
||||||
|
@ -338,13 +340,18 @@ fn parse_closure_param<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pattern<'a>(min_indent: u16) -> impl Parser<'a, Pattern<'a>> {
|
fn pattern<'a>(min_indent: u16) -> impl Parser<'a, Pattern<'a>> {
|
||||||
one_of3(
|
one_of4(
|
||||||
|
underscore_pattern(),
|
||||||
variant_pattern(),
|
variant_pattern(),
|
||||||
ident_pattern(),
|
ident_pattern(),
|
||||||
record_destructure(min_indent),
|
record_destructure(min_indent),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn underscore_pattern<'a>() -> impl Parser<'a, Pattern<'a>> {
|
||||||
|
map(char('_'), |_| Pattern::Underscore)
|
||||||
|
}
|
||||||
|
|
||||||
fn record_destructure<'a>(min_indent: u16) -> impl Parser<'a, Pattern<'a>> {
|
fn record_destructure<'a>(min_indent: u16) -> impl Parser<'a, Pattern<'a>> {
|
||||||
map(
|
map(
|
||||||
collection(
|
collection(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue