Grammar Documentation
Grammar Reference
Generated April 22, 2026 · 14 rules · ANTLR · Generated by DevDiagrams

abnf_grammar

entry point
abnf_grammar
    : rule_def* EOF
    ;
rule_def EOF

rule_def

rule = rulename defined-as elements c-nl
rule_def
    : rule_name defined_as alternation c_nl
    ;
rule_name defined_as alternation c_nl

rule_name

rulename = ALPHA *(ALPHA / DIGIT / "-")
rule_name
    : RULENAME
    ;
RULENAME

defined_as

defined-as = *c-wsp ("=" / "=/") *c-wsp
defined_as
    : EQUALS
    | INCREMENTAL_ALT
    ;
EQUALS INCREMENTAL_ALT

alternation

alternation = concatenation *(*c-wsp "/" *c-wsp concatenation)
alternation
    : concatenation (SLASH concatenation)*
    ;
concatenation SLASH concatenation

concatenation

concatenation = repetition *(1*c-wsp repetition)
concatenation
    : repetition+
    ;
repetition

repetition

repetition = [repeat] element
repetition
    : repeat? element
    ;
repeat element

repeat

repeat = 1*DIGIT / (*DIGIT "*" *DIGIT)
repeat
    : n = DIGIT_VAL ASTERISK m = DIGIT_VAL  // n*m — between n and m
    | n = DIGIT_VAL ASTERISK                // n*  — n or more
    | ASTERISK m = DIGIT_VAL                //  *m — up to m
    | ASTERISK                              //  *  — zero or more
    | n = DIGIT_VAL                         // n   — exactly n
    ;
n= DIGIT_VAL ASTERISK m= DIGIT_VAL n= DIGIT_VAL ASTERISK ASTERISK m= DIGIT_VAL ASTERISK n= DIGIT_VAL

element

element = rulename / group / option / char-val / num-val / prose-val
element
    : rule_name
    | group
    | option
    | char_val
    | num_val
    | PROSE_VAL
    ;
rule_name group option char_val num_val PROSE_VAL

group

group = "(" *c-wsp alternation *c-wsp ")"
group
    : LPAREN alternation RPAREN
    ;
LPAREN alternation RPAREN

option

option = "[" *c-wsp alternation *c-wsp "]"
option
    : LBRACKET alternation RBRACKET
    ;
LBRACKET alternation RBRACKET

char_val

char-val = case-insensitive-string / case-sensitive-string case-insensitive-string = [ "%i" ] quoted-string case-sensitive-string = "%s" quoted-string (RFC 7405)
char_val
    : CASE_SENSITIVE_STRING
    | CASE_INSENSITIVE_STRING
    | QUOTED_STRING
    ;
CASE_SENSITIVE_STRING CASE_INSENSITIVE_STRING QUOTED_STRING

num_val

num-val = "%" (bin-val / dec-val / hex-val)
num_val
    : BIN_VAL
    | DEC_VAL
    | HEX_VAL
    ;
BIN_VAL DEC_VAL HEX_VAL

c_nl

c-nl = comment / CRLF / LF
c_nl
    : CRLF
    | LF
    | EOF
    ;
CRLF LF EOF