Grammar Documentation
Grammar Reference
Generated May 6, 2026 · 14 rules · WBNF · Generated by DevDiagrams
[1]

grammar

entry point
W3C 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.
[1]  grammar     ::= rule+
rule
[2]

rule

A rule definition consists of an optional rule number, a rule name,
the ::= assignment operator, and an expression defining the rule.
[2]  rule        ::= rule-number? name '::=' expression
rule-number name '::=' expression
[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.
[3]  rule-number ::= '[' [0-9]+ [a-zA-Z]? ']'
'[' [0-9] [a-zA-Z] ']'
[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.
[4]  name  ::= [a-zA-Z_:] [a-zA-Z0-9_.:-]*
[a-zA-Z_:] [a-zA-Z0-9_.:-]
[5]

expression

An expression is one or more sequences separated by the |
alternation operator. The first matching alternative is used.
[5]  expression  ::= sequence ('|' sequence)*
sequence '|' sequence
[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.
[6]  sequence    ::= term+ ('-' term+)?
term '-' term
[7]

term

A term is a primary element with an optional suffix operator
controlling repetition.
[7]  term        ::= primary suffix?
primary suffix
[8]

suffix

Suffix operators control how many times a term may occur.
? means zero or one, * means zero or more, + means one or more.
[8]  suffix      ::= '?' | '*' | '+'
'?' '*' '+'
[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.
[9]  primary     ::= group | char-class | hex-char | string | name
group char-class hex-char string name
[10]

group

A grouped expression encloses an expression in parentheses to
control precedence and grouping.
[10] group       ::= '(' expression ')'
'(' expression ')'
[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.
[11] char-class  ::= '[' '^'? char-range+ ']'
'[' '^' char-range ']'
[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 '\'.
[12] char-range  ::= hex-char '-' hex-char | hex-char | [^#x5D#x5C]
hex-char '-' hex-char hex-char [^#x5D#x5C]
[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.
[13] hex-char    ::= '#x' [0-9a-fA-F]+
'#x' [0-9a-fA-F]
[14]

string

A quoted string literal. May use either double or single quotes.
Matches the exact characters within the quotes.
[14] string      ::= '"' [^"]* '"' | "'" [^']* "'"
'"' [^"] '"' "'" [^'] "'"