Implement tuple pattern parsing

Step 2 of N in implementing #4465
This commit is contained in:
Joshua Warner 2022-11-11 14:18:53 -05:00
parent 5f74e10d32
commit ca5d084497
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
17 changed files with 369 additions and 25 deletions

View file

@ -43,7 +43,9 @@ impl<'a> Formattable for Pattern<'a> {
| Pattern::QualifiedIdentifier { .. }
| Pattern::ListRest => false,
Pattern::List(patterns) => patterns.iter().any(|p| p.is_multiline()),
Pattern::Tuple(patterns) | Pattern::List(patterns) => {
patterns.iter().any(|p| p.is_multiline())
}
}
}
@ -162,6 +164,22 @@ impl<'a> Formattable for Pattern<'a> {
buf.push('_');
buf.push_str(name);
}
Tuple(loc_patterns) => {
buf.indent(indent);
buf.push_str("(");
let mut it = loc_patterns.iter().peekable();
while let Some(loc_pattern) = it.next() {
loc_pattern.format(buf, indent);
if it.peek().is_some() {
buf.push_str(",");
buf.spaces(1);
}
}
buf.push_str(")");
}
List(loc_patterns) => {
buf.indent(indent);
buf.push_str("[");

View file

@ -753,6 +753,7 @@ impl<'a> RemoveSpaces<'a> for Pattern<'a> {
Pattern::SpaceAfter(a, _) => a.remove_spaces(arena),
Pattern::SingleQuote(a) => Pattern::SingleQuote(a),
Pattern::List(pats) => Pattern::List(pats.remove_spaces(arena)),
Pattern::Tuple(pats) => Pattern::Tuple(pats.remove_spaces(arena)),
Pattern::ListRest => Pattern::ListRest,
}
}