Re: [Cbor] CDDL Module Design

Carsten Bormann <cabo@tzi.org> Wed, 01 July 2020 20:52 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 59E273A0D6F for <cbor@ietfa.amsl.com>; Wed, 1 Jul 2020 13:52:41 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.898
X-Spam-Level:
X-Spam-Status: No, score=-1.898 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8YlqwCmWbB7S for <cbor@ietfa.amsl.com>; Wed, 1 Jul 2020 13:52:38 -0700 (PDT)
Received: from gabriel-vm-2.zfn.uni-bremen.de (gabriel-vm-2.zfn.uni-bremen.de [134.102.50.17]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id A38B73A0D71 for <cbor@ietf.org>; Wed, 1 Jul 2020 13:52:38 -0700 (PDT)
Received: from [172.16.42.112] (p5089ae91.dip0.t-ipconnect.de [80.137.174.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gabriel-vm-2.zfn.uni-bremen.de (Postfix) with ESMTPSA id 49xthh09r7zyhR; Wed, 1 Jul 2020 22:52:35 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <042f01d64fcf$21428340$63c789c0$@augustcellars.com>
Date: Wed, 01 Jul 2020 22:52:35 +0200
Cc: cbor@ietf.org
X-Mao-Original-Outgoing-Id: 615329555.583293-d275117bf30745827822db22875743df
Content-Transfer-Encoding: quoted-printable
Message-Id: <134B9212-5C96-4621-8A59-26051F5E1933@tzi.org>
References: <03c701d64f41$e1763fa0$a462bee0$@augustcellars.com> <24433.1593575640@localhost> <03db01d64f66$cc797a20$656c6e60$@augustcellars.com> <040401d64fb4$3d776230$b8662690$@augustcellars.com> <675ADAFF-7A32-49D1-835C-866432BFED58@tzi.org> <042f01d64fcf$21428340$63c789c0$@augustcellars.com>
To: Jim Schaad <ietf@augustcellars.com>
X-Mailer: Apple Mail (2.3608.80.23.2.2)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/LegwLbmE2wtN9gQedJzYT7qN3Vo>
Subject: Re: [Cbor] CDDL Module Design
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 01 Jul 2020 20:52:41 -0000

Hi Jim,

let me pick on your example some more :-)

> This is the case that I was thinking of.  
> 
> Module A
> group = (
>   element1 : string
> )
> 
> Module B
> group //= ( element2 : int )
> 
> Module C
> group //= (element3 : float )
> 
> Module D
> myArray = [ group ]

Right.  Note that `group` is a group choice, so only one (and exactly one) of the alternatives can be chosen.  As the types “element1", “element2", “element3” (yes, the bare words turn into strings) do not overlap, the sequence in the choice is irrelevant.  If they did overlap, the first match would win, and the implied cut makes sure the alternatives are not tried.

So this is different from “adding entries to the group”, which would allow multiple of the entries to go into the array.

>>> 2.  Are there places where the current definitions of anything get
>>> messed up with multiple modules and ordering.  I am thinking of cuts
>>> in maps (where I can't remember which hill things died on) or maybe
>>> the newly proposed ..feature control.
>> 
>> Ordering within a group (different from the above) is important.
>> (That order controls cuts and other forms of prioritized choice, even if the
>> group creates a map that by definition is not order-sensitive.) But composition
>> from separate rules needs to be explicit here, e.g. in SDF:
>> 
>> sdfinfo = {
>> title: text
>> version: text
>> copyright: text
>> license: text
>> EXTENSION-POINT
>> }
>> 
>> EXTENSION-POINT = ( * text => any )
>> 
>> Putting the extension point first would enable the use of values that do not
>> match `text` in title, version, copyright, and license entries.
>> But the specifier put EXTENSION-POINT last explicitly, so there is no such
>> danger.
> 
> The question comes if you add more elements to the end of the map.  We have had this discussion during the cut process and I think that I lost that round but I would need to do a deep read on this to figure that out. Things become interesting if you do
> 
> sdfinfo = {
>  title: text,
>  version: text,
>  copyright: text,
>  license: text,
>  More-attributes,
>  EXTENSION-POINT
> }
> 
> More-attributes = ()

I would expect you are trying to build a group choice that is called More-attributes, so that we then can say:

More-attributes //= (foo: “bar”)

Starting that choice with () doesn’t work very well — the empty group always matches, and because of prioritized choice, nothing of the other alternatives is tried.

So let’s start it with something that never matches.  There is no idiomatic way to do this in CDDL yet, so let me invent one:

More-attributes = (1 .eq 2 => 3)

(This stochastically breaks the little brain of the CDDL tool, but let’s ignore that for now; maybe there are better ways to build impossible group choices.)

Now I can add 
More-attributes //= (foo: “bar”)
And
More-attributes //= (3: 4)

For good measure.

The way this is used in the maps means that only exactly one of the choices is ever added, which is not what I would call “adding entries"; if you want to be able to add from all of them (and optionally so), use

 * More-attributes,

in the map.

This is all a bit tedious, why it is not a very idiomatic way to build up maps.

Grüße, Carsten