summaryrefslogtreecommitdiff
path: root/docs/c1/grammar/abnf.txt
blob: 6daacebc53eeb8e757e56f6b75c91f8309831b56 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
; Standards-compliant ABNF (RFC 5234, RFC 7405)

; Compatible with: https://www.quut.com/abnfgen/

; It's unclear whether this grammar is truly complete.  It has been
; verified not to produce text that is rejected by the Zisp parser
; --except for Unicode escape sequences for surrogate code points--
; but there may be some text that is accepted by the parser despite
; not being grammatical according to these rules.


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


Unit          = *Blank Datum

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

Trail         = SkipLine / SkipUnit / ";" "~" *Blank


Datum         = BareString / DottedStr / CladDatum / Rune / RuneStr
              / RuneDotStr / RuneClad / LabelRef / LabelDef / HashStr
              / HashDotStr / HashClad / QuoteExpr / JoinExpr

Comment       = SkipLine LF / SkipUnit Blank

SkipLine      = ";" [ SkipLStart *AnyButLF ]

SkipUnit      = ";" "~" Unit

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

AnyButLF      = %x00-09 / %x0b-ff


BareString    = BareChar *( BareChar / Numeric )

DottedStr     = ( "." / Numeric ) *( "." / Numeric / BareChar )

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

Rune          = "#" RuneName

RuneStr       = "#" RuneName "\" BareString

RuneDotStr    = "#" RuneName "\" DottedStr

RuneClad      = "#" RuneName CladDatum

LabelRef      = "#" "%" Label "%"

LabelDef      = "#" "%" Label "=" Datum

HashStr       = "#" "\" BareString

HashDotStr    = "#" "\" DottedStr

HashClad      = "#" CladDatum

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

JoinExpr      = Datum RJoinDatum
              / LJoinDatum NoStartDot
              / Datum ":" Datum
              / NoEndDot "." Datum


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

Numeric       = "+" / "-" / DIGIT

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

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

StringEsc     = "\" / "|" / DQUOTE / *( HTAB / SP ) LF *( HTAB / SP )
              / %s"a" / %s"b" / %s"t" / %s"n"
              / %s"v" / %s"f" / %s"r" / %s"e"
              / %s"x" 1*( 2HEXDIG ) ";"
              / %s"u" ["0"] 1*5HEXDIG ";"
              / %s"u" "1" "0" 4HEXDIG ";"

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

Tail          = "&" Unit *Blank


RuneName      = ALPHA *5( ALPHA / DIGIT )

Label         = 1*12( HEXDIG )


RJoinDatum    = CladDatum / Rune / RuneStr / RuneDotStr / RuneClad
              / LabelRef / LabelDef / HashStr / HashDotStr / HashClad
              / QuoteExpr

LJoinDatum    = CladDatum / RuneClad / LabelRef / HashClad

NoStartDot    = BareString / CladDatum / Rune / RuneStr / RuneDotStr
              / RuneClad / LabelRef / LabelDef / HashStr / HashDotStr
              / HashClad / QuoteExpr

NoEndDot      = BareString / Rune / RuneStr / RuneClad / LabelRef
              / HashStr / HashClad