mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Merge pull request #7050 from roc-lang/arg-patterns-as
This commit is contained in:
commit
2469a3aa2d
11 changed files with 179 additions and 1 deletions
|
@ -38,6 +38,7 @@ pub enum Parens {
|
|||
InFunctionType,
|
||||
InApply,
|
||||
InOperator,
|
||||
InAsPattern,
|
||||
}
|
||||
|
||||
/// In an AST node, do we show newlines around it
|
||||
|
|
|
@ -1245,7 +1245,7 @@ fn fmt_closure<'a>(
|
|||
let mut it = loc_patterns.iter().peekable();
|
||||
|
||||
while let Some(loc_pattern) = it.next() {
|
||||
loc_pattern.format(buf, indent);
|
||||
loc_pattern.format_with_options(buf, Parens::InAsPattern, Newlines::No, indent);
|
||||
|
||||
if it.peek().is_some() {
|
||||
buf.indent(indent);
|
||||
|
|
|
@ -244,9 +244,19 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
}
|
||||
|
||||
As(pattern, pattern_as) => {
|
||||
let needs_parens = parens == Parens::InAsPattern;
|
||||
|
||||
if needs_parens {
|
||||
buf.push('(');
|
||||
}
|
||||
|
||||
fmt_pattern(buf, &pattern.value, indent, parens);
|
||||
|
||||
pattern_as.format(buf, indent + INDENT);
|
||||
|
||||
if needs_parens {
|
||||
buf.push(')');
|
||||
}
|
||||
}
|
||||
|
||||
// Space
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue