w3c / webdriver-bidi

Bidirectional WebDriver protocol for browser automation
https://w3c.github.io/webdriver-bidi/
370 stars 42 forks source link

Use parenthesis for base types #460

Closed jrandolf-2 closed 1 year ago

jrandolf-2 commented 1 year ago

CDDL doesn't allow composition with non-groups.

Basically, you have the following ABNF:

   grpent = [occur S] [memberkey S] type
            / [occur S] groupname [genericarg]  ; preempted by above
            / [occur S] "(" S group S ")"

When you you don't use parenthesis, it matches the first branch, but this is bad because for maps (types declared with { ... }), this is not valid ("If the memberkey is not given, the entry can only be used for matching arrays, not for maps." (Ctrl + F this)).

Thus we need to declare the base types with parenthesis.

See https://www.rfc-editor.org/rfc/rfc8610.html#appendix-C for the relevant spec.


Preview | Diff

OrKoN commented 1 year ago

@whimboo @jgraham could you please take a look?

jrandolf-2 commented 1 year ago

The difference is not readily apparent. You see the difference when you consider arrays.

For example, consider the following:

apple = ( uint )
banana = ( apple )
mango = [
 banana
]
banana-2 = { apple }
mango-2 = [
 banana-2
]

banana is a type alias, so what this means is mango = [apple] in TS. banana-2 is a type, so what this means is mango-2 = [banana-2] because types are not spread.

Fun fact:

You can have the CDDL test = ( test ) which is valid, but literally means nothing for tooling because you can't determine if test is a group name or a type name. If you had test = ( test .default 5 ), the test would be a type because .default can only be used on types.