summaryrefslogtreecommitdiff
path: root/spec/syntax.abnf
blob: 132deeb910bc1159728a5f22df89bba2842d6836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;This file follows strict ABNF rules and can be used with abnfgen.


File          = [Unit] *( Blank Unit ) *Blank [Trail]


Unit          = *Blank Datum

Blank         = HTAB / LF / %x0b / %x0c / CR / SP / Comment

Trail         = SkipLine / SkipUnit


Datum         = BareString
              / DottedString
              / CladDatum
              / HashExpr
              / HashDotExpr
              / QuoteExpr
              / JoinExpr

Comment       = SkipLine LF / SkipUnit Blank

SkipLine      = ';' [ SkipLStart *AnyButLF ]

SkipLStart    = %x00-09 / %x0b-7d / %x7f-ff
              ; any but LF or '~'

AnyButLF      = %x00-09 / %x0b-ff

SkipUnit      = ';' '~' Unit


BareString    = BareChar *( BareChar / Numeric )

DottedString  = ( '.' / Numeric ) *( '.' / Numeric / BareChar )

CladDatum     = '|' *( PipeStrChar / '\' StringEsc ) '|'
              / '"' *( QuotStrChar / '\' StringEsc ) '"'
              / '(' List ')' / '[' List ']' / '{' List '}'

HashExpr      = LabelExpr / RuneExpr / HashDatum

HashDotExpr   = RuneDotExpr / HashDotDatum

QuoteExpr     = "'" Datum / '`' Datum / ',' Datum

JoinExpr      = Datum LeftCladDatum
              / Datum ':' Datum
              / DotlessDatum '.' Datum

LeftCladDatum = CladDatum / HashExpr / QuoteExpr

DotlessDatum  = BareString / CladDatum / RuneExpr / HashDatum


BareChar      = '!' / '$' / '%' / '*' / '/' / '<' / '=' / '>'
              / '?' / '@' / '^' / '_' / '~' / ALPHA

Numeric       = '+' / '-' / DIGIT

PipeStrChar   = %x00-5b / %x5d-7b / %x7d-ff
              ; any but '|' or '\'

QuotStrChar   = %x00-21 / %x23-5b / %x5d-ff
              ; any but '"' or '\'

List          = [Unit] *( Blank Unit ) *Blank [Tail] [SkipUnit]

Tail          = '&' Unit *Blank

LabelExpr     = '#' '%' Label ( '%' / '=' Datum )

RuneExpr      = '#' Rune [ '\' BareString / CladDatum ]

RuneDotExpr   = '#' Rune '\' DottedString

HashDatum     = '#' '\' BareString / CladDatum

HashDotDatum  = '#' '\' DottedString


; Unicode escapes must not represent surrogate code points.
; This is difficult to express in ABNF.  But we do at least
; disallow code points greater than \u10FFFF which are also
; invalid, since U+10FFFF is the highest allowed.
StringEsc     = '\' / '|' / '"' / *( HTAB / SP ) LF *( HTAB / SP )
              / 'a' / 'b' / 't' / 'n' / 'v' / 'f' / 'r' / 'e'
              / 'x' 1*( 2HEXDIG ) ';'
              / 'u' ['0'] 1*5HEXDIG ';'
              / 'u' '1' '0' 4HEXDIG ';'


Rune          = ALPHA *5( ALPHA / DIGIT )

Label         = 1*12( HEXDIG )