Re: Grammar for Union Types

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 

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