Errors in syntax for array destructuring?
On Oct 14, 2010, at 11:47 PM, Dominic Cooney wrote:
On the harmony:destructuring page harmony:destructuring it specifies this syntax for patterns:
Pattern ::= "{" (Field ("," Field)) "}" | "[" ((Pattern | LValue)? ",")* "]" Field ::= Identifier (":" (Pattern | LValue))? LValue ::= <any lvalue expression allowed in a normal assignment expression>
Is it intentional that commas aren't required between fields of an object pattern, for example, {x y}? That seems concise, but odd. SpiderMonkey doesn't support this syntax.
There is a comma (",") in the first EBNF production you cite from the wiki, just after the meta-left-parenthesis:
Pattern ::= "{" (Field ("," Field)) "}"
Likewise, why aren't trailing commas permitted in object destructuring as they are in object literals? SpiderMonkey accepts trailing commas.
That is a good point, probably just an oversight. ECMA-262 doesn't use EBNF and we'd need to translate it into the spec's grammar. Thanks for noticing this.
Finally, surely trailing commas aren't required in array destructuring? The second alternative seems to indicate that they are.
Fixed -- thanks again.
On Fri, Oct 15, 2010 at 8:34 AM, Brendan Eich <brendan at mozilla.com> wrote:
On Oct 14, 2010, at 11:47 PM, Dominic Cooney wrote:
On the harmony:destructuring page harmony:destructuring it specifies this syntax for patterns:
Pattern ::= "{" (Field ("," Field)) "}" | "[" ((Pattern | LValue)? ",")* "]" Field ::= Identifier (":" (Pattern | LValue))? LValue ::= <any lvalue expression allowed in a normal assignment expression>
Is it intentional that commas aren't required between fields of an object pattern, for example, {x y}? That seems concise, but odd. SpiderMonkey doesn't support this syntax.
There is a comma (",") in the first EBNF production you cite from the wiki, just after the meta-left-parenthesis:
Pattern ::= "{" (Field ("," Field)) "}"
Maybe I'm misreading it too, but I would expect that since the inner ("," Field)* can match the empty string
"{" (Field )* "}"
and therefore as Dominic says just have "{" Field Field Field "}"
Mike
On Oct 15, 2010, at 11:08 AM, Mike Shaver wrote:
On Fri, Oct 15, 2010 at 8:34 AM, Brendan Eich <brendan at mozilla.com> wrote:
On Oct 14, 2010, at 11:47 PM, Dominic Cooney wrote:
On the harmony:destructuring page harmony:destructuring it specifies this syntax for patterns:
Pattern ::= "{" (Field ("," Field)) "}" | "[" ((Pattern | LValue)? ",")* "]" Field ::= Identifier (":" (Pattern | LValue))? LValue ::= <any lvalue expression allowed in a normal assignment expression>
Is it intentional that commas aren't required between fields of an object pattern, for example, {x y}? That seems concise, but odd. SpiderMonkey doesn't support this syntax.
There is a comma (",") in the first EBNF production you cite from the wiki, just after the meta-left-parenthesis:
Pattern ::= "{" (Field ("," Field)) "}"
Maybe I'm misreading it too, but I would expect that since the inner ("," Field)* can match the empty string
"{" (Field )* "}"
and therefore as Dominic says just have "{" Field Field Field "}"
Right, I noticed that after posting and fixed it already (see latest version and history of harmony:destructuring -- let me know if there are still bugs).
This EBNF was copied over from an old ES4 spec, which was not reviewed carefully enough. Thanks, and thanks again to Dominic.
On the harmony:destructuring page harmony:destructuring it
specifies this syntax for patterns:
Pattern ::= "{" (Field ("," Field)) "}" | "[" ((Pattern | LValue)? ",")* "]" Field ::= Identifier (":" (Pattern | LValue))? LValue ::= <any lvalue expression allowed in a normal assignment expression>
Is it intentional that commas aren't required between fields of an object pattern, for example, {x y}? That seems concise, but odd. SpiderMonkey doesn't support this syntax.
Likewise, why aren't trailing commas permitted in object destructuring as they are in object literals? SpiderMonkey accepts trailing commas.
Finally, surely trailing commas aren't required in array destructuring? The second alternative seems to indicate that they are. SpiderMonkey doesn't require trailing commas.
Shouldn't the syntax be something like:
Pattern ::= "{" (Field ("," Field)* ","?)? "}" | "[" (ArrayField ("," ArrayField)*)? "]"
ArrayField ::= (Pattern | LValue)?
(Field as before)
,
Dominic