Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Augmented Backus–Naur form
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Operators== ===White space=== White space is used to separate elements of a definition; for space to be recognized as a delimiter, it must be explicitly included. The explicit reference for a single [[whitespace character]] is <code>WSP</code> (linear white space), and <code>LWSP</code> is for zero or more whitespace characters with newlines permitted. The <code>LWSP</code> definition in RFC5234 is controversial<ref name="RFC5234 Errata">[http://www.rfc-editor.org/errata_search.php?rfc=5234&eid=3096 RFC Errata 3096].</ref> because at least one whitespace character is needed to form a delimiter between two fields. Definitions are left-aligned. When multiple lines are required (for readability), continuation lines are indented by whitespace. ===Comment=== <code>; comment</code> A semicolon (<code>;</code>) starts a comment that continues to the end of the line. ===Concatenation=== <code>Rule1 Rule2</code> A rule may be defined by listing a sequence of rule names. To match the string “aba”, the following rules could be used: * {{code|1=fu = %x61 ; a|2=abnf}} * {{code|1=bar = %x62 ; b|2=abnf}} * {{code|1=mumble = fu bar fu|2=abnf}} ===Alternative=== <code>Rule1 / Rule2</code> A rule may be defined by a list of alternative rules separated by a [[Solidus (punctuation)|solidus]] (<code>/</code>). To accept the rule ''fu'' or the rule ''bar'', the following rule could be constructed: * {{code|1=fubar = fu / bar|2=abnf}} ===Incremental alternatives=== <code>Rule1 =/ Rule2</code> Additional alternatives may be added to a rule through the use of <code>=/</code> between the rule name and the definition. The rule * {{code|1=ruleset = alt1 / alt2|2=abnf}} * {{code|1=ruleset =/ alt3|2=abnf}} * {{code|1=ruleset =/ alt4 / alt5|2=abnf}} is therefore equivalent to * {{code|1=ruleset = alt1 / alt2 / alt3 / alt4 / alt5|2=abnf}} ===Value range=== <code>%c##-##</code> A range of numeric values may be specified through the use of a hyphen (<code>-</code>). The rule * {{code|1=OCTAL = %x30-37|2=abnf}} is equivalent to * {{code|1=OCTAL = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7"|2=abnf}} ===Sequence group=== <code>(Rule1 Rule2)</code> Elements may be placed in parentheses to group rules in a definition. To match "a b d" or "a c d", the following rule could be constructed: * {{code|1=group = a (b / c) d|2=abnf}} To match “a b” or “c d”, the following rules could be constructed: * {{code|1=group = a b / c d|2=abnf}} * {{code|1=group = (a b) / (c d)|2=abnf}} ===Variable repetition=== <code>n*nRule</code> To indicate repetition of an element, the form <code><a>*<b>element</code> is used. The optional <code><a></code> gives the minimal number of elements to be included (with the default of 0). The optional <code><b></code> gives the maximal number of elements to be included (with the default of infinity). Use <code>*element</code> for zero or more elements, <code>*1element</code> for zero or one element, <code>1*element</code> for one or more elements, and <code>2*3element</code> for two or three elements, cf. [[regular expression]]s <code>e*</code>, <code>e?</code>, <code>e+</code> and <code>e{2,3}</code>. ===Specific repetition=== <code>nRule</code> To indicate an explicit number of elements, the form <code><a>element</code> is used and is equivalent to <code><a>*<a>element</code>. Use <code>2DIGIT</code> to get two numeric digits, and <code>3DIGIT</code> to get three numeric digits. (<code>DIGIT</code> is defined below under "[[#Core rules|Core rules]]". Also see ''zip-code'' in the example below.) ===Optional sequence=== <code>[Rule]</code> To indicate an optional element, the following constructions are equivalent: * {{code|1=[fubar snafu]|2=abnf}} * {{code|1=*1(fubar snafu)|2=abnf}} * {{code|1=0*1(fubar snafu)|2=abnf}} ===Operator precedence=== The following operators have the given precedence from tightest binding to loosest binding: #Strings, names formation #Comment #Value range #Repetition #Grouping, optional #Concatenation #Alternative Use of the alternative operator with concatenation may be confusing, and it is recommended that grouping be used to make explicit concatenation groups. ===Core rules=== [[File:ABNF core rules.png|thumb|alt=ABNF syntax diagram of core rules|ABNF [[syntax diagram]] of core rules]] The core rules are defined in the ABNF standard. {|class="wikitable" |- style="background-color: #efefef;" !Rule!!Formal definition!!Meaning |- |ALPHA || {{codett|%x41–5A / %x61–7A |abnf}} ||Upper- and lower-case ASCII letters (A–Z, a–z) |- |DIGIT || {{codett|%x30–39 |abnf}} ||Decimal digits (0–9) |- |HEXDIG || {{codett|DIGIT / "A" / "B" / "C" / "D" / "E" / "F" |abnf}} ||Hexadecimal digits (0–9, A–F, a–f) |- |DQUOTE || {{codett|%x22 |abnf}} ||Double quote |- |SP || {{codett|%x20 |abnf}} ||Space |- |HTAB || {{codett|%x09 |abnf}} ||Horizontal tab |- |WSP || {{codett|SP / HTAB |abnf}} ||Space and horizontal tab |- |LWSP || {{codett|*(WSP / CRLF WSP) |abnf}} ||Linear white space (past newline) |- |VCHAR || {{codett|%x21–7E |abnf}} ||Visible (printing) characters |- |CHAR || {{codett|%x01–7F |abnf}} ||Any ASCII character, excluding NUL |- |OCTET || {{codett|%x00–FF |abnf}} ||8 bits of data |- |CTL || {{codett|%x00–1F / %x7F |abnf}} ||Controls |- |CR || {{codett|%x0D |abnf}} ||Carriage return |- |LF || {{codett|%x0A |abnf}} ||Linefeed |- |CRLF || {{codett|CR LF |abnf}} ||Internet-standard newline |- |BIT || {{codett|"0" / "1" |abnf}} ||Binary digit |- |} Note that in the core rules diagram the '''CHAR2''' charset is inlined in '''char-val''' and '''CHAR3''' is inlined in '''prose-val''' in the RFC spec. They are named here for clarity in the main syntax diagram.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)