|Internet-Draft||CDDL control operators||July 2021|
|Bormann||Expires 1 February 2022||[Page]|
The Concise Data Definition Language (CDDL), standardized in RFC 8610, provides "control operators" as its main language extension point.¶
The present document defines a number of control operators that did
not make it into RFC 8610:
.det for the construction of constants,
.abnfb for including ABNF (RFC 5234/RFC 7405) in CDDL specifications, and
.feature for indicating the use of a non-basic feature in an instance.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 1 February 2022.¶
Copyright (c) 2021 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.¶
The present document defines a number of control operators that did not make it into RFC 8610:¶
|.det||String Concatenation, pre-dedenting|
|.abnf||ABNF in CDDL (text strings)|
|.abnfb||ABNF in CDDL (byte strings)|
|.feature||Detecting feature use in extension points|
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
CDDL as defined in [RFC8610] does not have any mechanisms to compute
literals. As an 80 % solution, this specification adds three control
.plus for numeric addition,
.cat for string
.det for string concatenation with dedenting of
both sides (target and controller).¶
For these operators, as with all control operators, targets and controllers are types. The resulting type is therefore formally a function of the elements of the cross-product of the two types. Not all tools may be able to work with non-unique targets or controllers.¶
In many cases in a specification, numbers are needed relative to a
base number. The
.plus control identifies a number that is
constructed by adding the numeric values of the target and of the
Target and controller MUST be numeric. If the target is a floating point number and the controller an integer number, or vice versa, the sum is converted into the type of the target; converting from a floating point number to an integer selects its floor (the largest integer less than or equal to the floating point number).¶
The example in Figure 1 contains the generic definition of a group
interval that gives a lower and an upper bound and optionally a
rect combines two of these groups into a map, one group for the X
dimension and one for Y dimension.¶
It is often useful to be able to compose string literals out of component literals defined in different places in the specification.¶
.cat control identifies a string that is built from a
concatenation of the target and the controller.
Target and controller MUST be strings.
The result of the operation has the type of the target.
The concatenation is performed on the bytes in both strings.
If the target is a text string, the result of that concatenation MUST
be valid UTF-8.¶
The example in Figure 2
builds a text string named
a out of concatenating the target text string
and the controller byte string entered in a text form byte string literal.
(This particular idiom is useful when the text string contains
newlines, which, as shown in the example for
b, may be harder to
read when entered in the format that the pure CDDL text string
notation inherits from JSON.)¶
Multi-line string literals for various applications, including embedded ABNF (Section 3), need to be set flush left, at least partially. Often, having some indentation in the source code for the literal can promote readability, as in Figure 3.¶
The control operator
.det works like
.cat, except that both
arguments (target and controller) are independently dedented before
the concatenation takes place.
For the purposes of this specification, we define dedenting as:¶
.det is a shortcut for "dedenting cat".
The maybe more obvious name
.dedcat has not been chosen
as it is longer and may invoke unpleasant images.)¶
Occasionally, dedenting of only a single item is needed.
This can be achieved by using this operator with an empty string,
"" .det rhs or
lhs .det "", which can in turn be combined
.cat: in the construct
lhs .cat ("" .det rhs), only
Many IETF protocols define allowable values for their text strings in ABNF [RFC5234] [RFC7405]. It is often desirable to define a text string type in CDDL by employing existing ABNF embedded into the CDDL specification. Without specific ABNF support in CDDL, that ABNF would usually need to be translated into a regular expression (if that is even possible).¶
ABNF is added to CDDL in the same way that regular
expressions were added: by defining a
.abnf control operator.
The target is usually
text or some restriction on it, the controller
is the text of an ABNF specification.¶
There are several small issues, with solutions given here:¶
.abnfbfor ABNF denoting byte sequences and
.abnffor denoting sequences of Unicode scalar values (codepoint) represented as UTF-8 text strings. Both control operators can be applied to targets of either string type; the ABNF is applied to sequence of bytes in the string interpreting that as a sequence of bytes (
.abnfb) or as a sequence of code points represented as an UTF-8 text string (
.abnf). The controller string MUST be a text string.¶
.catoperator introduced in Section 2.2 and the syntax for text in byte strings. As is customary for ABNF, the syntax of ABNF itself (NOT the syntax expressed in ABNF!) is relaxed to allow a single linefeed as a newline:¶
CRLF = %x0A / %x0D.0A¶
.catoperator, and/or by
.detif there is indentation to be disposed of.¶
Commonly, the kind of validation enabled by languages such as CDDL provides a Boolean result: valid, or invalid.¶
In rapidly evolving environments, this is too simplistic. The data models described by a CDDL specification may continually be enhanced by additional features, and it would be useful even for a specification that does not yet describe a specific future feature to identify the extension point the feature can use, accepting such extensions while marking them as such.¶
.feature control annotates the target as making use of the
feature named by the controller. The latter will usually be a string.
A tool that validates an instance against that specification may mark
the instance as using a feature that is annotated by the
More specifically, the tool's diagnostic output might contain the controller (right hand side) as a feature name, and the target (left hand side) as a feature detail. However, in some cases, the target has too much detail, and the specification might want to hint the tool that more limited detail is appropriate. In this case, the controller should be an array, with the first element being the feature name (that would otherwise be the entire controller), and the second element being the detail (usually another string), as illustrated in Figure 5.¶
Figure 6 shows what could be the definition of a person, with
potential extensions beyond
organization being marked
Extensions that are known at the time this definition is written can be
$$person-extensions. However, future extensions
would be deemed invalid unless the wildcard at the end of the map is
These extensions could then be specifically examined by a user or a
tool that makes use of the validation result; the label (map key)
actually used makes a fine feature detail for the tool's diagnostic
Leaving out the entire extension point would mean that instances that
make use of an extension would be marked as whole-sale invalid, making
the entire validation approach much less useful.
Leaving the extension point in, but not marking its use as special,
would render mistakes such as using the label
organisation instead of
A CDDL tool may simply report the set of features being used; the control then only provides information to the process requesting the validation. One could also imagine a tool that takes arguments allowing the tool to accept certain features and reject others (enable/disable). The latter approach could for instance be used for a JSON/CBOR switch, as illustrated in Figure 8.¶
It remains to be seen if the enable/disable approach can lead to new idioms of using CDDL. The language currently has no way to enforce mutually exclusive use of features, as would be needed in this example.¶
This section is to be removed before publishing as an RFC.¶
An early implementation of the control operator
.feature has been
available in the CDDL tool described in Appendix F of [RFC8610] since version 0.8.11.
The validator warns about each feature being used and provides the set
of target values used with the feature.
The other control operators defined in this specification are also
implemented as of version 0.8.21 and 0.8.26 (double-handed
Jim Schaad suggested several improvements.
.feature feature was developed out of a discussion with Henk Birkholz.
Paul Kyzivat helped isolate the need for
.det is an abbreviation for "dedenting cat", but Det is also the name of a German TV Cartoon character created in the 1960s.¶