Subject: Re: [Cbor] ABNF in place of regex (Was: Re: CDDL: Solving the regexp issue)

From: Pete Cordell <[email-masked]>
Date: Fri, 3 Aug 2018 12:27:09 +0100

Hi Carsten,

Thanks for responding to this - way back!  I had started replying 
earlier, but couldn't quite crystallize any useful thoughts.

One thought is that in JCR we have multi-line directives.  These are 
'global level' constructs.  It could be that CDDL2.0 could add something 
similar.  That way you can define a block of ABNF in a CDDL definition 
and then refer to it. For example, something like:

   ; A 'multi-line directive' containing a block of ABNF
   #{abnf
       three-digits = 1*DIGIT 2*(“.” 1*DIGIT)
       four-digits = 1*DIGIT 3*(“.” 1*DIGIT)
       DIGIT = %x30-39
   }

   ; CDDL rules that refer to ABNF rules
   triple-digit = text .abnf three-digits
   quad-digit = text .abnf four-digits

That way the same ABNF rule (e.g. DIGIT) can be used by multiple CDDL 
rules without being 'weird'!

I think the concept of multi-line global directives (and global 
directives in general) are a useful concept in their own right, as they 
provide a convenient "get out of jail free" card.  As such they are 
worth considering for CDDL2.0 independent of the above.

Grüße,

Pete Cordell
Codalogic Ltd
C++ tools for C++ programmers, http://codalogic.com
Read & write XML in C++, http://www.xml2cpp.com

On 17/07/2018 21:54, Carsten Bormann wrote:
> Hi Pete,
> 
> Mixing in ABNF into CDDL is still something I’d like to do (for 2.0).
> 
> A simple control like the .abnf you used in March is not enough, since most ABNF right hand sides require one or more rules to become useful.  In this case, DIGIT (even if that happens to be a core rule — you still have to provide it).  A good place to keep those additional rules hasn’t occurred to me.
> 
> Also, it would be nice for this to have an equivalent of Python’s “”” for this — you used | (which would be quite confusing for people that think in classic BNF).
> 
> Ugly straw man: maybe something like
> 
> triple-digit = text .abnf “”” 1*DIGIT 2*(“.” 1*DIGIT)
>                        DIGIT = %x30-39
> “””
> 
> (i.e., the first line of the string is used as the RHS for an anonymous ABNF rule, the others provide additional rules.)
> 
> Grüße, Carsten
> 
> 
>> On Mar 30, 2018, at 08:09, Pete Cordell <[email-masked]> wrote:
>>
>> Thinking laterally, if specifying a regex format is problematic, is it worth considering ABNF as an alternative?
>>
>> The pipe character could act as a suitable delimiter.  For example:
>>
>>    triple-digit = tstr .abnf | 1*DIGIT "." 1*DIGIT "." 1*DIGIT |
>>
>> Over multiple lines it could look like:
>>
>>    triple-digit = tstr .abnf |
>>         1*DIGIT "." 1*DIGIT "." 1*DIGIT
>>    |
>>
>> The ABNF could be loosely defined; as in:
>>
>>    opague-abnf = *( text / NOT-PIPE )
>>    NOT-PIPE = CRLF / %x20-5B / %x7D-10FFFD
>>
>> It's more verbose. And it's unconventional.  But...
>>
>> Pete.
>> -- 
>> ---------------------------------------------------------------------
>> Pete Cordell
>> http://json-content-rules.org Rule
>> ---------------------------------------------------------------------
>>
>> _______________________________________________
>> CBOR mailing list
>> [email-masked]
>> https://www.ietf.org/mailman/listinfo/cbor
>>
> 
>