forked from FamilySearch/GEDCOM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.abnf
262 lines (195 loc) · 8.66 KB
/
grammar.abnf
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
; This document is in ABNF, see <https://tools.ietf.org/html/std68>
; This document uses RFC 7405 to add case-sensitive literals to ABNF.
; ------------- Characters -------------
banned = %x00-08 / %x0B-0C / %x0E-1F ; C0 other than LF CR and Tab
/ %x7F ; DEL
/ %x80-9F ; C1
/ %xD800-DFFF ; Surrogates
/ %xFFFE-FFFF ; invalid
; All other rules assume the absence of any banned characters
; DIGIT = %x30-39 ; 0 through 9 -- defined in RFC 5234 section B.1
nonzero = %x31-39 ; 1 through 9
ucletter = %x41-5A ; A through Z
underscore = %x5F ; _
atsign = %x40 ; @
; ------------- Lines -------------
Line = Level D [Xref D] Tag [D LineVal] EOL
Level = "0" / nonzero *DIGIT
D = %x20 ; space
Xref = atsign 1*tagchar atsign ; but not "@VOID@"
Tag = stdTag / extTag
LineVal = pointer / lineStr
EOL = %x0D [%x0A] / %x0A ; CR-LF, CR, or LF
stdTag = ucletter *tagchar
extTag = underscore 1*tagchar
tagchar = ucletter / DIGIT / underscore
pointer = voidPtr / Xref
voidPtr = %s"@VOID@"
nonAt = %x09 / %x20-3F / %x41-10FFFF ; non-EOL, non-@
nonEOL = %x09 / %x20-10FFFF ; non-EOL
lineStr = (nonAt / atsign atsign) *nonEOL ; leading @ doubled
; ------------- Text -------------
anychar = %x09-10FFFF ; but not banned, as with all ABNF rules
Text = *anychar
; ------------- Integer -------------
Integer = 1*DIGIT
; ------------- Enumeration -------------
stdEnum = stdTag / Integer
Enum = stdEnum / extTag
; ------------- Date -------------
DateValue = [ date / DatePeriod / dateRange / dateApprox ]
DateExact = day D month D year ; in Gregorian calendar
DatePeriod = [ %s"TO" D date ]
/ %s"FROM" D date [ D %s"TO" D date ]
; note both DateValue and DatePeriod can be the empty string
date = [calendar D] [[day D] month D] year [D epoch]
dateRange = %s"BET" D date D %s"AND" D date
/ %s"AFT" D date
/ %s"BEF" D date
dateApprox = (%s"ABT" / %s"CAL" / %s"EST") D date
dateRestrict = %s"FROM" / %s"TO" / %s"BET" / %s"AND" / %s"BEF"
/ %s"AFT" / %s"ABT" / %s"CAL" / %s"EST"
calendar = %s"GREGORIAN" / %s"JULIAN" / %s"FRENCH_R" / %s"HEBREW"
/ extTag
day = Integer
year = Integer
month = stdTag / extTag ; constrained by calendar
epoch = %s"BCE" / extTag ; constrained by calendar
; ------------- Time -------------
Time = hour ":" minute [":" second ["." fraction]] [%s"Z"]
hour = DIGIT / ("0" / "1") DIGIT / "2" ("0" / "1" / "2" / "3")
minute = ("0" / "1" / "2" / "3" / "4" / "5") DIGIT
second = ("0" / "1" / "2" / "3" / "4" / "5") DIGIT
fraction = 1*DIGIT
; ------------- Age -------------
Age = [[ageBound D] ageDuration]
ageBound = "<" / ">"
ageDuration = years [D months] [D weeks] [D days]
/ months [D weeks] [D days]
/ weeks [D days]
/ days
years = Integer %x79 ; 35y
months = Integer %x6D ; 11m
weeks = Integer %x77 ; 8w
days = Integer %x64 ; 21d
; ------------- List -------------
list = listItem *(listDelim listItem)
listItem = [ nocommasp / nocommasp *nocomma nocommasp ]
listDelim = *D "," *D
nocomma = %x09-2B / %x2D-10FFFF
nocommasp = %x09-1D / %x21-2B / %x2D-10FFFF
List-Text = list
List-Enum = Enum *(listDelim Enum)
; ------------- Personal Name -------------
PersonalName = nameStr
/ [nameStr] "/" [nameStr] "/" [nameStr]
nameChar = %x20-2E / %x30-10FFFF ; any but '/' and '\t'
nameStr = 1*nameChar
; ------------- Media Type -------------
MediaType = type "/" subtype parameters
; ------------- Special -------------
Special = Text
; ABNF derived from RFC 5646 section 2.1
Language-Tag = langtag ; normal language tags
/ privateuse ; private use tag
/ grandfathered ; grandfathered tags
langtag = language
["-" script]
["-" region]
*("-" variant)
*("-" extension)
["-" privateuse]
language = 2*3ALPHA ; shortest ISO 639 code
["-" extlang] ; sometimes followed by
; extended language subtags
/ 4ALPHA ; or reserved for future use
/ 5*8ALPHA ; or registered language subtag
extlang = 3ALPHA ; selected ISO 639 codes
*2("-" 3ALPHA) ; permanently reserved
script = 4ALPHA ; ISO 15924 code
region = 2ALPHA ; ISO 3166-1 code
/ 3DIGIT ; UN M.49 code
variant = 5*8alphanum ; registered variants
/ (DIGIT 3alphanum)
extension = singleton 1*("-" (2*8alphanum))
; Single alphanumerics
; "x" reserved for private use
singleton = DIGIT ; 0 - 9
/ %x41-57 ; A - W
/ %x59-5A ; Y - Z
/ %x61-77 ; a - w
/ %x79-7A ; y - z
privateuse = "x" 1*("-" (1*8alphanum))
grandfathered = irregular ; non-redundant tags registered
/ regular ; during the RFC 3066 era
irregular = "en-GB-oed" ; irregular tags do not match
/ "i-ami" ; the 'langtag' production and
/ "i-bnn" ; would not otherwise be
/ "i-default" ; considered 'well-formed'
/ "i-enochian" ; These tags are all valid,
/ "i-hak" ; but most are deprecated
/ "i-klingon" ; in favor of more modern
/ "i-lux" ; subtags or subtag
/ "i-mingo" ; combination
/ "i-navajo"
/ "i-pwn"
/ "i-tao"
/ "i-tay"
/ "i-tsu"
/ "sgn-BE-FR"
/ "sgn-BE-NL"
/ "sgn-CH-DE"
regular = "art-lojban" ; these tags match the 'langtag'
/ "cel-gaulish" ; production, but their subtags
/ "no-bok" ; are not extended language
/ "no-nyn" ; or variant subtags: their meaning
/ "zh-guoyu" ; is defined by their registration
/ "zh-hakka" ; and all of these are deprecated
/ "zh-min" ; in favor of a more modern
/ "zh-min-nan" ; subtag or sequence of subtags
/ "zh-xiang"
alphanum = (ALPHA / DIGIT) ; letters and numbers
; ABNF derived from RFC 2045 section 5.1
type = discrete-type / composite-type
discrete-type = "text" / "image" / "audio" / "video" /
"application" / extension-token
composite-type = "message" / "multipart" / extension-token
extension-token = ietf-token / x-token
ietf-token = type-name
x-token = "x-" token
subtype = extension-token / iana-token
iana-token = subtype-name
; ABNF derived from RFC 6838 section 4.2
type-name = restricted-name
subtype-name = restricted-name
restricted-name = restricted-name-first *126restricted-name-chars
restricted-name-first = ALPHA / DIGIT
restricted-name-chars = ALPHA / DIGIT / "!" / "#" /
"$" / "&" / "-" / "^" / "_"
restricted-name-chars =/ "." ; Characters before first dot always
; specify a facet name
restricted-name-chars =/ "+" ; Characters after last plus always
; specify a structured syntax suffix
; ABNF derived from RFC 9110 section 5.6
parameters = *( OWS ";" OWS [ parameter ] )
parameter = parameter-name "=" parameter-value
parameter-name = token
parameter-value = ( token / quoted-string )
token = 1*tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
/ "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
/ DIGIT / ALPHA
; any VCHAR, except delimiters
OWS = *( SP / HTAB )
; optional whitespace
quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
obs-text = %x80-FF
quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
; Core Rules extracted from RFC 5234 section B.1
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
DIGIT = %x30-39 ; 0-9
SP = %x20
HTAB = %x09 ; horizontal tab
DQUOTE = %x22 ; " (Double Quote)
VCHAR = %x21-7E ; visible (printing) characters