w3c / webdriver-bidi

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

(cddl): merging groups #600

Closed christian-bromann closed 7 months ago

christian-bromann commented 8 months ago

In 2.1 of the cddl spec it is defined how groups can be merged together:

Groups can be used to factor out common parts of structs, e.g., instead of writing specifications in copy/paste style, such as in Figure 5, one can factor out the common subgroup, choose a name for it, and write only the specific parts into the individual maps (Figure 6).

While the .and type describes the same:

A ".and" control on a type indicates that the data item matches both the left-hand-side type and the type given as the right-hand side. (Formally, the resulting type is the intersection of the two types given.)

  "type1 .and type2"

I don't think it can be used in the context when a group is assigned to a variable especially as we can just use the format described in 2.1.


Preview | Diff

OrKoN commented 8 months ago

@jrandolf PTAL

jrandolf commented 7 months ago

To be more specific, script.RegExpLocalValue (and similarly the other) is a map therefore it define types, not groups, so what you wrote is a keyless value in a map (which is valid syntax, but does not spread.

The easiest way to think the difference between groups and types is the behavior in an array.

Example 1:

b = text
a = [b]

Means array with a single string.

Example 2:

b = (text, text)
a = [b]

Means array with two strings.

Example 3:

b = [text, text]
a = [b]

Means array with a single array with two strings.

Note for arrays, the following are equivalent:

a = [(foo: text, bar: text)]
a = [(text, text)]
a = [text, text]

For maps, the following is syntactically allowed, but is considered illegal in CDDL:

a = {(text, text)}

which means a map with two entries (but the key is not defined, so it doesn't make sense which is why it's illegal.)

jrandolf commented 7 months ago

Closing this as it's incorrect.