<?xml version='1.0' encoding='UTF-8'?>


<!-- draft submitted in xml v3 -->  

<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-cbor-update-8610-grammar-06" number="9682" category="std" consensus="true" submissionType="IETF" updates="8610" obsoletes="" tocInclude="true" sortRefs="true" symRefs="true" version="3" xml:lang="en">

  <front>
    <title abbrev="CDDL grammar updates">Updates to the Concise Data Definition Language (CDDL) Grammar</title>
    
    <seriesInfo name="RFC" value="9682"/>
    <author initials="C." surname="Bormann" fullname="Carsten Bormann">
      <organization>Universität Bremen TZI</organization>
      <address>
        <postal>
          <street>Postfach 330440</street>
          <city>Bremen</city>
          <code>D-28359</code>
          <country>Germany</country>
        </postal>
        <phone>+49-421-218-63921</phone>
        <email>cabo@tzi.org</email>
      </address>
    </author>
    <date year="2024" month="November"/>
    <area>ART</area>
    <workgroup>cbor</workgroup>

    <keyword>Concise Data Definition Language</keyword>

    <abstract>

<t>The Concise Data Definition Language (CDDL), as defined in
RFCs 8610 and 9165,
provides an easy and unambiguous way to express structures for
protocol messages and data formats that are represented in Concise Binary Object Representation (CBOR) or
JSON.</t>
      <t>This document updates RFC 8610 by addressing related errata reports and making
other small fixes for the ABNF grammar defined for CDDL.</t>
    </abstract>

  </front>
  <middle>

<section anchor="introduction">
      <name>Introduction</name>
      <t>The Concise Data Definition Language (CDDL), as defined in
<xref target="RFC8610"/> and <xref target="RFC9165"/>,
provides an easy and unambiguous way to express structures for
protocol messages and data formats that are represented in CBOR or
JSON.</t>
      <t>This document updates <xref target="RFC8610"/> by addressing errata reports and making
other small fixes for the ABNF grammar defined for CDDL.
The body of this document explains and shows motivation for the updates; the
updated collected ABNF syntax in <xref target="collected-abnf"/> in
<xref target="collected-abnf-appendix"/> replaces the collected ABNF syntax in
<xref section="B" sectionFormat="of" target="RFC8610"/>.</t>
      <section anchor="conventions-and-definitions">
        <name>Conventions and Definitions</name>
        <t>The terminology from <xref target="RFC8610"/> applies.
The grammar in <xref target="RFC8610"/> is based on ABNF, which is defined in <xref target="STD68"/>
and <xref target="RFC7405"/>.</t>
      </section>
    </section>
    <section anchor="clari">
      <name>Clarifications and Changes Based on Errata Reports</name>
      
      <t>A number of errata reports have been made regarding some details of text
string and byte string literal syntax: for example, <xref target="Err6527"/> and <xref target="Err6543"/>.
These are being addressed in this section, updating details of the
ABNF for these literal syntaxes.
Also, the changes described in <xref target="Err6526"/> need to be applied (backslashes have been lost during the RFC publication process of <xref target="RFC8610" sectionFormat="of" section="G.2"/>, garbling the text explaining backslash escaping).</t>
      <t>These changes are intended to mirror the way existing implementations
have dealt with the errata reports.  This document also uses the opportunity presented
by the necessary cleanup of the grammar of string literals for a
backward-compatible addition to the syntax for hexadecimal escapes.
The latter change is not automatically forward compatible (i.e., CDDL
specifications that make use of this syntax do not necessarily work
with existing implementations until these are updated, which is recommended by this
specification).</t>
      <section anchor="e6527">
        <name>Updates to String Literal Grammar</name>
        <section numbered="true" anchor="err6527-text-string-literals">  
          <name>Erratum ID 6527 (Text String Literals)</name>

          <t>The ABNF used in <xref target="RFC8610"/> for the content of text string literals
	  is rather permissive:</t>
	  
          <figure anchor="e6527-orig1">
            <name>Original ABNF from RFC 8610 for Strings with Permissive ABNF
                 for SESC (Which Did Not Allow Hex Escapes)</name>
            <sourcecode type="abnf"><![CDATA[
; ABNF from RFC 8610:
text = %x22 *SCHAR %x22
SCHAR = %x20-21 / %x23-5B / %x5D-7E / %x80-10FFFD / SESC
SESC = "\" (%x20-7E / %x80-10FFFD)
]]></sourcecode>
</figure>


          <t>This allows almost any non-C0 character to be escaped by a backslash,
