view Side-By-Side changes
Internet-DraftInternet-Draft: DRAFT-DRUMS-ABNF- Internet Mail 06.{txt,ps} Consortium Expiration <1/98> Paul OverellExpiration <7/97>Demon Internet Ltd Augmented BNF for Syntax Specifications: ABNF<draft-ietf-drums-abnf-02.txt>STATUS OF THIS MEMO This document is an Internet-Draft. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents asInternet- Drafts.Internet-Drafts. 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.'' To learn the current status of any Internet-Draft, please check the ``1id-abstracts.txt'' listing contained in the Internet- Drafts Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe), munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or ftp.isi.edu (US West Coast). TABLE OF CONTENTS 1. INTRODUCTION 2. RULE DEFINITION 2.1 Rule Naming 2.2 Rule Form 2.3 End-of-Rule 2.4 Terminal Values 2.5 External Encodings 3. OPERATORS 3.1Concatenation:Concatenation Rule1 Rule2 3.2Alternatives:Alternatives Rule1 / Rule2 3.3 IncrementalAlternatives:Alternatives Rule1 =/ Rule2 3.4 Value Range Alternatives %c##-## 3.5 SequenceGroup:Group (Rule1 Rule2)3.5 Set Group: {Rule 1 Rule2}3.6 VariableRepetition:Repetition *Rule 3.7 SpecificRepetition:Repetition nRule 3.8 OptionalSequence:Sequence [RULE] 3.9Lists: #Rule 3.10 Value Ranges: a..b 3.11; Comment3.123.10 Operator Precedence 4. ABNF DEFINITION OFABNF...ABNF 5. APPENDIX A - CORE 6. ACKNOWLEDGEMENTS 7. REFERENCES 8. CONTACT 1. INTRODUCTION Internet technical specifications often need to define a format syntax and are free to employ whatever notation their authors deem useful. Over the years, a modified version of Backus-Naur Form (BNF), called Augmented BNF (ABNF), has been popular among many Internet specifications. It balances compactness and simplicity, with reasonable representational power. In the early days of the Arpanet, each specification contained its own definition of ABNF. This included the email specifications, RFC733 and then RFC822 which have come to be the common citations for defining ABNF. The current document separates out that definition, to permit selective reference. Predictably, it also provides some enhancements. The differences between standard BNF andtheABNFdefined hereinvolve naming rules, repetition, alternatives,andorder-independence,and rules that add alternatives to existing rules,lists, and value ranges. Appendix A (Core) supplies rule definitions for a core lexicalanalyzer,analyzer of the type common to several Internet specifications. It is provided as a convenience and is otherwise separate from the meta language defined in the body of this document, and separate from its formal status. 2. RULE DEFINITION 2.1 Rule Naming The name of a rule is simply the name itself; that is, a sequence of characters,notbeginning witha digit, withanasterisk ("*"), or withalphabetic character, and followed by anumber (pound) sign ("#"). (This avoids ambiguity with the various repetition mechanisms, defined below.) Rule names are case-INsensitive.combination of alphabetics, digits and hyphens (dashes). RULE NAMES ARE CASE-INSENSITIVE. The names <rulename>, <Rulename>, <RULENAME> and <rUlENamE> all refer to the same rule. Unlike original BNF, angle brackets ("<", ">") are not required. However, angle brackets may be used around a rule reference whenever their presence will facilitate discerning the use of a rule name. This is typically restricted to rule name references in free-form prose, or to distinguish partial rules that combine into a string not separated bylinearwhite space, such as shown in the discussion about repetition, below. 2.2 Rule Form A rule is defined by the following sequence: name = elements where <name> is the name of the rule and <elements> is one or morerulesrule names or terminal specifications. The equal sign separates the name from the definition of the rule. The elementsareform a sequence of one or more rule names and/or value definitions, combined according to the various operators, defined in this document, such as alternative and repetition. 2.3 End-of-Rule Formally the grammar requires a one-token look-ahead to find the "=" token, which indicates that the previous token is the name of a new rule. For visual ease,rules should start in column 1, withrulecontinuation indicated by blank (linear white space) in column 1. In some documentation, "column 1" might be virtual, withdefinitions are left aligned. When aconsistent indentation fromrule requires multiple lines, theleft margin, for all rules.continuation lines are indented. 2.4 Terminal Values Rules resolve into a string of terminal values, sometimes called characters. Values within ABNF are represented as decimal numbers. Hence, an ABNF parser processes a sequence of characters. Each character is represented as a decimal number. A string of values is in "network byte order" with thehigher-valuedhigher- valued bytes represented on the left-hand side and begin sent over the network first.. Terminals are specified by one or morenumericanumeric characters with the base interpretation of those characters indicated explicitly. The following bases are currently defined: b = binary d = decimal x = hexadecimal Hence: CR = %d13 CR = %x0D respectively specify the decimal and hexadecimal representation of [US-ASCII] for carriage return. A concatenated string of such values is specified compactly, using a period (".") to indicate separation of characters within that value. Hence: CRLF = %d13.10For a sequence of values which can be represented as simple, graphical characters (letters), they may be specified as aABNF permits specifying literal text stringof literals,directly, enclosed in quotation-marks. Hence:rulecommand ="rule-name = rule-value" specifies the rule "rule" which contains the characters"command string" Literal text strings are interpreted as a concatenated set ofan ABNF rule specification.printable characters. ABNF STRINGS ARE CASE-INSENSITIVE AND THE CHARACTER SET FOR THESE STRINGS ISUS- ASCII.US-ASCII. Hence: rulename = "abc" will match "abc", "Abc", "aBc", "abC", "ABc", "aBC", "AbC" and "ABC".To specify a rule whichTO SPECIFY A RULE WHICH IScaseCASE SENSITIVE,specify the characters individually.SPECIFY THE CHARACTERS INDIVIDUALLY. For example: rulename = %d97 %d9 %d99 or rulename = %d97.98.99 will match only the string which comprises only lowercased characters, abc. 2.5 External Encodings External representations of these characters will vary according to constraints in the storage or transmission environment. Hence, the same ABNF-based grammar may have multiple external encodings, such as one for a 7-bit US-ASCII environment, another for a binary octet environment and still a different one when16-bit16- bit Unicode is used. Encoding details are beyond the scope of ABNF, although Appendix A (Core) provides definitions for a 7-bit US-ASCII environment as has been common to much of the Internet. By separating external encoding from the syntax, it is intended that alternate encoding environments can be used for the same syntax. 3. OPERATORS 3.1Concatenation:Concatenation Rule1 Rule2 A rule can define a simple, ordered string of values -- i.e., a concatenation of contiguous characters -- by listing a sequence of rule names. For example: foo = %x61 ; a bar = %x62 ; b mumble = foo bar foo So that the rule <mumble>definesmatches the lower-case string "aba". LINEAR WHITE SPACE: Concatenation is at the core of the ABNF parsing model. A string of contiguous characters (values) is parsed according to the rules defined in ABNF. For Internet specifications, there is some history of permitting linear white space (space and horizontal tab) to befreely-and implicitly-intersperedfreelyÐand implicitlyÐinterspered around major constructs, such as delimiting special characters or atomic strings. THIS SPECIFICATION FOR ABNF DOES NOT PROVIDE FOR IMPLICIT SPECIFICATION OF LINEAR WHITE SPACE. Any grammar which wishes to permit linear white space around delimiters or string segments must specify it explicitly. It is often useful to provide for such white space in "core" rules that are then used variously among higher-level rules. The "core" rules might be formed into a lexical analyzer or simply be part of the main ruleset. 3.2Alternatives:Alternatives Rule1 / Rule2 Elements separated by forward slash ("/") are alternatives. Therefore, foo / bar will accept <foo> or <bar>. REMINDER: A string containing alphabetic characters is a non-terminal representing the set of combinatorial strings with upper and lower case characters. 3.3 IncrementalAlternatives:Alternatives Rule1 =/ Rule2 It is sometimes convenient to specify a list of alternatives in fragments. That is, an initial rule maydefinematch one or more alternatives, with later rule definitions adding to the set of alternatives. This is particularly useful forotherwise-independentotherwise- independent specifications which derive from the same parent rule set, such as often occurs with parameter lists. ABNF permits this incremental definition through the construct: oldrule =/ additional-alternatives So that the rule set ruleset = alt1 / alt2 ruleset =/ alt3 ruleset =/ alt4 / alt5 is the same as specifying ruleset = alt1 / alt2 / alt3 / alt4 / alt5 3.4 Value Range Alternatives %c##-## A range of alternative numeric values can be specified compactly, using dash ("-") to indicate the range of alternative values. Hence: DIGIT = %x30-3A is equivalent to: DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" 3.5 SequenceGroup:Group (Rule1 Rule2) Elements enclosed in parentheses are treated as a single element, whose contents are STRICTLY ORDERED. Thus,(elem foo) / (bar blat)elemallows the token sequences(foo / bar) blat which matches (elem fooelem) and (bar blat elem). Without the grouping, the rule:blat) or (elem bar blat). elem foo / barelem would matchblat matches (elemfoo elem)foo) or (bar blat). IT IS STRONGLY ADVISED TO USE GROUPING NOTATION, RATHER THAN TO RELY ON PROPER READING OF "BARE" ALTERNATIONS, WHEN ALTERNATIVES CONSIST OF MULTIPLE RULE NAMES OR LITERALS.. Hence it is strongly recommended that instead of the above form, the form: (elembar elem).foo) / (bar blat) be used. It will avoid misinterpretation by casual readers. The local grouping notation is also used within free text to set off an element sequence from the prose.3.5 Set Group: {Rule 1 Rule2} Elements enclosed in braces (squiggly brackets) are treated as a single, UNORDERED element. Its contents may occur in any order. Hence: {elem foo} bar would match (elem foo bar) and (foo elem bar). NOTE: Specifying alternatives is quite different from specifying set grouping. Alternatives indicate the matching of exactly one (sub-)rule out of the total grouping. The set mechanism indicates the matching of a string which contains all of the elements within the group; however the elements may occur in any order.3.6 VariableRepetition:Repetition *Rule The operator "*" preceding an element indicates repetition. The full form is: <a>*<b>element where <a> and <b> are optional decimal values, indicating at least <a> and at most <b> occurrences of element. Default values are 0 and infinity so that <*element> allows any number, including zero; <1*element> requires at least one; <3*3element> allows exactly 3 and <1*2element> allows one or two. 3.7 SpecificRepetition:Repetition nRule A rule of the form: <n>element is equivalent to <n>*<n>element That is, exactly <N> occurrences of <element>. Thus 2DIGIT is a 2-digit number, and 3ALPHA is a string of three alphabetic characters. 3.8 OptionalSequence:Sequence [RULE] Square brackets enclose an optional element sequence: [foo bar] is equivalent to *1(foo bar). 3.9Lists: #Rule A construct "#" is defined as being similar to "*", for a list sequence: <a>#<b>element indicates at least <a> and at most <b> elements, each separated by one or more commas (","). This makes the usual form of lists very easy; a rule such as: element *("," element) can therefore be shown as 1#element Wherever this construct is used, null elements are allowed, but do not contribute to the count of elements present. That is, element,,element is permitted, but counts as only two elements. Therefore, where at least one element is required, at least one non- null element must be present. Default values are 0 and infinity so that <#element> allows any number, including zero; <1#element> requires at least one; and <1#2element> allows one or two. 3.10 Value Ranges: a..b Values separated by double periods ("..") specify a range of values from the lowest, on the left-hand side, to the highest on the right-hand side. Values may be specifiednumericallyl or with rule references. The form: %d12..%d15 or %d12..15 represents a value in the range 12 to 15, inclusively. When the values are specified using rules rather than explicit decimal numbers, the rules must reduce to single, decimal values. Hence: CR = %d12 LF = %d15 smallrange = LF..CR is valid and indicates the decimal value range 12 to 15. 3.11; Comment A semi-colon starts a comment that continues to the end of line. This is a simple way of including useful notes in parallel with the specifications.3.123.10 Operator Precedence The various mechanisms described above have the following precedence, from highest (binding tightest) at thetop,top-left, to lowest and loosest at thebottom:bottom-right: Strings, Names formation Comment Value range Repetition, List Grouping, Optional Concatenation Alternative Use of the alternative operator, freely mixed with concatenations can be confusing.It isIT IS STRONGLYrecommended that the grouping operator be used to make explicit concatenation groups.RECOMMENDED THAT THE GROUPING OPERATOR BE USED TO MAKE EXPLICIT CONCATENATION GROUPS. 4. ABNF DEFINITION OFABNF...ABNF This syntax uses the rules provided in Appendix A (Core). rulelist = 1*( rule / (*c-wsp c-nl) ) rule = rulename*WSP ("=" / "=/") value [comment] *WSP CRLFdefined-as elements c-nl ; continues if next line starts ; with white space rulename = ALPHA *(ALPHA / DIGIT / "-") defined-as = *c-wsp ("=" / "=/") *c-wsp ; basic rules definition and ; incremental alternativesbin-valelements = alternation *c-wsp c-wsp = WSP / (c-nl WSP) c-nl ="b" 1*("0".."1") [ 1*("." 1*("0".."1")) / (".." 1*("0".."1")) ]comment / CRLF ; comment or newline comment =*WSP";" *(WSP /%x21..%x7E) dec-valPCHAR) CRLF alternation = concatenation *(*c-wsp "/" *c-wsp concatenation) concatenation = repetition *(1*c-wsp repetition) repetition = [repeat] element repeat ="d"1*DIGIT[ 1*("." 1*DIGIT)/(".." 1*DIGIT) ] el-component(*DIGIT "*" *DIGIT) element = rulename /set /group / option /num-valchar-val /lit-valnum-val / prose-valelement = [repeat] el-componentgroup =*WSP"("value *WSP*c-wsp alternation *c-wsp ")"hex-valoption ="x" 1*(DIGIT / "A".."F") [ 1*("." 1*(DIGIT / "A".."F")) / (".." 1*(DIGIT / "A".."F")) ] lit-val = *WSP <"> *PCHAR <">"[" *c-wsp alternation *c-wsp "]" char-val = DQUOTE *PCHAR-NDQ DQUOTE num-val =*WSP"%" (bin-val / dec-val / hex-val)option = *WSP "[" value *WSP "] prose-val = *WSP "<" <description of value> ">" set = *WSP "{" 2*element *WSP "}" ; elements in any order rangebin-val =value *WSP ".." value"b" 1*BIT *( ("." 1*BIT) / (":" 1*BIT) ) ; series of concatenated bit valuesmust reduce to single decimal values repeat = repeat-num / [repeat-num] *WSP ("*" / "#") [repeat-num] repeat-num; and/or series of ONEOF ranges dec-val =*WSP"d" 1*DIGITrulename = *WSP ALPHA*(ALPHA("." 1*DIGIT) /DIGIT(":" 1*DIGIT) ) hex-val = "x" 1*HEXDIG *( ("." 1*HEXDIG) /"-"(":" 1*HEXDIG) )valueprose-val =1*element *(*WSP "/" 1*element)"<" *PCHAR-NRB ">" 5. APPENDIX A - CORE This Appendix is provided as a convenient core for specific grammars. The definitions may be used as a core set of rules. Certain basic rules are in uppercase, such asSPACE, TAB,SP, HT, CRLF, DIGIT, ALPHA, etc. ALPHA ="A".."Z"%x41-5A / %x61-7A ;case not significantA-Z / a-z BIT = "0" / "1" CHAR =%x00..7F%x00-7F ;us-asciiany US-ASCII character CR =%d13%x0D ; carriage return CRLF = CR LF ; Internet standard newline CTL =%d0..31%x00-1F /%d127%x7F ; controls DIGIT ="0".."9" HTAB%x30-39 ; 0-9 DQUOTE =%d9%x22 ; " (Double Quote) HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F" HT = %x09 ; horizontal tab LF =%d10%x0A ; linefeed LWSP =SP*(WSP / CRLF WSP) ; linear white space (past newline) PCHAR = %x20-7E ; printable characters PCHAR-NRB = %x20-3D /HTAB SPACE%x3F-7E ; PCHAR less > (No Right Bracket) PCHAR-NDQ =" "%x20-21 / %x23-7E ; PCHAR less " (No Double Quote) SP =%x20..7E%x20 ; space WSP =LWSPSP /CRLF LWSPHT ; white space Externally, data are represented as "network virtual ASCII", namely 7-bit US-ASCII in an 8th bit field, with the high (8th) bit set to zero. 6. ACKNOWLEDGEMENTS The syntax for ABNF was originally specified in RFC #733. Ken L. Harrenstien, of SRI International, was responsible for re-coding the BNF into an augmented BNF that makes the representation smaller and easier to understand. The current round of specification was part of the DRUMS working group, with significant contributions from Roger Fajman, Bill McQuillan, Keith Moore, Pete Resnick, Jerome Abela and Chris Newman. 7. REFERENCES [US-ASCII] Coded Character Set--7-Bit American Standard Code for Information Interchange, ANSI X3.4-1986. 8. CONTACT David H. Crocker Paul OverellDemon Internet LtdInternet Mail ConsortiumDorking Business ParkDemon Internet Ltd 675 Spruce Dr. Dorking Business Park Sunnyvale, CA 94086 USA Dorking Surrey, RH4 1HNUK<dcrocker@imc.org><paulo@turnpike.com>UK Phone: +1 408 246 8253 <paulo@turnpike.com> Fax: +1 408 249 6205 ----