home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / drafts / draft__misc / Abnf14.txt < prev    next >
Text File  |  1997-10-17  |  20KB  |  624 lines

  1. Network Working Group                         D. Crocker (editor)
  2. Internet-Draft:  DRAFT-DRUMS-ABNF-                  Internet Mail
  3.      08.txt                                            Consortium
  4. Expiration <4/98>                                    Paul Overell
  5.                                                Demon Internet Ltd
  6.                                                                  
  7.                                 
  8.                                 
  9.                                 
  10.                                 
  11.           Augmented BNF for Syntax Specifications: ABNF
  12.                                 
  13.                                 
  14.                                 
  15.  
  16. STATUS OF THIS MEMO
  17.  
  18. This document is an Internet-Draft.  Internet-Drafts are working
  19. documents of the Internet Engineering Task Force (IETF), its
  20. areas, and its working groups.  Note that other groups may also
  21. distribute working documents as Internet-Drafts.
  22.  
  23. Internet-Drafts are draft documents valid for a maximum of six
  24. months and may be updated, replaced, or obsoleted by other
  25. documents at any time.  It is inappropriate to use Internet-
  26. Drafts as reference material or to cite them other than as ``work
  27. in progress.''
  28.  
  29. To learn the current status of any Internet-Draft, please check
  30. the ``1id-abstracts.txt'' listing contained in the Internet-
  31. Drafts Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net
  32. (Europe), munnari.oz.au (Pacific Rim), ds.internic.net (US East
  33. Coast), or ftp.isi.edu (US West Coast).
  34.  
  35.  
  36. TABLE OF CONTENTS
  37.  
  38.  
  39.  
  40. 1. INTRODUCTION
  41.  
  42. 2. RULE DEFINITION
  43. 2.1 RULE NAMING
  44. 2.2 RULE FORM
  45. 2.3 TERMINAL VALUES
  46. 2.4 EXTERNAL ENCODINGS
  47.  
  48. 3. OPERATORS
  49. 3.1 CONCATENATION   RULE1
  50.     RULE2
  51. 3.2 ALTERNATIVES RULE1 / RULE2
  52. 3.3 INCREMENTAL ALTERNATIVES
  53.     RULE1 =/ RULE2
  54. 3.4 VALUE RANGE ALTERNATIVES
  55.     %C##-##
  56. 3.5 SEQUENCE GROUP (RULE1
  57.     RULE2)
  58. 3.6 VARIABLE REPETITION *RULE
  59. 3.7 SPECIFIC REPETITION NRULE
  60. 3.8 OPTIONAL SEQUENCE [RULE]
  61. 3.9 ; COMMENT
  62. 3.10 OPERATOR PRECEDENCE
  63.  
  64. 4. ABNF DEFINITION OF ABNF
  65.  
  66. 5. SECURITY CONSIDERATIONS
  67.  
  68. 6. APPENDIX A - CORE
  69. 6.1 CORE RULES
  70. 6.2 COMMON ENCODING
  71.  
  72. 7. ACKNOWLEDGMENTS
  73.  
  74. 8. REFERENCES
  75.  
  76. 9. CONTACT
  77.  
  78.  
  79.  
  80. 1.   INTRODUCTION
  81.  
  82. Internet technical specifications often need to define a format
  83. syntax and are free to employ whatever notation their authors
  84. deem useful.  Over the years, a modified version of Backus-Naur
  85. Form (BNF), called Augmented BNF (ABNF), has been popular among
  86. many Internet specifications.  It balances compactness and
  87. simplicity, with reasonable representational power.  In the early
  88. days of the Arpanet, each specification contained its own
  89. definition of ABNF.  This included the email specifications,
  90. RFC733 and then RFC822 which have come to be the common citations
  91. for defining ABNF.  The current document separates out that
  92. definition, to permit selective reference.  Predictably, it also
  93. provides some modifications and enhancements.
  94.  
  95. The differences between standard BNF and ABNF involve naming
  96. rules, repetition, alternatives, order-independence, and value
  97. ranges.  Appendix A (Core) supplies rule definitions and encoding
  98. for a core lexical analyzer of the type common to several
  99. Internet specifications.  It is provided as a convenience and is
  100. otherwise separate from the meta language defined in the body of
  101. this document, and separate from its formal status.
  102.  
  103.  
  104.  
  105. 2.   RULE DEFINITION
  106.  
  107. 2.1  Rule Naming
  108.  
  109. The name of a rule is simply the name itself; that is, a sequence
  110. of characters, beginning with  an alphabetic character, and
  111. followed by a combination of alphabetics, digits and hyphens
  112. (dashes).
  113.      
  114.      NOTE:     Rule names are case-insensitive
  115.  
  116. The names <rulename>, <Rulename>, <RULENAME> and <rUlENamE> all
  117. refer to the same rule.
  118.  
  119. Unlike original BNF, angle brackets ("<", ">") are not  required.
  120. However, angle brackets may be used around a rule name whenever
  121. their presence will facilitate discerning the use of  a rule
  122. name.  This is typically restricted to rule name references in
  123. free-form prose, or to distinguish partial rules that combine
  124. into a string not separated by white space, such as shown in the
  125. discussion about repetition, below.
  126.  
  127. 2.2  Rule Form
  128.  
  129. A rule is defined by the following sequence:
  130.      
  131.      name =  elements crlf
  132.  
  133. where <name> is the name of the rule, <elements> is one or more
  134. rule names or terminal specifications and <crlf> is the end-of-
  135. line indicator, carriage return followed by line feed.  The equal
  136. sign separates the name from the definition of the rule.  The
  137. elements form a sequence of one or more rule names and/or value
  138. definitions, combined according to the various operators, defined
  139. in this document, such as alternative and repetition.
  140.  
  141. For visual ease, rule definitions are left aligned.  When a rule
  142. requires multiple lines, the continuation lines are indented.
  143. The left alignment and indentation are relative to the first
  144. lines of the ABNF rules and need not match the left margin of the
  145. document.
  146.  
  147. 2.3  Terminal Values
  148.  
  149. Rules resolve into a string of terminal values, sometimes called
  150. characters.  In ABNF a character is merely a non-negative
  151. integer.  In certain contexts a specific mapping (encoding) of
  152. values into a character set (such as ASCII) will be specified.
  153.  
  154. Terminals are specified by one or more numeric characters with
  155. the base interpretation of those characters indicated explicitly.
  156. The following bases are currently defined:
  157.      
  158.      b           =  binary
  159.      
  160.      d           =  decimal
  161.      
  162.      x           =  hexadecimal
  163.  
  164. Hence:
  165.      
  166.      CR          =  %d13
  167.      
  168.      CR          =  %x0D
  169.  
  170. respectively specify the decimal and hexadecimal representation
  171. of [US-ASCII] for carriage return.
  172.  
  173. A concatenated string of such values is specified compactly,
  174. using a period (".") to indicate separation of characters within
  175. that value.  Hence:
  176.      
  177.      CRLF        =  %d13.10
  178.  
  179. ABNF permits specifying literal text string directly, enclosed in
  180. quotation-marks.  Hence:
  181.      
  182.      command     =  "command string"
  183.  
  184. Literal text strings are interpreted as a concatenated set of
  185. printable characters.
  186.      
  187.      NOTE:     ABNF strings are case-insensitive and
  188.                the character set for these strings is
  189.                us-ascii.
  190.  
  191. Hence:
  192.      
  193.      rulename = "abc"
  194.  
  195. and:
  196.      
  197.      rulename = "aBc"
  198.  
  199. will match "abc", "Abc", "aBc", "abC", "ABc", "aBC", "AbC" and
  200. "ABC".
  201.                                 
  202.            To specify a rule which IS case SENSITIVE,
  203.               specify the characters individually.
  204.  
  205. For example:
  206.      
  207.      rulename    =  %d97 %d98 %d99
  208.  
  209. or
  210.      
  211.      rulename    =  %d97.98.99
  212.  
  213. will match only the string which comprises only lowercased
  214. characters, abc.
  215.  
  216. 2.4  External Encodings
  217.  
  218. External representations of terminal value characters will vary
  219. according to constraints in the storage or transmission
  220. environment.  Hence, the same ABNF-based grammar may have
  221. multiple external encodings, such as one for a 7-bit US-ASCII
  222. environment, another for a binary octet environment and still a
  223. different one when 16-bit Unicode is used.  Encoding details are
  224. beyond the scope of ABNF, although Appendix A (Core) provides
  225. definitions for a 7-bit US-ASCII environment as has been common
  226. to much of the Internet.
  227.  
  228. By separating external encoding from the syntax, it is intended
  229. that alternate encoding environments can be used for the same
  230. syntax.
  231.  
  232.  
  233.  
  234. 3.   OPERATORS
  235.  
  236. 3.1  Concatenation                                  Rule1 Rule2
  237.  
  238. A rule can define a simple, ordered string of values -- i.e., a
  239. concatenation of contiguous characters -- by listing a sequence
  240. of rule names.  For example:
  241.      
  242.      foo         =  %x61           ; a
  243.      
  244.      bar         =  %x62           ; b
  245.      
  246.      mumble      =  foo bar foo
  247.  
  248. So that the rule <mumble> matches the lowercase string "aba".
  249.  
  250. LINEAR WHITE SPACE:  Concatenation is at the core of the ABNF
  251. parsing model.  A string of contiguous characters (values) is
  252. parsed according to the rules defined in ABNF.  For Internet
  253. specifications, there is some history of permitting linear white
  254. space (space and horizontal tab) to be freely╨and
  255. implicitly╨interspersed around major constructs, such as
  256. delimiting special characters or atomic strings.
  257.      
  258.      NOTE:     This specification for ABNF does not
  259.                provide for implicit specification of
  260.                linear white space.
  261.  
  262. Any grammar which wishes to permit linear white space around
  263. delimiters or string segments must specify it explicitly.  It is
  264. often useful to provide for such white space in "core" rules that
  265. are then used variously among higher-level rules.  The "core"
  266. rules might be formed into a lexical analyzer or simply be part
  267. of the main ruleset.
  268.  
  269. 3.2  Alternatives                               Rule1 / Rule2
  270.  
  271. Elements separated by forward slash ("/") are alternatives.
  272. Therefore,
  273.      
  274.      foo / bar
  275.  
  276. will accept <foo> or <bar>.
  277.      
  278.      NOTE:     A quoted string containing alphabetic
  279.                characters is special form for
  280.                specifying alternative characters and is
  281.                interpreted as a non-terminal
  282.                representing the set of combinatorial
  283.                strings with the contained characters,
  284.                in the specified order but with any
  285.                mixture of upper and lower case..
  286.  
  287. 3.3  Incremental Alternatives                    Rule1 =/ Rule2
  288.  
  289. It is sometimes convenient to specify a list of alternatives in
  290. fragments.  That is, an initial rule may match one or more
  291. alternatives, with later rule definitions adding to the set of
  292. alternatives.  This is particularly useful for otherwise-
  293. independent specifications which derive from the same parent rule
  294. set, such as often occurs with parameter lists.  ABNF permits
  295. this incremental definition through the construct:
  296.      
  297.      oldrule     =/ additional-alternatives
  298.  
  299. So that the rule set
  300.      
  301.      ruleset     =  alt1 / alt2
  302.      
  303.      ruleset     =/ alt3
  304.      
  305.      ruleset     =/ alt4 / alt5
  306.  
  307. is the same as specifying
  308.      
  309.      ruleset     =  alt1 / alt2 / alt3 / alt4 / alt5
  310.  
  311. 3.4  Value Range Alternatives                           %c##-##
  312.  
  313. A range of alternative numeric values can be specified compactly,
  314. using dash ("-") to indicate the range of alternative values.
  315. Hence:
  316.      
  317.      DIGIT       =  %x30-39
  318.  
  319. is equivalent to:
  320.      
  321.      DIGIT       =  "0" / "1" / "2" / "3" / "4" / "5" / "6" /
  322.      
  323.                          "7" / "8" / "9"
  324.  
  325. Concatenated numeric values and numeric value ranges can not be
  326. specified in the same string.  A numeric value may use the dotted
  327. notation for concatenation or it may use the dash notation to
  328. specify one value range.  Hence, to specify one printable
  329. character, between end of line sequences, the specification could
  330. be:
  331.      
  332.      onechar-line = %x0D.0A %x20-7E %x0D.0A
  333.  
  334. 3.5  Sequence Group                             (Rule1 Rule2)
  335.  
  336. Elements enclosed in parentheses are treated as a single element,
  337. whose contents are STRICTLY ORDERED.   Thus,
  338.      
  339.      elem (foo / bar) blat
  340.  
  341. which matches (elem foo blat) or (elem bar blat).
  342.      
  343.      elem foo / bar blat
  344.  
  345. matches (elem foo) or (bar blat).
  346.      
  347.      NOTE:     It is strongly advised to use grouping
  348.                notation, rather than to rely on proper
  349.                reading of "bare" alternations, when
  350.                alternatives consist of multiple rule
  351.                names or literals.
  352.  
  353. Hence it is recommended that instead of the above form, the form:
  354.      
  355.      (elem foo) / (bar blat)
  356.  
  357. be used.  It will avoid misinterpretation by casual readers.
  358.  
  359. The sequence group notation is also used within free text to set
  360. off an element sequence from the prose.
  361.  
  362. 3.6  Variable Repetition                                *Rule
  363.  
  364. The operator "*" preceding an element indicates repetition. The
  365. full form is:
  366.      
  367.      <a>*<b>element
  368.  
  369. where <a> and <b> are optional decimal values, indicating at
  370. least <a> and at most <b> occurrences of element.
  371.  
  372. Default values are 0 and infinity so that *<element> allows any
  373. number, including zero; 1*<element> requires at  least  one;
  374. 3*3<element> allows exactly 3 and 1*2<element> allows one or two.
  375.  
  376. 3.7  Specific Repetition                                  nRule
  377.  
  378. A rule of the form:
  379.      
  380.      <n>element
  381.  
  382. is equivalent to
  383.      
  384.      <n>*<n>element
  385.  
  386. That is, exactly  <N>  occurrences  of <element>. Thus 2DIGIT is
  387. a 2-digit number, and 3ALPHA is a string of three alphabetic
  388. characters.
  389.  
  390. 3.8  Optional Sequence                                   [RULE]
  391.  
  392. Square brackets enclose an optional element sequence:
  393.      
  394.      [foo bar]
  395.  
  396. is equivalent to
  397.      
  398.      *1(foo bar).
  399.  
  400. 3.9  ; Comment
  401.  
  402. A semi-colon starts a comment that continues to the end of line.
  403. This is a simple way of including useful notes in parallel with
  404. the specifications.
  405.  
  406. 3.10 Operator Precedence
  407.  
  408. The various mechanisms described above have the following
  409. precedence, from highest (binding tightest) at the top, to lowest
  410. and loosest at the bottom:
  411.      
  412.      Strings, Names formation
  413.      Comment
  414.      Value range
  415.      Repetition
  416.      Grouping, Optional
  417.      Concatenation
  418.      Alternative
  419.  
  420. Use of the alternative operator, freely mixed with concatenations
  421. can be confusing.
  422.      
  423.      Again, it is recommended that the grouping
  424.      operator be used to make explicit concatenation
  425.      groups.
  426.  
  427.  
  428.  
  429. 4.   ABNF DEFINITION OF ABNF
  430.  
  431. This syntax uses the rules provided in Appendix A (Core).
  432.      
  433.      rulelist       =  1*( rule / (*c-wsp c-nl) )
  434.      
  435.      rule           =  rulename defined-as elements c-nl
  436.                             ; continues if next line starts
  437.                             ;  with white space
  438.      
  439.      rulename       =  ALPHA *(ALPHA / DIGIT / "-")
  440.      
  441.      defined-as     =  *c-wsp ("=" / "=/") *c-wsp
  442.                             ; basic rules definition and
  443.                             ;  incremental alternatives
  444.      
  445.      elements       =  alternation *c-wsp
  446.      
  447.      c-wsp          =  WSP / (c-nl WSP)
  448.      
  449.      c-nl           =  comment / CRLF
  450.                             ; comment or newline
  451.      
  452.      comment        =  ";" *(WSP / VCHAR) CRLF
  453.      
  454.      alternation    =  concatenation
  455.                        *(*c-wsp "/" *c-wsp concatenation)
  456.      
  457.      concatenation  =  repetition *(1*c-wsp repetition)
  458.      
  459.      repetition     =  [repeat] element
  460.      
  461.      repeat         =  1*DIGIT / (*DIGIT "*" *DIGIT)
  462.      
  463.      element        =  rulename / group / option /
  464.                        char-val / num-val / prose-val
  465.      
  466.      group          =  "(" *c-wsp alternation *c-wsp ")"
  467.      
  468.      option         =  "[" *c-wsp alternation *c-wsp "]"
  469.      
  470.      char-val       =  DQUOTE *(%x20-21 / %x23-7E) DQUOTE
  471.                             ; quoted string of SP and VCHAR
  472.                                without DQUOTE
  473.      
  474.      num-val        =  "%" (bin-val / dec-val / hex-val)
  475.      
  476.      bin-val        =  "b" 1*BIT
  477.                        [ 1*("." 1*BIT) / ("-" 1*BIT) ]
  478.                             ; series of concatenated bit values
  479.                             ; or single ONEOF range
  480.      
  481.      dec-val        =  "d" 1*DIGIT
  482.                        [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ]
  483.      
  484.      hex-val        =  "x" 1*HEXDIG
  485.                        [ 1*("." 1*HEXDIG) / ("-" 1*HEXDIG) ]
  486.      
  487.      prose-val      =  "<" *(%x20-3D / %x3F-7E) ">"
  488.                             ; bracketed string of SP and VCHAR
  489.                                without angles
  490.                             ; prose description, to be used as
  491.                                last resort
  492.  
  493.  
  494.  
  495. 5.   SECURITY CONSIDERATIONS
  496.  
  497. Security is truly believed to be irrelevant to this document.
  498.  
  499.  
  500.  
  501. 6.   APPENDIX A - CORE
  502.  
  503. This Appendix is provided as a convenient core for specific
  504. grammars.  The definitions may be used as a core set of rules.
  505.  
  506. 6.1  Core Rules
  507.  
  508. Certain  basic  rules  are  in uppercase, such as SP, HTAB, CRLF,
  509. DIGIT, ALPHA, etc.
  510.      
  511.      ALPHA          =  %x41-5A / %x61-7A   ; A-Z / a-z
  512.      
  513.      BIT            =  "0" / "1"
  514.      
  515.      CHAR           =  %x01-7F
  516.                             ; any 7-bit US-ASCII character,
  517.                                excluding NUL
  518.      
  519.      CR             =  %x0D
  520.                             ; carriage return
  521.      
  522.      CRLF           =  CR LF
  523.                             ; Internet standard newline
  524.      
  525.      CTL            =  %x00-1F / %x7F
  526.                             ; controls
  527.      
  528.      DIGIT          =  %x30-39
  529.                             ; 0-9
  530.      
  531.      DQUOTE         =  %x22
  532.                             ; " (Double Quote)
  533.      
  534.      HEXDIG         =  DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
  535.      
  536.      HTAB           =  %x09
  537.                             ; horizontal tab
  538.      
  539.      LF             =  %x0A
  540.                             ; linefeed
  541.      
  542.      LWSP           =  *(WSP / CRLF WSP)
  543.                             ; linear white space (past newline)
  544.      
  545.      OCTET          =  %x00-FF
  546.                             ; 8 bits of data
  547.      
  548.      SP             =  %x20
  549.                             ; space
  550.      
  551.      VCHAR          =  %x21-7E
  552.                             ; visible (printing) characters
  553.      
  554.      WSP            =  SP / HTAB
  555.                             ; white space
  556.  
  557. 6.2  Common Encoding
  558.  
  559. Externally, data are represented as "network virtual ASCII",
  560. namely 7-bit US-ASCII in an 8-bit field, with the high (8th) bit
  561. set to zero.  A string of values is in "network byte order" with
  562. the higher-valued bytes represented on the left-hand side and
  563. being sent over the network first.
  564.  
  565.  
  566.  
  567. 7.   ACKNOWLEDGMENTS
  568.  
  569. The syntax for ABNF was originally specified in RFC #733.  Ken L.
  570. Harrenstien, of SRI International, was responsible for re-coding
  571. the BNF into an augmented BNF that makes the representation
  572. smaller and easier to understand.
  573.  
  574. This recent project began as a simple effort to cull out the
  575. portion of RFC 822 which has been repeatedly cited by non-email
  576. specification writers, namely the description of augmented BNF.
  577. Rather than simply and blindly converting the existing text into
  578. a separate document, the working group chose to give careful
  579. consideration to the deficiencies, as well as benefits, of the
  580. existing specification and related specifications available over
  581. the last 15 years and therefore to pursue enhancement.  This
  582. turned the project into something rather more ambitious than
  583. first intended.  Interestingly the result is not massively
  584. different from that original, although decisions such as removing
  585. the list notation came as a surprise.
  586.  
  587. The current round of specification was part of the DRUMS working
  588. group, with significant contributions from Jerome Abela , Harald
  589. Alvestrand, Robert Elz, Roger Fajman, Aviva Garrett, Tom Harsch,
  590. Dan Kohn, Bill McQuillan, Keith Moore, Chris Newman , Pete
  591. Resnick and Henning Schulzrinne.
  592.  
  593.  
  594.  
  595. 8.   REFERENCES
  596.  
  597. [US-ASCII]     Coded Character Set--7-Bit American Standard Code
  598. for Information Interchange, ANSI X3.4-1986.
  599.  
  600. [RFC733]  Crocker,  D.H., Vittal,  J.J., Pogran,  K.T.,
  601. Henderson,  D.A. "Standard  for  the  Format  of  ARPA  Network
  602. Text Message," RFC  733, November 1977.
  603.  
  604. [RFC822]  Crocker, D., "Standard for the Format of ARPA Internet
  605. Text Messages", RFC 822, August, 1982.
  606.  
  607.  
  608.  
  609. 9.   CONTACT
  610.  
  611.  
  612. David H. Crocker                 Paul Overell
  613.                                  
  614. Internet Mail Consortium         Demon Internet Ltd
  615. 675 Spruce Dr.                   Dorking Business Park
  616. Sunnyvale, CA 94086 USA          Dorking
  617.                                  Surrey, RH4 1HN
  618. <dcrocker@imc.org>               UK
  619.                                  
  620. Phone:         +1 408 246 8253   <paulo@turnpike.com>
  621. Fax:      +1 408 249 6205        
  622.  
  623.  
  624.