but critically misses out on the <tt>\uXXXX</tt> and <tt>\uHHHH\uLLLL</tt> forms
that JSON allows to specify characters in hex

(which should
apply here according to item 6 of <xref section="3.1" sectionFormat="of" target="RFC8610"/>).


(Note that CDDL imports from JSON the unwieldy <tt>\uHHHH\uLLLL</tt> syntax,
which represents Unicode code points beyond U+FFFF by making them look
like UTF-16 surrogate pairs; CDDL text strings do not use UTF-16 or
	  surrogates.)</t>

<t>Both can be solved by updating the SESC rule.

This document uses the opportunity to add a popular form of directly specifying
characters in strings using hexadecimal escape sequences of the form
<tt>\u{hex}</tt>, where <tt>hex</tt> is the hexadecimal representation of the
Unicode scalar value.
The result is the new set of rules defining SESC in <xref target="e6527-new1"/>.</t>
          <figure anchor="e6527-new1">
            <name>Update to String ABNF in <xref target="RFC8610" sectionFormat="of" section="B"/>: Allow Hex Escapes</name>
<sourcecode type="abnf" name="cddl-new-sesc.abnf"><![CDATA[
; new rules collectively defining SESC:
SESC = "\" ( %x22 / "/" / "\" /                 ; \" \/ \\
             %x62 / %x66 / %x6E / %x72 / %x74 / ; \b \f \n \r \t
             (%x75 hexchar) )                   ; \uXXXX
hexchar = "{" (1*"0" [ hexscalar ] / hexscalar) "}" /
          non-surrogate / (high-surrogate "\" %x75 low-surrogate)
non-surrogate = ((DIGIT / "A"/"B"/"C" / "E"/"F") 3HEXDIG) /
                ("D" %x30-37 2HEXDIG )
high-surrogate = "D" ("8"/"9"/"A"/"B") 2HEXDIG
low-surrogate = "D" ("C"/"D"/"E"/"F") 2HEXDIG
hexscalar = "10" 4HEXDIG / HEXDIG1 4HEXDIG
          / non-surrogate / 1*3HEXDIG
HEXDIG1 = DIGIT1 / "A" / "B" / "C" / "D" / "E" / "F"
]]></sourcecode>
</figure>
        <aside><t>Notes:
In ABNF, strings such as <tt>"A"</tt>, <tt>"B"</tt>, etc., are case insensitive, as is
intended here.
The rules above could have also used <tt>%s"b"</tt>, etc., instead of <tt>%x62</tt>, but didn't, in order to
	  maximize compatibility with ABNF tools.</t></aside>	  
          <t>Now that SESC is more restrictively formulated, an
update to the BCHAR rule used in the ABNF syntax for byte string
literals is also required:</t>
          <figure anchor="e6527-orig2">
            <name>ABNF from RFC 8610 for BCHAR</name>
            <sourcecode type="abnf"><![CDATA[
; ABNF from RFC 8610:
bytes = [bsqual] %x27 *BCHAR %x27
BCHAR = %x20-26 / %x28-5B / %x5D-10FFFD / SESC / CRLF
bsqual = "h" / "b64"
]]></sourcecode>
</figure>

	  
          <t>With the SESC updated as above, <tt>\'</tt> is no longer allowed in BCHAR and now needs to be explicitly included there; see <xref target="e6527-new2"/>.</t>
        </section>
        <section numbered="true" anchor="e6278">
          <name>Erratum ID 6278 (Consistent String Literals)</name>
          <t>Updating BCHAR also provides an opportunity to address <xref target="Err6278"/>,
which points to an inconsistency in treating U+007F (DEL) between SCHAR and
BCHAR.
As U+007F is not printable, including it in a byte string literal is
as confusing as for a text string literal; therefore, it should be
excluded from BCHAR as it is from SCHAR.
The same reasoning also applies to the C1 control characters,
so the updated ABNF actually excludes the entire range from U+007F to U+009F.
The same reasoning also applies to text in comments (PCHAR).  For completeness, all these rules should also explicitly exclude the code
points that have been set aside for UTF-16 surrogates.</t>
          <figure anchor="e6527-new2">
            <name>Update to ABNF in  <xref target="RFC8610" sectionFormat="of" section="B"/>: BCHAR, SCHAR, and PCHAR</name>
            <sourcecode type="abnf" name="cddl-new-bchar.abnf"><![CDATA[
; new rules for SCHAR, BCHAR, and PCHAR:
SCHAR = %x20-21 / %x23-5B / %x5D-7E / NONASCII / SESC
BCHAR = %x20-26 / %x28-5B / %x5D-7E / NONASCII / SESC / "\'" / CRLF
PCHAR = %x20-7E / NONASCII
NONASCII = %xA0-D7FF / %xE000-10FFFD
]]></sourcecode>
	  </figure>

          <t>(Note that, apart from addressing the inconsistencies, there is no
attempt to further exclude non-printable characters from the ABNF;
doing this properly would draw in complexity from the ongoing
evolution of the Unicode standard <xref target="UNICODE"/> that is not needed here.)</t>
        </section>
        <section numbered="true" anchor="addressing-err6526-err6543">
          <name>Addressing Erratum ID 6526 and Erratum ID 6543</name>
          <t>The above changes also cover <xref target="Err6543"/> (a proposal to split off
qualified byte string literals from UTF-8 byte string literals) and
<xref target="Err6526"/> (lost backslashes); see <xref target="Err6543-covered"/> for details.</t>
        </section>
      </section>
      <section anchor="examples-demonstrating-the-updated-string-syntaxes">
        <name>Examples Demonstrating the Updated String Syntaxes</name>


        <t>The CDDL example in <xref target="string-examples"/> demonstrates various escaping
techniques now available for (byte and text) strings in CDDL.
Obviously, in the literals for <tt>a</tt> and <tt>x</tt>, there is no need to escape
the second character, an <tt>o</tt>, as <tt>\u{6f}</tt>; this is just for demonstration.
Similarly, as shown in <tt>c</tt> and <tt>z</tt>, there also is no need to escape the
<u>🁳</u> or <u>⌘</u>; however, escaping them may be convenient in order to limit the character
repertoire of a CDDL file itself to ASCII <xref target="STD80"/>.</t>
        <figure anchor="string-examples">
          <name>Example Text and Byte String Literals with Various Escaping Techniques</name>
          <sourcecode type="cddl"><![CDATA[
start = [a, b, c, x, y, z]

; "🁳", DOMINO TILE VERTICAL-02-02, and
; "⌘", PLACE OF INTEREST SIGN, in a text string:
a = "D\u{6f}mino's \u{1F073} + \u{2318}"      ; \u{}-escape 3 chars
b = "Domino's \uD83C\uDC73 + \u2318"          ; escape JSON-like
c = "Domino's 🁳 + ⌘"                          ; unescaped

; in a byte string given as text, the ' needs to be escaped:
x = 'D\u{6f}mino\u{27}s \u{1F073} + \u{2318}' ; \u{}-escape 4 chars
y = 'Domino\'s \uD83C\uDC73 + \u2318'         ; escape JSON-like
z = 'Domino\'s 🁳 + ⌘'                         ; escape ' only
]]></sourcecode>
        </figure>
        <t>In this example, the rules a to c and x to z all produce strings with
byte-wise identical content: a to c are text strings and x to z
are byte strings.
<xref target="string-examples-pretty"/> illustrates this by showing the output generated from
the <tt>start</tt> rule in <xref target="string-examples"/>, using pretty-printed hexadecimal.</t>
        <figure anchor="string-examples-pretty">
          <name>Generated CBOR from CDDL Example (Pretty-Printed Hexadecimal)</name>
          <sourcecode type="cbor-pretty"><![CDATA[
86                                      # array(6)
   73                                   # text(19)
      446f6d696e6f277320f09f81b3202b20e28c98 # "Domino's 🁳 + ⌘"
   73                                   # text(19)
      446f6d696e6f277320f09f81b3202b20e28c98 # "Domino's 🁳 + ⌘"
   73                                   # text(19)
      446f6d696e6f277320f09f81b3202b20e28c98 # "Domino's 🁳 + ⌘"
   53                                   # bytes(19)
      446f6d696e6f277320f09f81b3202b20e28c98 # "Domino's 🁳 + ⌘"
   53                                   # bytes(19)
      446f6d696e6f277320f09f81b3202b20e28c98 # "Domino's 🁳 + ⌘"
   53                                   # bytes(19)
      446f6d696e6f277320f09f81b3202b20e28c98 # "Domino's 🁳 + ⌘"
]]></sourcecode>
        </figure>
	

</section>
    </section>
    <section anchor="small-enabling-grammar-changes">
      <name>Small Enabling Grammar Changes</name>
      <t>Each subsection that follows specifies a small change to the
grammar that is intended to enable certain kinds of specifications.
These changes are backward compatible (i.e., CDDL files that
comply with <xref target="RFC8610"/> continue to match the updated grammar) but not
necessarily forward compatible (i.e., CDDL specifications that make
use of these changes cannot necessarily be processed by existing implementations of <xref target="RFC8610"/>).</t>
      <section anchor="empty">
        <name>Empty Data Models</name>
        <t><xref target="RFC8610"/> requires a CDDL file to have at least one rule.</t>
        <figure anchor="empty-orig">
          <name>ABNF from RFC 8610 for Top-Level Rule <tt>cddl</tt></name>
          <sourcecode type="abnf"><![CDATA[
; ABNF from RFC 8610:
cddl = S 1*(rule S)
]]></sourcecode>
        </figure>
        <t>This makes sense when the file has to stand alone, as a CDDL data
model needs to have at least one rule to provide an entry point (i.e., a start
rule).</t>
        <t>With CDDL modules <xref target="I-D.ietf-cbor-cddl-modules"/>, CDDL files can also include directives,
and these might be the source of all the rules that
ultimately make up the module created by the file.
Any other rule content in the file has to be available for directive
processing, making the requirement for at least one rule cumbersome.</t>
        <t>Therefore, the present update extends the grammar as in <xref target="empty-new"/>
and turns the existence of at least one rule into a semantic constraint, to
be fulfilled after processing of all directives.</t>
        <figure anchor="empty-new">
          <name>Update to Top-Level ABNF in  Appendices B and C of RFC 8610</name>
          <sourcecode type="abnf" name="cddl-new-cddl.abnf"><![CDATA[
; new top-level rule:
cddl = S *(rule S)
]]></sourcecode>
        </figure>
      </section>
      <section anchor="tagnum">
	
        <name>Non-Literal Tag Numbers and Simple Values</name>
        <t>The existing ABNF syntax for expressing tags in CDDL is as follows:</t>
        <figure anchor="tag-orig">
          <name>Original ABNF from RFC 8610 for Tag Syntax</name>
          <sourcecode type="abnf"><![CDATA[
; extracted from the ABNF in RFC 8610:
type2 =/ "#" "6" ["." uint] "(" S type S ")"
]]></sourcecode>
        </figure>
        <t>This means tag numbers can only be given as literal numbers (uints).
