Re: [Cbor] CDDL 2.0 import and paths

Carsten Bormann <cabo@tzi.org> Mon, 06 February 2023 04:12 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 6E253C14EAA3 for <cbor@ietfa.amsl.com>; Sun, 5 Feb 2023 20:12:11 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -4.199
X-Spam-Level:
X-Spam-Status: No, score=-4.199 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VRc2TZRQw2NL for <cbor@ietfa.amsl.com>; Sun, 5 Feb 2023 20:12:08 -0800 (PST)
Received: from smtp.zfn.uni-bremen.de (smtp.zfn.uni-bremen.de [134.102.50.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id AE78FC14E513 for <cbor@ietf.org>; Sun, 5 Feb 2023 20:12:06 -0800 (PST)
Received: from client-0013.vpn.uni-bremen.de (client-0013.vpn.uni-bremen.de [134.102.107.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.zfn.uni-bremen.de (Postfix) with ESMTPSA id 4P9CWk6PqDzDCbM; Mon, 6 Feb 2023 05:12:02 +0100 (CET)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <Y9FYSKde6bXgzep3@hephaistos.amsuess.com>
Date: Mon, 06 Feb 2023 05:12:02 +0100
X-Mao-Original-Outgoing-Id: 697349522.216964-9e59afa5ec342131ff181d8b3d3c3536
Content-Transfer-Encoding: quoted-printable
Message-Id: <BAFC97D5-3B5A-4ED5-ADEC-93CB53CC2128@tzi.org>
References: <Y9FYSKde6bXgzep3@hephaistos.amsuess.com>
To: cbor@ietf.org
X-Mailer: Apple Mail (2.3608.120.23.2.7)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/tFdfiv58pOAzoFH2rpf8JDJ-uTY>
Subject: Re: [Cbor] CDDL 2.0 import and paths
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
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: Mon, 06 Feb 2023 04:12:11 -0000

Christian made a great list of requirements in his email dated 2023-01-25.

cddlc 0.1.2 now implements a tiny bit of that.

   gem update cddlc

(or `gem install cddlc` if you didn’t have that yet.  Requires Ruby ≥ 3.0.)

I didn’t really want to nail pathnames or partial URIs into the CDDL files, so I added a simple CDDL_INCLUDE_PATH as an environment variable.  This is the usual colon-separated list, with a special feature: an empty element points to cddlc’s own collection, which contains 20 fragments of extracted CDDL from published RFCs(**).  If you are missing anything, please tell me.  

I did not implement Web paths (which is interesting because of the colon), some more thinking required.  (There are no useful collections of extracted CDDL on the Web yet that I am aware of, and extractors are another work item.)

The default CDDL_INCLUDE_PATH is  .:  — so you get files out of the current directory and, if not found there, cddlc’s collection.

Based on this, I implemented two directives for now:

;# include rfc9052
;;; include all the rules from rfc9052.cddl as well as the ones imported/included there, no questions asked

and

;# import rfc9052
;;; include only those rules from rfc9052.cddl that actually are undefined references in the current CDDL file, treating rfc9052 as a “library”.

I plan to add something like

;# import rfc9052 as COSE

which would rename the names in the imported rules to start with COSE(*).
(This is of course interesting because of other imported names, as well as prelude names…)

Please have a look.  My favorite command to play with this is

cddlc -2 -tcddl mytestfile.cddl | cddl - gp 10

I’ll update the cddl2 plan document as well as the implementation when I have some feedback.

This is not yet the Pareto 80 %, but already goes surprisingly far!

Grüße, Carsten

(*) I’m not yet sure whether the auto-import mechanism should add glue rules automatically, so you don’t have to call your referencing names COSE.COSE_Encrypt0 while still getting overly generic names such as `label` or `values` prefixed as `COSE.label` and `COSE.values`.  This could be limited to specific names listed in a “import … from” part of the directive.  I need to see more examples to make a useful suggestion.

(**) I also need to reserve an afternoon for submitting all the errata reports for the extracted CDDL.  From a missing closing parenthesis via word wrapping out of a comment to using # as the comment character.  Ouch.