Grammar Documentation
Grammar Reference
[1]
grammar
entry pointW3C Extended Backus-Naur Form (WBNF) — self-describing grammar
Based on the notation defined in the W3C XML 1.0 specification
https://www.w3.org/TR/xml/#sec-notation
A WBNF grammar consists of one or more rule definitions.
Based on the notation defined in the W3C XML 1.0 specification
https://www.w3.org/TR/xml/#sec-notation
A WBNF grammar consists of one or more rule definitions.
Grammar definition
[1] grammar ::= rule+
Railroad diagram
References
[2]
rule
A rule definition consists of an optional rule number, a rule name,
the ::= assignment operator, and an expression defining the rule.
the ::= assignment operator, and an expression defining the rule.
Grammar definition
[2] rule ::= rule-number? name '::=' expression
Railroad diagram
Referenced by
References
[3]
rule-number
An optional rule number prefix for documentation purposes.
Rule numbers may include a letter suffix e.g. [4a]. They are
used as cross-references in specifications and have no effect
on parsing.
Rule numbers may include a letter suffix e.g. [4a]. They are
used as cross-references in specifications and have no effect
on parsing.
Grammar definition
[3] rule-number ::= '[' [0-9]+ [a-zA-Z]? ']'
Railroad diagram
Referenced by
[4]
name
A rule name is an identifier. It must begin with a letter,
underscore, or colon, and may contain letters, digits, hyphens,
periods, underscores, and colons.
underscore, or colon, and may contain letters, digits, hyphens,
periods, underscores, and colons.
Grammar definition
[4] name ::= [a-zA-Z_:] [a-zA-Z0-9_.:-]*
Railroad diagram
Referenced by
[5]
expression
An expression is one or more sequences separated by the |
alternation operator. The first matching alternative is used.
alternation operator. The first matching alternative is used.
Grammar definition
[5] expression ::= sequence ('|' sequence)*Railroad diagram
Referenced by
References
[6]
sequence
A sequence is one or more terms in order, with an optional
exclusion. The - operator excludes strings matching the right
side from those matching the left side.
exclusion. The - operator excludes strings matching the right
side from those matching the left side.
Grammar definition
[6] sequence ::= term+ ('-' term+)?Railroad diagram
Referenced by
References
[7]
term
A term is a primary element with an optional suffix operator
controlling repetition.
controlling repetition.
Grammar definition
[7] term ::= primary suffix?
Railroad diagram
Referenced by
References
[8]
suffix
Suffix operators control how many times a term may occur.
? means zero or one, * means zero or more, + means one or more.
? means zero or one, * means zero or more, + means one or more.
Grammar definition
[8] suffix ::= '?' | '*' | '+'
Railroad diagram
Referenced by
[9]
primary
A primary element is a grouped expression, a character class,
a Unicode hex character value, a quoted string, or a rule name
reference.
a Unicode hex character value, a quoted string, or a rule name
reference.
Grammar definition
[9] primary ::= group | char-class | hex-char | string | name
Railroad diagram
Referenced by
References
[10]
group
A grouped expression encloses an expression in parentheses to
control precedence and grouping.
control precedence and grouping.
Grammar definition
[10] group ::= '(' expression ')'Railroad diagram
Referenced by
References
[11]
char-class
A character class matches any single character in the set.
A leading ^ negates the class. May contain hex character
references and ranges.
A leading ^ negates the class. May contain hex character
references and ranges.
Grammar definition
[11] char-class ::= '[' '^'? char-range+ ']'
Railroad diagram
Referenced by
References
[12]
char-range
A character range within a character class. May be a hex range,
a single hex value, or any literal character except #x5D ']' and #x5C '\'.
a single hex value, or any literal character except #x5D ']' and #x5C '\'.
Grammar definition
[12] char-range ::= hex-char '-' hex-char | hex-char | [^#x5D#x5C]
Railroad diagram
Referenced by
References
[13]
hex-char
A Unicode character specified by hexadecimal code point.
For example #x20 is the space character, #xD7FF is the last
character before the surrogate range.
For example #x20 is the space character, #xD7FF is the last
character before the surrogate range.
Grammar definition
[13] hex-char ::= '#x' [0-9a-fA-F]+
Railroad diagram
Referenced by
[14]
string
A quoted string literal. May use either double or single quotes.
Matches the exact characters within the quotes.
Matches the exact characters within the quotes.
Grammar definition
[14] string ::= '"' [^"]* '"' | "'" [^']* "'"
Railroad diagram
Referenced by