allow single var patterns to double as a label in records
This commit is contained in:
parent
d94ae82901
commit
89153a4d82
|
@ -1270,6 +1270,12 @@ impl<'comments> Formatter<'comments> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pattern_call_arg<'a>(&mut self, arg: &'a CallArg<UntypedPattern>) -> Document<'a> {
|
fn pattern_call_arg<'a>(&mut self, arg: &'a CallArg<UntypedPattern>) -> Document<'a> {
|
||||||
|
if let (UntypedPattern::Var { name, .. }, Some(label)) = (&arg.value, &arg.label) {
|
||||||
|
if name == label {
|
||||||
|
return self.pattern(&arg.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arg.label
|
arg.label
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|s| s.to_doc().append(": "))
|
.map(|s| s.to_doc().append(": "))
|
||||||
|
|
|
@ -913,12 +913,6 @@ pub fn pub_parser() -> impl Parser<Token, (), Error = ParseError> {
|
||||||
|
|
||||||
pub fn pattern_parser() -> impl Parser<Token, ast::UntypedPattern, Error = ParseError> {
|
pub fn pattern_parser() -> impl Parser<Token, ast::UntypedPattern, Error = ParseError> {
|
||||||
recursive(|r| {
|
recursive(|r| {
|
||||||
let no_label = r.clone().map_with_span(|pattern, span| ast::CallArg {
|
|
||||||
location: span,
|
|
||||||
value: pattern,
|
|
||||||
label: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
let record_constructor_pattern_arg_parser = choice((
|
let record_constructor_pattern_arg_parser = choice((
|
||||||
select! {Token::Name {name} => name}
|
select! {Token::Name {name} => name}
|
||||||
.then_ignore(just(Token::Colon))
|
.then_ignore(just(Token::Colon))
|
||||||
|
@ -928,7 +922,19 @@ pub fn pattern_parser() -> impl Parser<Token, ast::UntypedPattern, Error = Parse
|
||||||
label: Some(name),
|
label: Some(name),
|
||||||
value: pattern,
|
value: pattern,
|
||||||
}),
|
}),
|
||||||
no_label.clone(),
|
r.clone().map_with_span(|pattern, span| {
|
||||||
|
let label = if let ast::UntypedPattern::Var { name, .. } = &pattern {
|
||||||
|
Some(name.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
ast::CallArg {
|
||||||
|
location: span,
|
||||||
|
value: pattern,
|
||||||
|
label,
|
||||||
|
}
|
||||||
|
}),
|
||||||
))
|
))
|
||||||
.separated_by(just(Token::Comma))
|
.separated_by(just(Token::Comma))
|
||||||
.allow_trailing()
|
.allow_trailing()
|
||||||
|
@ -940,7 +946,13 @@ pub fn pattern_parser() -> impl Parser<Token, ast::UntypedPattern, Error = Parse
|
||||||
)
|
)
|
||||||
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace));
|
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace));
|
||||||
|
|
||||||
let tuple_constructor_pattern_arg_parser = no_label
|
let tuple_constructor_pattern_arg_parser = r
|
||||||
|
.clone()
|
||||||
|
.map_with_span(|pattern, span| ast::CallArg {
|
||||||
|
location: span,
|
||||||
|
value: pattern,
|
||||||
|
label: None,
|
||||||
|
})
|
||||||
.separated_by(just(Token::Comma))
|
.separated_by(just(Token::Comma))
|
||||||
.allow_trailing()
|
.allow_trailing()
|
||||||
.then(
|
.then(
|
||||||
|
|
|
@ -35,8 +35,8 @@ pub fn spend(
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let x = datum.rdmr
|
let x = datum.rdmr
|
||||||
when x is {
|
when x is {
|
||||||
sample.Buy { fin: fin, .. } -> fin > 0
|
sample.Buy { fin, .. } -> fin > 0
|
||||||
sample.Sell { find: fin, .. } -> fin > 0
|
sample.Sell { find, .. } -> find > 0
|
||||||
sample.Hold(some) -> some > 0
|
sample.Hold(some) -> some > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue