idnits 2.17.1 draft-crocker-abnf-v3-00.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Looks like you're using RFC 2026 boilerplate. This must be updated to follow RFC 3978/3979, as updated by RFC 4748. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing document type: Expected "INTERNET-DRAFT" in the upper left hand corner of the first page ** Missing expiration date. The document expiration date should appear on the first and last page. == No 'Intended status' indicated for this document; assuming Proposed Standard == The page length should not exceed 58 lines per page, but there was 1 longer page, the longest (page 1) being 708 lines Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an Abstract section. ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack an Authors' Addresses Section. ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. Miscellaneous warnings: ---------------------------------------------------------------------------- == Line 133 has weird spacing: '...ng with an al...' == Line 145 has weird spacing: '... use of a rul...' == Line 393 has weird spacing: '...ires at least...' == Line 407 has weird spacing: '...rrences of Demon Internet Ltd 5 June 23, 2002 7 Augmented BNF for Syntax Specifications: ABNF 9 Status Of This Memo 11 This document is an Internet-Draft and is in full 12 conformance with all provisions of Section 10 of 13 RFC2026. 15 Internet-Drafts are working documents of the Internet 16 Engineering Task Force (IETF), its areas, and its 17 working groups. Note that other groups may also 18 distribute working documents as Internet-Drafts. 20 Internet-Drafts are draft documents valid for a maximum 21 of six months and may be updated, replaced, or obsoleted 22 by other documents at any time. It is inappropriate to 23 use Internet-Drafts as reference material or to cite 24 them other than as "work in progress." 26 The list of current Internet-Drafts can be accessed at 27 http://www.ietf.org/ietf/1id-abstracts.txt 29 The list of Internet-Draft Shadow Directories can be 30 accessed at http://www.ietf.org/shadow.html. 32 Table Of Contents 34 1. Introduction 35 2. Rule Definition 36 2.1 Rule Naming 37 2.2 Rule Form 38 2.3 Terminal Values 39 2.4 External 40 Encodings 41 3. Operators 42 3.1 Concatenation -- 43 Rule1 Rule2 44 3.2 Alternatives -- 45 Rule1 / Rule2 46 3.3 Incremental 47 Alternatives -- 48 Rule1 =/ Rule2 49 3.4 Value Range 50 Alternatives -- 51 %c##-## 52 3.5 Sequence Group -- 53 (Rule1 Rule2) 54 3.6 Variable 55 Repetition -- 56 *Rule 57 3.7 Specific 58 Repetition -- 59 nRule 60 3.8 Optional Sequence 61 -- [Rule] 62 3.9 ; Comment 63 3.10 Operator 64 Precedence 65 4. ABNF Definition of 66 ABNF 67 5. Security 68 Considerations 69 6. Appendix A - Core 70 6.1 Core Rules 71 6.2 Common Encoding 72 7. Appendix B - 73 Enhancements 74 7.1 Concatenated 75 Terminal Values 76 7.2 Binary Literal 77 Values 78 8. Acknowledgements 79 9. References 80 10. Contact 82 0. Change Notes 84 Per Alvestrand: 86 ; Suggested change to allow blank lines within rules: 87 c-wsp = *c-nl WSP 88 ; This allows comments at col. 1 within rules; is this a 89 problem? 90 ;c-wsp = WSP / (c-nl WSP) 92 and: 94 prose-val = "<" *(%x20-3D / %x3F-7E / c-wsp) ">" 95 ; bracketed string of SP and VCHAR 96 ; without angles 97 ; prose description, to be used as 98 ; last resort 99 ; c-wsp added after DRUMS chair's 100 note 1998-08-11 101 ; orig: prose-val = "<" *(%x20-3D / %x3F-7E ) ">" 103 1. Introduction 105 Internet technical specifications often need to define a 106 format syntax and are free to employ whatever notation their 107 authors deem useful. Over the years, a modified version of 108 Backus-Naur Form (BNF), called Augmented BNF (ABNF), has 109 been popular among many Internet specifications. It 110 balances compactness and simplicity, with reasonable 111 representational power. In the early days of the Arpanet, 112 each specification contained its own definition of ABNF. 113 This included the email specifications, [RFC733] and then 114 [RFC822] which have come to be the common citations for 115 defining ABNF. The current document separates out that 116 definition, to permit selective reference. Predictably, it 117 also provides some modifications and enhancements. 119 The differences between standard BNF and ABNF involve naming 120 rules, repetition, alternatives, order-independence, and 121 value ranges. Appendix A (Core) supplies rule definitions 122 and encoding for a core lexical analyzer of the type common 123 to several Internet specifications. It is provided as a 124 convenience and is otherwise separate from the meta language 125 defined in the body of this document, and separate from its 126 formal status. 128 2. Rule Definition 130 2.1 Rule Naming 132 The name of a rule is simply the name itself; that is, a 133 sequence of characters, beginning with an alphabetic 134 character, and followed by a combination of alphabetics, 135 digits and hyphens (dashes). 137 NOTE: Rule names are case-INsensitive 139 The names , , and 140 all refer to the same rule. 142 Unlike original BNF, angle brackets ("<", ">") are not 143 required. However, angle brackets may be used around a 144 rule name whenever their presence will facilitate discerning 145 the use of a rule name. This is typically restricted to 146 rule name references in free-form prose, or to distinguish 147 partial rules that combine into a string not separated by 148 white space, such as shown in the discussion about 149 repetition, below. 151 2.2 Rule Form 153 A rule is defined by the following sequence: 155 name = elements CRLF 157 where is the name of the rule, is one or 158 more rule names or terminal specifications and is the 159 end-of-line indicator, carriage return followed by line 160 feed. The equal sign separates the name from the definition 161 of the rule. The elements form a sequence of one or more 162 rule names and/or value definitions, combined according to 163 the various operators, defined in this document, such as 164 alternative and repetition. 166 For visual ease, rule definitions are left aligned. When a 167 rule requires multiple lines, the continuation lines are 168 indented, although a line containing only a comment need not 169 be indented. The left alignment and indentation are 170 relative to the first lines of the ABNF rules and need not 171 match the left margin of the document. 173 2.3 Terminal Values 175 Rules resolve into a string of terminal values, sometimes 176 called characters. In ABNF a character is merely a non- 177 negative integer. In certain contexts a specific mapping 178 (encoding) of values into a character set (such as ASCII) 179 will be specified. 181 Terminals are specified by one or more numeric characters 182 with the base interpretation of those characters indicated 183 explicitly. The following bases are currently defined: 185 d = decimal 187 x = hexadecimal 189 Hence: 191 CR = %d13 193 CR = %x0D 195 respectively specify the decimal and hexadecimal 196 representation of [US-ASCII] for carriage return. 198 ABNF permits specifying literal text string directly, 199 enclosed in quotation marks. Hence: 201 command = "command string" 203 Literal text strings are interpreted as a concatenated set 204 of printable characters. 206 NOTE: ABNF strings are case-INsensitive and 207 the character set for these strings is 208 US-ASCII. 210 Hence: 212 rulename = "abc" 214 and: 216 rulename = "aBc" 218 will match "abc", "Abc", "aBc", "abC", "ABc", "aBC", "AbC" 219 and "ABC". 221 NOTE: To specify a rule that IS case 222 SENSITIVE, specify the characters 223 individually. 225 For example: 227 rulename = %d97 %d98 %d99 229 will match only the string that comprises only lowercased 230 characters, 'abc'. 232 2.4 External Encodings 234 External representations of terminal value characters will 235 vary according to constraints in the storage or transmission 236 environment. Hence, the same ABNF-based grammar may have 237 multiple external encodings, such as one for a 7-bit US- 238 ASCII environment, another for a binary octet environment 239 and still a different one when 16-bit Unicode is used. 240 Encoding details are beyond the scope of ABNF, although 241 Appendix A (Core) provides definitions for a 7-bit US-ASCII 242 environment as has been common too much of the Internet. 244 By separating external encoding from the syntax, it is 245 intended that alternate encoding environments can be used 246 for the same syntax. 248 Examples in the text below use the US-ASCII environment as 249 specified in Appendix A. 251 3. Operators 253 3.1 Concatenation -- Rule1 Rule2 255 A rule can define a simple, ordered string of values -- that 256 is, a concatenation of contiguous characters -- by listing a 257 sequence of rule names. For example: 259 foo = %x61 ; a 261 bar = %x62 ; b 263 mumble = foo bar foo 265 So that the rule matches the lowercase string 266 "aba". 268 LINEAR WHITE SPACE: Concatenation is at the core of the 269 ABNF parsing model. A string of contiguous characters 270 (values) is parsed according to the rules defined in ABNF. 271 For Internet specifications, there is some history of 272 permitting linear white space (space and horizontal tab) to 273 be freely--and implicitly--interspersed around major 274 constructs, such as delimiting special characters or atomic 275 strings. 277 NOTE: This specification for ABNF does not 278 provide for implicit specification of 279 linear white space. 281 Any grammar that wishes to permit linear white space around 282 delimiters or string segments must specify it explicitly. 283 It is often useful to provide for such white space in "core" 284 rules that are then used variously among higher-level rules. 285 The "core" rules might be formed into a lexical analyzer or 286 simply might be part of the main ruleset. 288 3.2 Alternatives -- Rule1 / Rule2 290 Elements separated by forward slash ("/") are alternatives. 291 Therefore, 293 foo / bar 295 will accept or . 297 NOTE: A quoted string containing alphabetic 298 characters is special form for 299 specifying alternative characters and is 300 interpreted as a non-terminal 301 representing the set of combinatorial 302 strings with the contained characters, 303 in the specified order but with any 304 mixture of upper and lower case. 306 3.3 Incremental Alternatives -- Rule1 =/ Rule2 308 It is sometimes convenient to specify a list of alternatives 309 in fragments. That is, an initial rule may match one or 310 more alternatives, with later rule definitions adding to the 311 set of alternatives. This is particularly useful for 312 otherwise-independent specifications which derive from the 313 same parent rule set, such as often occurs with parameter 314 lists. ABNF permits this incremental definition through the 315 construct: 317 oldrule =/ additional-alternatives 319 So that the rule set: 321 ruleset = alt1 / alt2 323 ruleset =/ alt3 325 ruleset =/ alt4 / alt5 327 is the same as specifying: 329 ruleset = alt1 / alt2 / alt3 / alt4 / alt5 331 3.4 Value Range Alternatives -- %c##-## 333 A range of alternative numeric values can be specified 334 compactly, using dash ("-") to indicate the range of 335 alternative values. Hence: 337 DIGIT = %x30-39 339 is equivalent to: 341 DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / 342 "6" / "7" / "8" / "9" 344 Concatenated numeric values and numeric value ranges can not 345 be specified in the same string. A numeric value may use 346 the dotted notation for concatenation or it may use the dash 347 notation to specify one value range. Hence, to specify one 348 printable character, between end of line sequences, the 349 specification could be: 351 onechar-line = %x0D %0A %x20-7E %x0D %0A 353 3.5 Sequence Group -- (Rule1 Rule2) 355 Elements enclosed in parentheses are treated as a single 356 element, whose contents are STRICTLY ORDERED. Thus, 358 elem (foo / bar) blat 360 which matches (elem foo blat) or (elem bar blat). 362 elem foo / bar blat 364 matches (elem foo) or (bar blat). 366 NOTE: It is strongly advised to use grouping 367 notation, rather than to rely on proper 368 reading of "bare" alternations, when 369 alternatives consist of multiple rule 370 names or literals. 372 Hence it is recommended that instead of the above form, the 373 form: 375 (elem foo) / (bar blat) 377 be used. It will avoid misinterpretation by casual readers. 379 The sequence group notation is also used within free text to 380 set off an element sequence from the prose. 382 3.6 Variable Repetition -- *Rule 384 The operator "*" preceding an element indicates repetition. 385 The full form is: 387 *element 389 where and are optional decimal values, indicating at 390 least and at most occurrences of element. 392 Default values are 0 and infinity so that * allows 393 any number, including zero; 1* requires at least 394 one; 3*3 allows exactly 3 and 1*2 allows 395 one or two. 397 3.7 Specific Repetition -- nRule 399 A rule of the form: 401 element 403 is equivalent to 405 *element 407 That is, exactly occurrences of . Thus 408 2DIGIT is a 2-digit number, and 3ALPHA is a string of three 409 alphabetic characters. 411 3.8 Optional Sequence -- [Rule] 413 Square brackets enclose an optional element sequence: 415 [foo bar] 417 is equivalent to 419 *1(foo bar). 421 3.9 ; Comment 423 A semi-colon starts a comment that continues to the end of 424 line. This is a simple way of including useful notes in 425 parallel with the specifications. 427 3.10 Operator Precedence 429 The various mechanisms described above have the following 430 precedence, from highest (binding tightest) at the top, to 431 lowest and loosest at the bottom: 433 Strings, Names formation 434 Comment 435 Value range 436 Repetition 437 Grouping, Optional 438 Concatenation 439 Alternative 441 Use of the alternative operator, freely mixed with 442 concatenations can be confusing. 444 Again, it is recommended that the grouping 445 operator be used to make explicit concatenation 446 groups. 448 4. ABNF Definition of ABNF 450 This syntax uses the rules provided in Appendix A (Core). 452 rulelist = 1*( rule / (*c-wsp c-nl) ) 454 rule = rulename defined-as elements c-nl 455 ; continues if next line 456 ; starts with white space and 457 ; is not comment 459 rulename = ALPHA *(ALPHA / DIGIT / "-") 461 defined-as = *c-wsp ("=" / "=/") *c-wsp 462 ; basic rules definition and 463 ; incremental alternatives 465 elements = alternation *c-wsp 467 c-wsp = WSP / (c-nl WSP) 469 c-nl = comment / CRLF 470 ; comment or newline 472 comment = ";" *(WSP / VCHAR) CRLF 474 alternation = concatenation 475 *(*c-wsp "/" *c-wsp concatenation) 477 concatenation = repetition *(1*c-wsp repetition) 479 repetition = [repeat] element 481 repeat = 1*DIGIT / (*DIGIT "*" *DIGIT) 483 element = rulename / group / option / 484 char-val / num-val / prose-val 486 group = "(" *c-wsp alternation *c-wsp ")" 488 option = "[" *c-wsp alternation *c-wsp "]" 490 char-val = DQUOTE *(%x20-21 / %x23-7E) DQUOTE 491 ; quoted string of SP and 492 ; VCHAR without DQUOTE 494 num-val = "%" (bin-val / dec-val / hex-val) 496 bin-val = "b" 1*BIT [ "-" 1*BIT ] 497 ; a single bit string or a 498 ; range of alternative bit 499 ; values 501 dec-val = "d" 1*DIGIT [ "-" 1*DIGIT ] 503 hex-val = "x" 1*HEXDIG [ "-" 1*HEXDIG ] 505 prose-val = "<" *(%x20-3D / %x3F-7E / c-wsp) ">" 506 ; bracketed string of SP and VCHAR 507 ; without angles 508 ; prose description, to be used as 509 ; last resort 511 5. Security Considerations 513 Security is truly believed to be irrelevant to this 514 document. 516 6. Appendix A - Core 518 This Appendix is provided as a convenient core for specific 519 grammars. The definitions may be used as a core set of 520 rules. 522 6.1 Core Rules 524 Certain basic rules are in uppercase, such as SP, HTAB, 525 CRLF, DIGIT, ALPHA, etc. 527 ALPHA = %x41-5A / %x61-7A ; A-Z / a-z 529 BIT = "0" / "1" 531 CHAR = %x01-7F 532 ; any 7-bit US-ASCII 533 ; character, excluding NUL 535 CR = %x0D 536 ; carriage return 538 CRLF = CR LF 539 ; Internet standard newline 541 CTL = %x00-1F / %x7F 542 ; controls 544 DIGIT = %x30-39 545 ; 0-9 547 DQUOTE = %x22 548 ; " (Double Quote) 550 HEXDIG = DIGIT / 551 "A" / "B" / "C" / "D" / "E" / "F" 553 HTAB = %x09 554 ; horizontal tab 556 LF = %x0A 557 ; linefeed 559 LWSP = *(WSP / CRLF WSP) 560 ; linear white space 561 ; (past newline) 563 OCTET = %x00-FF 564 ; 8 bits of data 566 SP = %x20 567 ; space 569 VCHAR = %x21-7E 570 ; visible (printing) 571 ; characters 573 WSP = SP / HTAB 574 ; white space 576 6.2 Common Encoding 578 Externally, data are represented as "network virtual ASCII", 579 namely 7-bit US-ASCII in an 8-bit field, with the high (8th) 580 bit set to zero. A string of values is in "network byte 581 order" with the higher-valued bytes represented on the left- 582 hand side and being sent over the network first. 584 7. Appendix B - Enhancements 586 This section provides some additional features for ABNF that 587 are not part of the official specification. The features 588 contained here are expected to have benefit, eventually, but 589 did not gain immediate use. Writers of specifications 590 wishing to use these features may cite the relevant sub- 591 sections to this appendix. 593 7.1 Concatenated Terminal Values 595 A concatenated string of such values is specified compactly, 596 using a period (".") to indicate separation of characters 597 within that value. Hence: 599 CRLF = %d13.10 601 Therefore, 603 rulename = %d97.98.99 605 will match only the string that comprises only lowercased 606 characters, abc. 608 If a grammar uses concatenated terminal values, then the 609 "ABNF Definition of ABNF" will modify two rules to be: 611 dec-val = "d" 1*DIGIT 612 [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ] 614 hex-val = "x" 1*HEXDIG 615 [ 1*("." 1*HEXDIG) 616 / ("-" 1*HEXDIG) ] 618 7.2 Binary Literal Values 620 Terminals are specified by one or more numeric characters 621 with the base interpretation of those characters indicated 622 explicitly. The following, additional base is defined: 624 b = binary 626 If binary literal values are used with the concatenation 627 mechanism defined above, then the "ABNF Definition of ABNF" 628 modifies the relevant rule to be: 630 bin-val = "b" 1*BIT [ "-" 1*BIT ] 631 ; a single bit string or a 632 ; range of alternative bit 633 ; values 635 8. Acknowledgements 637 The syntax for ABNF was originally specified in [RFC733]. 638 Ken L. Harrenstien, of SRI International, was responsible 639 for re-coding the BNF into an augmented BNF that makes the 640 representation smaller and easier to understand. 642 This recent project began as a simple effort to cull out the 643 portion of [RFC822], which has been repeatedly cited by non- 644 email specification writers, namely the description of 645 augmented BNF. Rather than simply and blindly converting 646 the existing text into a separate document, the working 647 group chose to give careful consideration to the 648 deficiencies, as well as benefits, of the existing 649 specification and related specifications available over the 650 last 15 years and therefore to pursue enhancement. This 651 turned the project into something rather more ambitious than 652 first intended. Interestingly the result is not massively 653 different from that original, although decisions such as 654 removing the list notation came as a surprise. 656 The current round of specification was part of the DRUMS 657 working group, with significant contributions from Jerome 658 Abela , Harald Alvestrand, Robert Elz, Roger Fajman, Aviva 659 Garrett, Tom Harsch, Dan Kohn, Bill McQuillan, Keith Moore, 660 Chris Newman , Pete Resnick and Henning Schulzrinne. 662 9. References 664 [US-ASCII] Coded Character Set--7-Bit American Standard 665 Code for Information Interchange, ANSI X3.4-1986. 667 [RFC733] Crocker, D.H., Vittal, J.J., Pogran, K.T., 668 Henderson, D.A. "Standard for the Format of ARPA 669 Network Text Message," RFC 733, November 1977. 671 [RFC822] Crocker, D., "Standard for the Format of ARPA 672 Internet Text Messages", RFC 822, August, 1982. 674 10. Contact 676 David H. Crocker Paul Overell 677 Brandenburg InternetWorking Demon Internet Ltd 678 675 Spruce Drive Dorking Business Park 679 Sunnyvale, CA 94086, USA Dorking 680 Surrey, RH4 1HN, UK 681 682 Phone: +1 408 246 8253