Grammar Documentation
Grammar Reference
rulelist
entry pointrulelist — The top-level rule. An ABNF grammar consists of one or more
rules or blank lines (comment/newline combinations).
rules or blank lines (comment/newline combinations).
Grammar definition
rulelist = 1 * ( rule / ( * c-wsp c-nl ) )
Railroad diagram
References
rule
rule — A single rule definition. Consists of a rule name, the defined-as
operator, the rule elements, and a terminating newline. A rule may
continue on the next line if that line begins with whitespace.
operator, the rule elements, and a terminating newline. A rule may
continue on the next line if that line begins with whitespace.
Grammar definition
rule = rulename defined-as elements c-nl
Railroad diagram
Referenced by
References
rulename
continues if next line starts
with white space
rulename — The name of a rule. Must begin with a letter and may contain
letters, digits, and hyphens.
with white space
rulename — The name of a rule. Must begin with a letter and may contain
letters, digits, and hyphens.
Grammar definition
rulename = ALPHA * ( ALPHA / DIGIT / "-" )
Railroad diagram
Referenced by
References
ALPHADIGIT
defined-as
defined-as — The operator that separates a rule name from its definition.
"=" defines a new rule. "=/" incrementally adds alternatives to an
existing rule. Optional whitespace is allowed on either side.
"=" defines a new rule. "=/" incrementally adds alternatives to an
existing rule. Optional whitespace is allowed on either side.
Grammar definition
defined-as = * c-wsp ( "=" / "=/" ) * c-wsp
Railroad diagram
Referenced by
References
elements
basic rules definition and
incremental alternatives
elements — The body of a rule definition, consisting of an alternation
followed by optional whitespace.
incremental alternatives
elements — The body of a rule definition, consisting of an alternation
followed by optional whitespace.
Grammar definition
elements = alternation * c-wsp
Railroad diagram
Referenced by
References
c-wsp
c-wsp — Comment or whitespace. Either a plain whitespace character or
a newline followed by whitespace (enabling rule continuation across lines).
a newline followed by whitespace (enabling rule continuation across lines).
Grammar definition
c-wsp = WSP / ( c-nl WSP )
Railroad diagram
Referenced by
References
WSPc-nl
c-nl
c-nl — Comment or newline. Either a semicolon comment or a bare CRLF.
Used as optional padding and as the rule terminator.
Used as optional padding and as the rule terminator.
Grammar definition
c-nl = comment / CRLF
Railroad diagram
Referenced by
References
commentCRLF
comment
comment or newline
comment — A line comment beginning with a semicolon and ending with CRLF.
May contain any printable characters and spaces.
comment — A line comment beginning with a semicolon and ending with CRLF.
May contain any printable characters and spaces.
Grammar definition
comment = ";" * ( WSP / VCHAR ) CRLF
Railroad diagram
Referenced by
References
WSPVCHARCRLF
alternation
alternation — A choice between two or more concatenations, separated by
the "/" operator. Optional whitespace is permitted around the operator.
the "/" operator. Optional whitespace is permitted around the operator.
Grammar definition
alternation = concatenation * ( * c-wsp "/" * c-wsp concatenation )
Railroad diagram
Referenced by
References
concatenation
concatenation — A sequence of one or more repetitions. Elements in a
concatenation must be separated by at least one whitespace character.
concatenation must be separated by at least one whitespace character.
Grammar definition
concatenation = repetition * ( 1 * c-wsp repetition )
Railroad diagram
Referenced by
References
repetition
repetition — An optional repeat count followed by an element. If no
repeat count is given, the element occurs exactly once.
repeat count is given, the element occurs exactly once.
Grammar definition
repetition = [ repeat ] element
Railroad diagram
Referenced by
References
repeat
repeat — Specifies how many times an element may occur. Supports exact
counts, minimum counts, maximum counts, and ranges.
counts, minimum counts, maximum counts, and ranges.
Grammar definition
repeat = 1 * DIGIT / ( * DIGIT "*" * DIGIT )
Railroad diagram
Referenced by
References
DIGIT
element
element — A single grammar element. May be a rule name reference, a
grouped alternation, an optional group, a character value, a numeric
value, or a prose description.
grouped alternation, an optional group, a character value, a numeric
value, or a prose description.
Grammar definition
element = rulename / group / option / char-val / num-val / prose-val
Railroad diagram
Referenced by
References
group
group — A grouped alternation enclosed in parentheses. Used to control
precedence and grouping of alternatives.
precedence and grouping of alternatives.
Grammar definition
group = "(" * c-wsp alternation * c-wsp ")"Railroad diagram
Referenced by
References
option
option — An optional grouped alternation enclosed in square brackets.
Equivalent to the grouped alternation occurring zero or one times.
Equivalent to the grouped alternation occurring zero or one times.
Grammar definition
option = "[" * c-wsp alternation * c-wsp "]"
Railroad diagram
Referenced by
References
char-val
char-val — A quoted string literal. May be case-sensitive (prefixed with
%s) or case-insensitive (prefixed with %i or no prefix). Contains any
printable characters except double-quote.
%s) or case-insensitive (prefixed with %i or no prefix). Contains any
printable characters except double-quote.
Grammar definition
char-val = DQUOTE * ( %x20-21 / %x23-7E ) DQUOTE
Railroad diagram
Referenced by
References
DQUOTE
num-val
quoted string of SP and VCHAR
without DQUOTE
num-val — A numeric character value. May be binary (%b), decimal (%d),
or hexadecimal (%x). Supports single values, ranges, and concatenations.
without DQUOTE
num-val — A numeric character value. May be binary (%b), decimal (%d),
or hexadecimal (%x). Supports single values, ranges, and concatenations.
Grammar definition
num-val = "%" ( bin-val / dec-val / hex-val )
Railroad diagram
Referenced by
References
bin-val
bin-val — A binary numeric value. Consists of the "b" prefix followed by
binary digits. Optionally followed by a range or concatenation of values.
binary digits. Optionally followed by a range or concatenation of values.
Grammar definition
bin-val = "b" 1 * BIT [ 1 * ( "." 1 * BIT ) / ( "-" 1 * BIT ) ]
Railroad diagram
Referenced by
References
BIT
dec-val
series of concatenated bit values
or single ONEOF range
dec-val — A decimal numeric value. Consists of the "d" prefix followed by
decimal digits. Optionally followed by a range or concatenation of values.
or single ONEOF range
dec-val — A decimal numeric value. Consists of the "d" prefix followed by
decimal digits. Optionally followed by a range or concatenation of values.
Grammar definition
dec-val = "d" 1 * DIGIT [ 1 * ( "." 1 * DIGIT ) / ( "-" 1 * DIGIT ) ]
Railroad diagram
Referenced by
References
DIGIT
hex-val
hex-val — A hexadecimal numeric value. Consists of the "x" prefix followed
by hexadecimal digits. Optionally followed by a range or concatenation.
by hexadecimal digits. Optionally followed by a range or concatenation.
Grammar definition
hex-val = "x" 1 * HEXDIG [ 1 * ( "." 1 * HEXDIG ) / ( "-" 1 * HEXDIG ) ]
Railroad diagram
Referenced by
References
HEXDIG
prose-val
prose-val — A prose description enclosed in angle brackets. Used as a
last resort when a construct cannot be formally expressed in ABNF.
May contain any printable characters except angle brackets.
last resort when a construct cannot be formally expressed in ABNF.
May contain any printable characters except angle brackets.
Grammar definition
prose-val = "<" * ( %x20-3D / %x3F-7E ) ">"
Railroad diagram
Referenced by