Some specifications operate on ranges of tag numbers;  for example, <xref target="RFC9277"/>
has a range of tag numbers 1668546817 (0x63740101) to 1668612095
(0x6374FFFF) to tag specific content formats.
This cannot currently be expressed in CDDL.
Similar considerations apply to simple values (<tt>#7.</tt>xx).</t>
        <t>This update extends the syntax to the following:</t>
        <figure anchor="tag-new">
          <name>Update to Tag and Simple Value ABNF in Appendices B and C of RFC 8610</name>
          <sourcecode type="abnf" name="cddl-new-tag.abnf"><![CDATA[
; new rules collectively defining the tagged case:
type2 =/ "#" "6" ["." head-number] "(" S type S ")"
       / "#" "7" ["." head-number]
head-number = uint / ("<" type ">")
]]></sourcecode>
        </figure>
        <t>For <tt>#6</tt>, the <tt>head-number</tt> stands for the tag number.
For <tt>#7</tt>, the <tt>head-number</tt> stands for the simple value if it is in
the ranges 0..23 or 32..255 (as per Section <xref target="RFC8949" section="3.3" sectionFormat="bare"/> of RFC 8949 <xref target="STD94"/>,
the simple values 24..31 are not used).
For 24..31, the <tt>head-number</tt> stands for the "additional
information", e.g., <tt>#7.25</tt> or <tt>#7.&lt;25&gt;</tt> is a float16, etc.
(All ranges mentioned here are inclusive.)</t>
        <t>So the above range can be expressed in a CDDL fragment such as:</t>
        <sourcecode type="cddl"><![CDATA[
ct-tag<content> = #6.<ct-tag-number>(content)
ct-tag-number = 1668546817..1668612095
; or use 0x63740101..0x6374FFFF
]]></sourcecode>
       <aside> <t>Notes:</t>
        <ol spacing="normal" type="1"><li>
	  
            <t>This syntax reuses the angle bracket syntax for generics;
this reuse is innocuous because a generic parameter or argument only ever
occurs after a rule name (<tt>id</tt>), while it occurs after the "<tt>.</tt>" (dot) character here.
(Whether there is potential for human confusion can be debated; the
above example deliberately uses generics as well.)</t>
          </li>
          <li>

            <t>The updated ABNF grammar makes it a bit more explicit that the
 number given after the optional dot is the value of the argument:
 for tags and simple
 values, it is not giving the CBOR "additional information”, 
 as it is with other uses of <tt>#</tt> in CDDL.
(Adding this observation to <xref section="2.2.3" sectionFormat="of" target="RFC8610"/> is the subject
of <xref target="Err6575"/>; it is correctly noted in <xref section="3.6" sectionFormat="of" target="RFC8610"/>.)
In hindsight, maybe a different character than the dot should have
been chosen for this special case; however, changing the grammar
in the current document would have been too disruptive.</t>
          </li>
        </ol></aside>
      </section>
    </section>
    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>The grammar fixes and updates in this document are not believed to
create additional security considerations.
The security considerations in <xref section="5" sectionFormat="of" target="RFC8610"/> apply.
Specifically, the potential for confusion is increased in an
environment that uses a combination of CDDL tools, some of which have
been updated and some of which have not, in particular based on
<xref target="clari"/>.</t>
      <t>Attackers may want to exploit such potential confusion by crafting
CDDL models that are interpreted differently by different parts of a
system.
There will be a period of transition from the details that the grammar in
<xref target="RFC8610"/> handled in a less well-defined way, to the updated
grammar defined in the present document.  This transition might offer one (but not the only) type of opportunity
   for the kind of attack that relies on differences between
   implementations.
Implementations that make use of CDDL models operationally already
need to ascertain the provenance (and thus authenticity and integrity)
and applicability of models they employ.
At the time of writing, it is expected that the models will generally
be processed by a software developer, within a software development
environment.
Therefore, developers are advised to treat CDDL models with
the same care as any other source code.</t>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>

      <t>This document has no IANA actions.</t>
    </section>
  </middle>
  <back>
    <displayreference target="I-D.ietf-cbor-cddl-modules" to="CDDL-MODULES"/>
    <displayreference target="I-D.ietf-cbor-edn-literals" to="EDN-LITERALS"/>
    <references>
      <name>References</name>
      <references anchor="sec-normative-references">
        <name>Normative References</name>

	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8610.xml"/>

<xi:include href="https://bib.ietf.org/public/rfc/bibxml9/reference.STD.0068.xml" />

<xi:include href="https://bib.ietf.org/public/rfc/bibxml9/reference.STD.0094.xml" />

      </references>
      <references anchor="sec-informative-references">
        <name>Informative References</name>

<xi:include href="https://bib.ietf.org/public/rfc/bibxml9/reference.STD.0080.xml" />

	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.7405.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9165.xml"/>

<!-- [I-D.ietf-cbor-cddl-modules];I-D exists as of 9/5/24 -->
        <xi:include href="https://datatracker.ietf.org/doc/bibxml3/draft-ietf-cbor-cddl-modules.xml"/>

<!-- [I-D.ietf-cbor-edn-literals];Waiting for AD go-ahead as of 9/5/24 -->
        <xi:include href="https://datatracker.ietf.org/doc/bibxml3/draft-ietf-cbor-edn-literals.xml"/>

        <reference anchor="Err6278" target="https://www.rfc-editor.org/errata/eid6278" quote-title="false">
          <front>
            <title>Erratum ID 6278</title>
            <author>
              <organization>RFC Errata</organization>
            </author>
          </front>
          <refcontent>RFC 8610</refcontent>
        </reference>

        <reference anchor="Err6526" target="https://www.rfc-editor.org/errata/eid6526" quote-title="false">
          <front>
            <title>Erratum ID 6526</title>
            <author>
              <organization>RFC Errata</organization>
            </author>
          </front>
          <refcontent>RFC 8610</refcontent>
        </reference>

        <reference anchor="Err6527" target="https://www.rfc-editor.org/errata/eid6527" quote-title="false">
          <front>
            <title>Erratum ID 6527</title>
            <author>
              <organization>RFC Errata</organization>
            </author>
            <date/>
          </front>
          <refcontent>RFC 8610</refcontent>
        </reference>

        <reference anchor="Err6543" target="https://www.rfc-editor.org/errata/eid6543" quote-title="false">
          <front>
            <title>Erratum ID 6543</title>
            <author>
              <organization>RFC Errata</organization>
            </author>
          </front>
          <refcontent>RFC 8610</refcontent>
        </reference>

        <reference anchor="Err6575" target="https://www.rfc-editor.org/errata/eid6575" quote-title="false">
          <front>
            <title>Erratum ID 6575</title>
            <author>
              <organization>RFC Errata</organization>
            </author>
          </front>
          <refcontent>RFC 8610</refcontent>
        </reference>

	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9277.xml"/>

	<reference anchor="UNICODE" target="https://www.unicode.org/versions/latest/" quoteTitle="true" derivedAnchor="UNICODE">
<front>
<title>The Unicode Standard</title>
<author>
<organization showOnFrontPage="true">The Unicode Consortium</organization>
</author>
</front>
</reference>
      </references>
    </references>


<section anchor="collected-abnf-appendix">
      <name>Updated Collected ABNF for CDDL</name>
      <t>This appendix is normative.</t>
      <t>It provides the full ABNF from <xref target="RFC8610"/> as updated by the present document.</t>
      <figure anchor="collected-abnf">
        <name>ABNF for CDDL as Updated</name>
        <sourcecode type="abnf" name="cddl-updated-complete.abnf"><![CDATA[
cddl = S *(rule S)
rule = typename [genericparm] S assignt S type
     / groupname [genericparm] S assigng S grpent

typename = id
groupname = id

assignt = "=" / "/="
assigng = "=" / "//="

genericparm = "<" S id S *("," S id S ) ">"
genericarg = "<" S type1 S *("," S type1 S ) ">"

type = type1 *(S "/" S type1)

type1 = type2 [S (rangeop / ctlop) S type2]
; space may be needed before the operator if type2 ends in a name

type2 = value
      / typename [genericarg]
      / "(" S type S ")"
      / "{" S group S "}"
      / "[" S group S "]"
      / "~" S typename [genericarg]
      / "&" S "(" S group S ")"
      / "&" S groupname [genericarg]
      / "#" "6" ["." head-number] "(" S type S ")"
      / "#" "7" ["." head-number]
      / "#" DIGIT ["." uint]                ; major/ai
      / "#"                                 ; any
head-number = uint / ("<" type ">")

rangeop = "..." / ".."

ctlop = "." id

group = grpchoice *(S "//" S grpchoice)

grpchoice = *(grpent optcom)

grpent = [occur S] [memberkey S] type
       / [occur S] groupname [genericarg]  ; preempted by above
       / [occur S] "(" S group S ")"

memberkey = type1 S ["^" S] "=>"
          / bareword S ":"
          / value S ":"

bareword = id

optcom = S ["," S]

occur = [uint] "*" [uint]
      / "+"
      / "?"

uint = DIGIT1 *DIGIT
     / "0x" 1*HEXDIG
     / "0b" 1*BINDIG
     / "0"

value = number
      / text
      / bytes

int = ["-"] uint

; This is a float if it has fraction or exponent; int otherwise
number = hexfloat / (int ["." fraction] ["e" exponent ])
hexfloat = ["-"] "0x" 1*HEXDIG ["." 1*HEXDIG] "p" exponent
fraction = 1*DIGIT
exponent = ["+"/"-"] 1*DIGIT

text = %x22 *SCHAR %x22
SCHAR = %x20-21 / %x23-5B / %x5D-7E / NONASCII / SESC

SESC = "\" ( %x22 / "/" / "\" /                 ; \" \/ \\
             %x62 / %x66 / %x6E / %x72 / %x74 / ; \b \f \n \r \t
             (%x75 hexchar) )                   ; \uXXXX

hexchar = "{" (1*"0" [ hexscalar ] / hexscalar) "}" /
          non-surrogate / (high-surrogate "\" %x75 low-surrogate)
non-surrogate = ((DIGIT / "A"/"B"/"C" / "E"/"F") 3HEXDIG) /
                ("D" %x30-37 2HEXDIG )
high-surrogate = "D" ("8"/"9"/"A"/"B") 2HEXDIG
low-surrogate = "D" ("C"/"D"/"E"/"F") 2HEXDIG
hexscalar = "10" 4HEXDIG / HEXDIG1 4HEXDIG
          / non-surrogate / 1*3HEXDIG

bytes = [bsqual] %x27 *BCHAR %x27
BCHAR = %x20-26 / %x28-5B / %x5D-7E / NONASCII / SESC / "\'" / CRLF
bsqual = "h" / "b64"

id = EALPHA *(*("-" / ".") (EALPHA / DIGIT))
ALPHA = %x41-5A / %x61-7A
EALPHA = ALPHA / "@" / "_" / "$"
DIGIT = %x30-39
DIGIT1 = %x31-39
HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
HEXDIG1 = DIGIT1 / "A" / "B" / "C" / "D" / "E" / "F"
BINDIG = %x30-31

S = *WS
WS = SP / NL
SP = %x20
NL = COMMENT / CRLF
COMMENT = ";" *PCHAR CRLF
PCHAR = %x20-7E / NONASCII
NONASCII = %xA0-D7FF / %xE000-10FFFD
CRLF = %x0A / %x0D.0A
]]></sourcecode>
      </figure>
    </section>
    <section anchor="Err6543-covered">
      <name>Details about Covering Erratum ID 6543</name>
      <t>This appendix is informative.</t>
      <t><xref target="Err6543"/> notes that
the ABNF used in <xref target="RFC8610"/> for the content of byte string literals
lumps together byte strings notated as text with byte strings notated
      in base16 (hex) or base64 (but see also updated BCHAR rule in <xref target="e6527-new2"/>):</t>
     
      <figure anchor="e6527-orig2a">
        <name>Original ABNF from RFC 8610 for BCHAR</name>
        <sourcecode type="abnf"><![CDATA[
; ABNF from RFC 8610:
bytes = [bsqual] %x27 *BCHAR %x27
BCHAR = %x20-26 / %x28-5B / %x5D-10FFFD / SESC / CRLF
]]></sourcecode>
      </figure>
      <section numbered="true" anchor="change-proposed-by-errata-report-6543">
        <name>Change Proposed by Erratum ID 6543</name>
        <t>Erratum ID 6543 proposes handling the two cases in separate
ABNF rules (where, with an updated SESC, BCHAR obviously needs to be
updated as above):</t>
        <figure anchor="e6543-1">
          <name>Proposal from Erratum ID 6543 to Split the Byte String Rules</name>
          <sourcecode type="abnf"><![CDATA[
; Proposal from Erratum ID 6543:
bytes = %x27 *BCHAR %x27
      / bsqual %x27 *QCHAR %x27
BCHAR = %x20-26 / %x28-5B / %x5D-10FFFD / SESC / CRLF
QCHAR = DIGIT / ALPHA / "+" / "/" / "-" / "_" / "=" / WS
]]></sourcecode>
        </figure>
        <t>This potentially causes a subtle change, which is hidden in the WS rule:</t>
        <figure anchor="e6543-2">
          <name>ABNF Definition of WS from RFC 8610</name>
          <sourcecode type="abnf"><![CDATA[
; ABNF from RFC 8610:
WS = SP / NL
SP = %x20
NL = COMMENT / CRLF
COMMENT = ";" *PCHAR CRLF
PCHAR = %x20-7E / %x80-10FFFD
CRLF = %x0A / %x0D.0A
]]></sourcecode>
        </figure>
        <t>This allows any non-C0 character in a comment, so this fragment
becomes possible:</t>
        <sourcecode type="cddl"><![CDATA[
foo = h'
   43424F52 ; 'CBOR'
   0A       ; LF, but don't use CR!
'
]]></sourcecode>
        <t>The current text is not unambiguously saying whether the three apostrophes
need to be escaped with a <tt>\</tt> or not, as in:</t>
        <sourcecode type="cddl"><![CDATA[
foo = h'
   43424F52 ; \'CBOR\'
   0A       ; LF, but don\'t use CR!
'
]]></sourcecode>
        <t>... which would be supported by the existing ABNF in <xref target="RFC8610"/>.</t>
      </section>
      <section numbered="true" anchor="no-further-change-needed-after-updating-string-literal-grammar-e6527">
        <name>No Further Change Needed after Updating String Literal Grammar</name>
	
        <t>This document takes the simpler approach of leaving the processing of
the content of the byte string literal to a semantic step after
processing the syntax of the <tt>bytes</tt> and <tt>BCHAR</tt> rules, as updated by
Figures <xref target="e6527-new1" format="counter"/> and <xref target="e6527-new2" format="counter"/> in <xref target="e6527"/> (updates prompted by the combination
of <xref target="Err6527"/> and <xref target="Err6278"/>).</t>
        <t>Therefore, the rules in <xref target="e6543-2"/> (as updated by <xref target="e6527-new2"/>) are 
applied to the result of this
processing where <tt>bsqual</tt> is given as <tt>h</tt> or <tt>b64</tt>.</t>
        <t>Note that this approach also works well with the use of byte strings
in <xref section="3" sectionFormat="of" target="RFC9165"/>.
It does require some care when copying-and-pasting into CDDL models from ABNF
that contains single quotes (which may also hide as apostrophes
in comments); these need to be escaped or possibly replaced by <tt>%x27</tt>.</t>
        <t>Finally, the approach taken lends support to extending <tt>bsqual</tt> in CDDL
similar to the way this is done for CBOR diagnostic notation in <xref target="I-D.ietf-cbor-edn-literals"/>.
(Note that, at the time of writing, the processing of string literals is quite similar for both
CDDL and Extended Diagnostic Notation (EDN), except that CDDL has end-of-line comments that are "<tt>;</tt>" based and EDN has
two comment syntaxes: one in-line "<tt>/</tt>" based and one end-of-line "<tt>#</tt>" based.)</t>
      </section>
    </section>
    <section numbered="false" anchor="acknowledgments">
      <name>Acknowledgments</name>
      <t>Many thanks go to the submitters of the errata reports addressed in
this document.
In one of the ensuing discussions, <contact fullname="Doug Ewell"/> proposed  defining an
ABNF rule "NONASCII", of which we have included the essence.
Special thanks to the reviewers <contact fullname="Marco Tiloca"/>, <contact fullname="Christian Amsüss"/> (Shepherd Review and further guidance), <contact fullname="Orie Steele"/> (AD
Review and further guidance), and <contact fullname="Éric Vyncke"/>
(detailed IESG review).</t>
    </section>
  </back>
</rfc>
