⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfc5234.txt

📁 广泛使用的邮件服务器!同时
💻 TXT
📖 第 1 页 / 共 2 页
字号:
Network Working Group                                    D. Crocker, Ed.Request for Comments: 5234                   Brandenburg InternetWorkingSTD: 68                                                       P. OverellObsoletes: 4234                                                THUS plc.Category: Standards Track                                   January 2008             Augmented BNF for Syntax Specifications: ABNFStatus of This Memo   This document specifies an Internet standards track protocol for the   Internet community, and requests discussion and suggestions for   improvements.  Please refer to the current edition of the "Internet   Official Protocol Standards" (STD 1) for the standardization state   and status of this protocol.  Distribution of this memo is unlimited.Abstract   Internet technical specifications often need to define a formal   syntax.  Over the years, a modified version of Backus-Naur Form   (BNF), called Augmented BNF (ABNF), has been popular among many   Internet specifications.  The current specification documents ABNF.   It balances compactness and simplicity with reasonable   representational power.  The differences between standard BNF and   ABNF involve naming rules, repetition, alternatives, order-   independence, and value ranges.  This specification also supplies   additional rule definitions and encoding for a core lexical analyzer   of the type common to several Internet specifications.Crocker & Overell           Standards Track                     [Page 1]RFC 5234                          ABNF                      January 2008Table of Contents   1.  Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  3   2.  Rule Definition  . . . . . . . . . . . . . . . . . . . . . . .  3     2.1.  Rule Naming  . . . . . . . . . . . . . . . . . . . . . . .  3     2.2.  Rule Form  . . . . . . . . . . . . . . . . . . . . . . . .  4     2.3.  Terminal Values  . . . . . . . . . . . . . . . . . . . . .  4     2.4.  External Encodings . . . . . . . . . . . . . . . . . . . .  6   3.  Operators  . . . . . . . . . . . . . . . . . . . . . . . . . .  6     3.1.  Concatenation:  Rule1 Rule2  . . . . . . . . . . . . . . .  6     3.2.  Alternatives:  Rule1 / Rule2 . . . . . . . . . . . . . . .  7     3.3.  Incremental Alternatives: Rule1 =/ Rule2 . . . . . . . . .  7     3.4.  Value Range Alternatives:  %c##-## . . . . . . . . . . . .  8     3.5.  Sequence Group:  (Rule1 Rule2) . . . . . . . . . . . . . .  8     3.6.  Variable Repetition:  *Rule  . . . . . . . . . . . . . . .  9     3.7.  Specific Repetition:  nRule  . . . . . . . . . . . . . . .  9     3.8.  Optional Sequence:  [RULE] . . . . . . . . . . . . . . . .  9     3.9.  Comment:  ; Comment  . . . . . . . . . . . . . . . . . . .  9     3.10. Operator Precedence  . . . . . . . . . . . . . . . . . . . 10   4.  ABNF Definition of ABNF  . . . . . . . . . . . . . . . . . . . 10   5.  Security Considerations  . . . . . . . . . . . . . . . . . . . 12   6.  References . . . . . . . . . . . . . . . . . . . . . . . . . . 12     6.1.  Normative References . . . . . . . . . . . . . . . . . . . 12     6.2.  Informative References . . . . . . . . . . . . . . . . . . 12   Appendix A.  Acknowledgements  . . . . . . . . . . . . . . . . . . 13   Appendix B.  Core ABNF of ABNF . . . . . . . . . . . . . . . . . . 13     B.1.  Core Rules . . . . . . . . . . . . . . . . . . . . . . . . 13     B.2.  Common Encoding  . . . . . . . . . . . . . . . . . . . . . 15Crocker & Overell           Standards Track                     [Page 2]RFC 5234                          ABNF                      January 20081.  Introduction   Internet technical specifications often need to define a formal   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   came to be the common citations for defining ABNF.  The current   document separates those definitions to permit selective reference.   Predictably, it also provides some modifications and enhancements.   The differences between standard BNF and ABNF involve naming rules,   repetition, alternatives, order-independence, and value ranges.   Appendix B supplies rule definitions and encoding for a core lexical   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 Definition2.1.  Rule Naming   The name of a rule is simply the name itself, that is, a sequence of   characters, beginning with an alphabetic character, and followed by a   combination of alphabetics, digits, and hyphens (dashes).   NOTE:      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 name whenever their   presence facilitates in 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   by white space, such as shown in the discussion about repetition,   below.Crocker & Overell           Standards Track                     [Page 3]RFC 5234                          ABNF                      January 20082.2.  Rule Form   A rule is defined by the following sequence:         name =  elements crlf   where <name> is the name of the rule, <elements> is one or more rule   names or terminal specifications, and <crlf> is the end-of-line   indicator (carriage return followed by line feed).  The equal sign   separates the name from the definition of the rule.  The elements   form 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.   For visual ease, rule definitions are left aligned.  When a rule   requires multiple lines, the continuation lines are indented.  The   left alignment and indentation are relative to the first lines of the   ABNF rules and need not match the left margin of the document.2.3.  Terminal Values   Rules resolve into a string of terminal values, sometimes called   characters.  In ABNF, a character is merely a non-negative integer.   In certain contexts, a specific mapping (encoding) of values into a   character set (such as ASCII) will be specified.   Terminals are specified by one or more numeric 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.Crocker & Overell           Standards Track                     [Page 4]RFC 5234                          ABNF                      January 2008   A concatenated string of such values is specified compactly, using a   period (".") to indicate a separation of characters within that   value.  Hence:         CRLF        =  %d13.10   ABNF permits the specification of literal text strings directly,   enclosed in quotation marks.  Hence:         command     =  "command string"   Literal text strings are interpreted as a concatenated set of   printable characters.   NOTE:      ABNF strings are case insensitive and the character set for these      strings is US-ASCII.   Hence:         rulename = "abc"   and:         rulename = "aBc"   will match "abc", "Abc", "aBc", "abC", "ABc", "aBC", "AbC", and   "ABC".      To specify a rule that is case sensitive, specify the characters      individually.   For example:         rulename    =  %d97 %d98 %d99   or         rulename    =  %d97.98.99   will match only the string that comprises only the lowercase   characters, abc.Crocker & Overell           Standards Track                     [Page 5]RFC 5234                          ABNF                      January 20082.4.  External Encodings   External representations of terminal value 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 when 16-bit   Unicode is used.  Encoding details are beyond the scope of ABNF,   although Appendix B 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.  Operators3.1.  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> matches the lowercase 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 be freely and implicitly interspersed around major   constructs, such as delimiting special characters or atomic strings.   NOTE:      This specification for ABNF does not provide for implicit      specification of linear white space.   Any grammar that 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.Crocker & Overell           Standards Track                     [Page 6]RFC 5234                          ABNF                      January 20083.2.  Alternatives:  Rule1 / Rule2   Elements separated by a forward slash ("/") are alternatives.   Therefore,         foo / bar   will accept <foo> or <bar>.   NOTE:      A quoted string containing alphabetic characters is a special form      for specifying alternative characters and is interpreted as a non-      terminal representing the set of combinatorial strings with the      contained characters, in the specified order but with any mixture      of upper- and lowercase.3.3.  Incremental Alternatives: Rule1 =/ Rule2   It is sometimes convenient to specify a list of alternatives in   fragments.  That is, an initial rule may match one or more   alternatives, with later rule definitions adding to the set of   alternatives.  This is particularly useful for otherwise independent   specifications that derive from the same parent ruleset, such as   often occurs with parameter lists.  ABNF permits this incremental   definition through the construct:         oldrule     =/ additional-alternatives   So that the ruleset         ruleset     =  alt1 / alt2         ruleset     =/ alt3         ruleset     =/ alt4 / alt5   is the same as specifying         ruleset     =  alt1 / alt2 / alt3 / alt4 / alt5Crocker & Overell           Standards Track                     [Page 7]RFC 5234                          ABNF                      January 20083.4.  Value Range Alternatives:  %c##-##   A range of alternative numeric values can be specified compactly,   using a dash ("-") to indicate the range of alternative values.   Hence:         DIGIT       =  %x30-39   is equivalent to:         DIGIT       =  "0" / "1" / "2" / "3" / "4" / "5" / "6" /                        "7" / "8" / "9"   Concatenated numeric values and numeric value ranges cannot be   specified in the same string.  A numeric value may use the dotted   notation for concatenation or it may use the dash notation to specify   one value range.  Hence, to specify one printable character between   end-of-line sequences, the specification could be:         char-line = %x0D.0A %x20-7E %x0D.0A3.5.  Sequence Group:  (Rule1 Rule2)   Elements enclosed in parentheses are treated as a single element,   whose contents are strictly ordered.  Thus,         elem (foo / bar) blat   matches (elem foo blat) or (elem bar blat), and         elem foo / bar blat   matches (elem foo) or (bar blat).   NOTE:      It is strongly advised that grouping notation be used, rather than      relying on the proper reading of "bare" alternations, when      alternatives consist of multiple rule names or literals.   Hence, it is recommended that the following form be used:        (elem foo) / (bar blat)   It will avoid misinterpretation by casual readers.Crocker & Overell           Standards Track                     [Page 8]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -