fix parenthesized binding (#707)
This commit is contained in:
parent
9984e73ff3
commit
72d8785abe
@ -96,7 +96,7 @@ The last element is #b.
|
||||
"Homer": "The Odyssey",
|
||||
"Austen": "Persuasion",
|
||||
)
|
||||
#let (Austen) = books
|
||||
#let (Austen,) = books
|
||||
Austen wrote #Austen.
|
||||
|
||||
#let (Homer: h) = books
|
||||
|
@ -1620,7 +1620,14 @@ pub enum DestructuringKind {
|
||||
impl Pattern {
|
||||
/// The kind of the pattern.
|
||||
pub fn kind(&self) -> PatternKind {
|
||||
if self.0.children().len() <= 1 {
|
||||
if self
|
||||
.0
|
||||
.children()
|
||||
.map(SyntaxNode::kind)
|
||||
.skip_while(|&kind| kind == SyntaxKind::LeftParen)
|
||||
.take_while(|&kind| kind != SyntaxKind::RightParen)
|
||||
.eq([SyntaxKind::Ident])
|
||||
{
|
||||
return PatternKind::Ident(self.0.cast_first_match().unwrap_or_default());
|
||||
}
|
||||
|
||||
|
@ -847,11 +847,15 @@ fn pattern(p: &mut Parser) -> PatternKind {
|
||||
let m = p.marker();
|
||||
|
||||
if p.at(SyntaxKind::LeftParen) {
|
||||
collection(p, false);
|
||||
let kind = collection(p, false);
|
||||
validate_destruct_pattern(p, m);
|
||||
p.wrap(m, SyntaxKind::Pattern);
|
||||
|
||||
PatternKind::Destructuring
|
||||
if kind == SyntaxKind::Parenthesized {
|
||||
PatternKind::Normal
|
||||
} else {
|
||||
PatternKind::Destructuring
|
||||
}
|
||||
} else {
|
||||
if p.expect(SyntaxKind::Ident) {
|
||||
p.wrap(m, SyntaxKind::Pattern);
|
||||
|
@ -32,6 +32,11 @@ Three
|
||||
#test(v2, 2)
|
||||
#test(v3, 3)
|
||||
|
||||
---
|
||||
// Test parenthesised assignments.
|
||||
// Ref: false
|
||||
#let (a) = (1, 2)
|
||||
|
||||
---
|
||||
// Ref: false
|
||||
// Simple destructuring.
|
||||
@ -39,6 +44,11 @@ Three
|
||||
#test(a, 1)
|
||||
#test(b, 2)
|
||||
|
||||
---
|
||||
// Ref: false
|
||||
#let (a,) = (1,)
|
||||
#test(a, 1)
|
||||
|
||||
---
|
||||
// Ref: false
|
||||
// Destructuring with multiple placeholders.
|
||||
@ -115,10 +125,6 @@ Three
|
||||
// Error: 13-14 not enough elements to destructure
|
||||
#let (a, b, c) = (1, 2)
|
||||
|
||||
---
|
||||
// Error: 6-9 too many elements to destructure
|
||||
#let (a) = (1, 2)
|
||||
|
||||
---
|
||||
// Error: 6-20 not enough elements to destructure
|
||||
#let (..a, b, c, d) = (1, 2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user