cbor-wg / cddl-control

New control operators for CDDL
Other
0 stars 0 forks source link

Element selection in ABNF control is unintuitive #5

Closed anweiss closed 3 years ago

anweiss commented 3 years ago

Per the spec:

ABNF defines a list of rules, not a single expression (called "elements" in [RFC5234]). This is resolved by requiring the controller string to be one valid "element", followed by zero or more valid "rule" separated from the element by a newline; so the controller string can be built by preceding a piece of valid ABNF by an "element" that selects from that ABNF and a newline.

As I interpret this, in order to to select an element from an ABNF spec using the .abnf control operator, one has to .cat the element name with the UTF-8 byte string representation of the ABNF. IMHO, this is unintuitive as the .cat control operator as described in Section 2.1 would imply that the target is itself part of the ABNF specification. But the use of .abnf with .cat changes the semantics of .cat in such a way the target becomes more of a "selector" rather than part of a string concatenation.

Granted, alternative approaches that come to mind based on the CDDL syntax as is aren't necessarily any more intuitive. My first thought is some sort of key/value selector similar to other languages that makes this clearer ... e.g. text .abnf controller.element ... But this introduces new syntax that results in additional defined semantics that may not be warranted at this point. And I'm not even sure I like something like this any better. So thinking out loud here.

cabo commented 3 years ago

.cat is a convenient way to piece together the format described for the controller in .abnf, but in no way needed. There is no interaction in the semantics.

anweiss commented 3 years ago

In that case, how would one denote the ABNF rule to validate against without the use of .cat? For example,

valid-date = tstr .abnf rfc3339

rfc3339 = `
  date-fullyear  = 4DIGIT
  date-month     = 2DIGIT
`

How do I ensure that the JSON string "2004" is valid against the date-fullyear rule in the ABNF spec?

cabo commented 3 years ago
valid-date = tstr .abnf 'date-fullyear
  date-fullyear  = 4DIGIT
  date-month     = 2DIGIT
`

I don't like that too much, but I haven't found a better way to combine the "element" and the ABNF rules.

Well, in this case, this can be shortened to:

valid-date = tstr .abnf '4DIGIT'

(Actually, these are all invalid as DIGIT is not defined, so really:)

valid-date = tstr .abnf '4DIGIT
DIGIT = %x30-39
'

.cat is just a nice vehicle to pull in some common ABNF to multiple places of using it by citing different "elements".

cabo commented 3 years ago

It seems I can close this now -- please re-open as needed.