Record pattern
This commit is contained in:
parent
67b98c47fc
commit
7ffd6b2bd7
@ -276,7 +276,23 @@ fn tuple_struct_pattern(text: &str) -> ParseResult<Pattern> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn record_pattern(text: &str) -> ParseResult<Pattern> {
|
fn record_pattern(text: &str) -> ParseResult<Pattern> {
|
||||||
unimplemented!()
|
let p = tuple((
|
||||||
|
qualified_name,
|
||||||
|
delimited(ws(tag("{")),
|
||||||
|
separated_nonempty_list(ws(tag(",")), ws(record_pattern_entry)), //TODO support newlines?
|
||||||
|
ws(tag("}")))
|
||||||
|
));
|
||||||
|
map(p, |(name, members)| Pattern::Record(name, members))(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn record_pattern_entry(text: &str) -> ParseResult<(Rc<String>, Pattern)> {
|
||||||
|
alt((
|
||||||
|
map(tuple((ws(identifier), ws(tag(":")), ws(pattern))),
|
||||||
|
|(name, _, pattern)| (name, pattern)),
|
||||||
|
map(identifier, |name|
|
||||||
|
(name.clone(), Pattern::Literal(PatternLiteral::StringPattern(name.clone())))
|
||||||
|
)
|
||||||
|
))(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pattern_literal(text: &str) -> ParseResult<PatternLiteral> {
|
fn pattern_literal(text: &str) -> ParseResult<PatternLiteral> {
|
||||||
|
Loading…
Reference in New Issue
Block a user