This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 17508 - Let enum lists end with a comma
Summary: Let enum lists end with a comma
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
: 21589 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-06-16 11:07 UTC by contributor
Modified: 2013-08-05 06:25 UTC (History)
5 users (show)

See Also:


Attachments

Description contributor 2012-06-16 11:07:21 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/
Multipage: http://www.whatwg.org/C#textFieldSelection
Complete: http://www.whatwg.org/c#textFieldSelection

Comment:
Invalid IDL of SelectionMode

Posted from: 84.182.211.110
User agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.34 Safari/536.11
Comment 1 Wolfgang Keller 2012-06-16 11:16:23 UTC
If we look at http://www.whatwg.org/specs/web-apps/current-work/#selectionmode we'll see the following IDL of SelectionMode

enum SelectionMode {
  // ...
  'preserve',
};

This is not allowed according to WebIDL http://dev.w3.org/2006/webapi/WebIDL/

Let's look why:

The nonterminal EnumValueList (what is between the { }) is defined (using EnumValues) as

[21]	EnumValueList	→	string EnumValues
[22]	EnumValues	→	"," string EnumValues 
 | ε

Thus if there is a comma a string has to follow. This string 'preserve' (which is also an invalid string according to WebIDL since string terminals have to be enclosed in double quotes - see bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=17507 - but this shall not mind here) is followed by a comma - but not by an additional string.

Thus we either have to change the WebIDL rules such that there is no need for a string after a comma or fix this IDL fragment by removing the , after 'preserve'.
Comment 2 contributor 2012-07-18 17:46:52 UTC
This bug was cloned to create bug 18234 as part of operation convergence.
Comment 3 Ian 'Hixie' Hickson 2012-09-07 16:24:46 UTC
I think we should just fix Web IDL.
Comment 4 Cameron McCormack 2012-12-07 04:25:33 UTC
Sorry, the trailing comma look pretty ugly to me.
Comment 5 Nils Barth 2013-05-24 06:50:17 UTC
I've opened a more general and detailed bug here:
Bug 22156 - Allow trailing commas in Web IDL lists

To address your concerns Cameron, I think this is primarily about vertical lists and computer-generated lists, and secondarily about individual tastes.

I agree that the horizontal list {"foo", "bar",} is pretty ugly,
but OTOH in a vertical list, the form with trailing commas:
{
  "foo",
  "bar",
}
...looks clearer than the form without:
{
  "foo",
  "bar"
}
...and it's easier to edit when there are trailing commas (since don't need to add or remove when last element changes or moves).

It's also of course easier to generate for computer output or pretty-printing, since you don't need to special-case the last element, and as discussed in Bug 22156, trailing commas allow clearer diffs, and not allowing trailing commas is a comma source of syntax errors. Further many parsers allow trailing commas anyway (notably non-IE ES3 parsers -- a common cause of errors there -- and existing Blink IDL parser, which I'm in the middle of fixing). Also some developers really prefer trailing commas (for varied personal reasons).

So allowing trailing commas sounds like it would avoid a holy war (accommodating either style), avoid errors, and save developer time worrying about this -- it's a very easy mistake to make, so making the grammar more robust seems advisable.

What do you think?
Comment 7 Cameron McCormack 2013-08-03 08:17:19 UTC
*** Bug 21589 has been marked as a duplicate of this bug. ***
Comment 8 Nils Barth 2013-08-05 06:12:08 UTC
Thanks Cameron!

One tweak: the latest spec uses 4 rules:
Enum                → "enum" identifier "{" EnumValueList "}" ";"
EnumValueList       → string EnumValueListComma
EnumValueListComma  → "," EnumValueListString 
                      | ε
EnumValueListString → string EnumValueListComma 
                      | ε

...though we could instead use these 3 rules, which seem a bit simpler:
Enum          → "enum" identifier "{" EnumValueList "}" ";"
EnumValueList → string EnumValues
EnumValues    → "," string EnumValues
                | ","
                | ε

WDYT?
Comment 9 Cameron McCormack 2013-08-05 06:16:52 UTC
(In reply to comment #8)
> ...though we could instead use these 3 rules, which seem a bit simpler:
> Enum          → "enum" identifier "{" EnumValueList "}" ";"
> EnumValueList → string EnumValues
> EnumValues    → "," string EnumValues
>                 | ","
>                 | ε
> 
> WDYT?

That's not LL(1), since you can't decide which of the first two productions of EnumValues to take without looking ahead another token.  I'd like to keep the language LL(1) to make it easy to write a parser for.
Comment 10 Nils Barth 2013-08-05 06:25:27 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > ...though we could instead use these 3 rules, which seem a bit simpler:
> > Enum          → "enum" identifier "{" EnumValueList "}" ";"
> > EnumValueList → string EnumValues
> > EnumValues    → "," string EnumValues
> >                 | ","
> >                 | ε
> > 
> > WDYT?
> 
> That's not LL(1), since you can't decide which of the first two productions
> of EnumValues to take without looking ahead another token.  I'd like to keep
> the language LL(1) to make it easy to write a parser for.

Got it, thanks for the explanation!
Right, it's LL(2); been using LALR parser so didn't notice.