W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: Grammar for Union Types

From: Cameron McCormack <cam@mcc.id.au>
Date: Wed, 04 Jan 2012 13:56:32 +1100
Message-ID: <4F03BFE0.7090700@mcc.id.au>
To: Dominique Hazael-Massieux <dom@w3.org>
CC: public-script-coord@w3.org
Dominique Hazael-Massieux:
>> From my reading of the grammar of the latest editors draft of Web IDL,
> it doesn't match what the examples show is supposed to be supported.
>
> For instance, "float or (Date or Event) or (Node or DOMString)?" doesn't
> match the "Type" production, since "ParenthesizedUnionType" only appears
> in "Type", and not in SingleType.

Type => SingleType OptionalUnionTypeParts
      => PrimitiveType TypeSuffix OptionalUnionTypeParts
      => "float" TypeSuffix OptionalUnionTypeParts
      => "float" OptionalUnionTypeParts
      => "float" UnionTypeParts
      => "float" "or" SingleType UnionTypeParts
      ...

Ah yeah I see the problem.  I think that production should be

   UnionTypeParts -> "or" Type

> Also, I think the usage of parenthesis in types changes the nature of
> the grammar. In the example below:
>          interface Foo {
>            (DOMString) or ();
>          };
> you can't determine that "or" is actually the name of an operation until
> you hit the empty parenthesis.

Actually since "or" is now a keyword, if you want to have an operation 
named "or" you will need to write it as "_or".  Otherwise you would be 
right.

You know it's probably just simpler and neater to require parentheses 
around any sequence of "or"s.

> Also, since "any" is not acceptable in an union type, it probably
> shouldn't be allowed in the grammar.

OK, here's what I'll replace the grammar with then:

Type → SingleType
         | UnionType

SingleType → NonAnyType TypeSuffix
               | "any" TypeSuffixStartingWithArray

NonAnyType → PrimitiveType TypeSuffix
               | "DOMString" TypeSuffix
               | identifier TypeSuffix
               | "sequence" "<" Type ">" Null
               | "object" TypeSuffix
               | "Date" TypeSuffix

UnionType → "(" UnionMemberType "or" UnionMemberType UnionMemberTypes 
")" TypeSuffix

UnionMemberType → NonAnyType
                    | "any" "[" "]" TypeSuffix

UnionMemberTypes → "or" UnionMemberType UnionMemberTypes
                     | ε

Can you verify this is correct?
Received on Wednesday, 4 January 2012 02:59:36 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:05 UTC