-
Notifications
You must be signed in to change notification settings - Fork 10
/
xmldtd.nez
253 lines (189 loc) · 4.71 KB
/
xmldtd.nez
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
// XML Document Type Declaration
// author Shinya Yamaguchi
TopLevel
= Document
Document
= PROLOG? { ($(Dtd))+ #Root} _
PROLOG
= '<?xml' (!'?>' .)* '?>' _
Dtd
= '<!' (ElementDeclaration / AttributeListDeclaration / EntityDeclaration / ConditionalSection) '>' _
/* Tokens */
"<" = '<' _
"<!" = '<!' _
">" = '>' _
"(" = '(' _
")" = ')' _
"[" = '[' _
"]]" = ']]' _
";" = ';' _
"|" = '|' _
"," = ',' _
"%" = '%' _
/* keyword */
"ANY" = 'ANY' !W _
"ATTLIST" = 'ATTLIST' !W _
"CDATA" = 'CDATA' !W _
"ELEMENT" = 'ELEMENT' !W _
"EMPTY" = 'EMPTY' !W _
"ENTITIES" = 'ENTITIES' !W _
"ENTITY" = 'ENTITY' !W _
"ID" = 'ID' !W _
"IDREF" = 'IDREF' !W _
"IDREFS" = 'IDREFS' !W _
"INCLUDE" = 'INCLUDE' !W _
"IGNORE" = 'IGNORE' !W _
"NDATA" = 'NDATA' !W _
"NMTOKEN" = 'NMTOKEN' !W _
"NMTOKENS" = 'NMTOKENS' !W _
"PUBLIC" = 'PUBLIC' !W _
"SYSTEM" = 'SYSTEM' !W _
"#FIXED" = '#FIXED' !W _
"#IMPLIED" = '#IMPLIED' !W _
"#PCDATA" = '#PCDATA' !W _
"#REQUIRED" = '#REQUIRED' !W _
/* Conditional Section */
ConditionalSection
= {IGNORE / _Include #CondSect}
_Include
= "[" ('INCLUDE'/NAME) "[" $(Dtd)* NAME? _ "]]"
IGNORE
= "[" "IGNORE" "[" IGNORESECT* "]]"
IGNORESECT
= "<!" (!'>' .)* ">"
/ '%' NAME ";"
/ (!']' .)+
example ConditionalSection ~28c214 '''
[IGNORE[
<!ELEMENT book (title,author,summary)>
]]
'''
example ConditionalSection ~837bd6 '''
[INCLUDE[
<!ELEMENT book (comments*,title,author,summary)>
]]
'''
/* Element Declaration */
ElementDeclaration
= "ELEMENT" {$name(Name) $member(Content) {$ &'' _Qualifier}? #Element} _
Content
= SpecialContent
/ "(" (PCData / ElementName) ")"
/ Member
SpecialContent
= {"EMPTY" #Empty}
/ {"ANY" #Any}
Member
= PCData
/ ElementName
/ Choice
/ Sequence
PCData
= {"#PCDATA" #Data} _
ElementName
= { NAME #ElName } {@ &'' _Qualifier}? _
Choice
= "(" { $(Member) _ ("|" $(Member))+ #Choice} ")" {$ &'' _Qualifier}? _
Sequence
= "(" { $(Member) _ ("," $(Member))+ #Sequence} ")" {$ &'' _Qualifier}? _
_Qualifier
= '+' #OneMore
/ '*' #ZeroMore
/ '?' #Option
example ElementDeclaration ~d7cf5b ELEMENT a EMPTY
example ElementDeclaration ~cbca6a ELEMENT a (#PCDATA)
example ElementDeclaration ~3a22b9 ELEMENT a (b|c)
example ElementDeclaration ~9eac9b ELEMENT a (b,c)
example ElementDeclaration ~5a7c57 ELEMENT a (b|c)*
example ElementDeclaration ~abe358 ELEMENT a ((b|c),(d|e))
/* Attribute Declaration */
AttributeListDeclaration
= "ATTLIST" { $name(Name) $(AttributeDefinition)+ #Attlist} _
AttributeDefinition
= { $name(Name) $type(AttributeType) _AttributeQualifier } _
AttributeType
= PrimitiveType / EnumerationType
PrimitiveType
= {"CDATA" #CDATA}
/ {"IDREFS" #IDREFS}
/ {"IDREF" #IDREF}
/ {"ID" #ID}
/ {"ENTITY" #ENTITY}
/ {"ENTITIES" #ENTITIES}
/ {"NMTOKENS" #NMTOKENS}
/ {"NMTOKEN" #NMTOKEN}
EnumerationType
= "(" { $(Name) ( "|" $(Name) )* #Enum } ")"
_AttributeQualifier
= "#REQUIRED" #REQUIRED
/ "#IMPLIED" #IMPLIED
/ "#FIXED" _DefaultValue #FIXED
/ _DefaultValue #Default
_DefaultValue
= '"' $value({ (![<&"].)* #Value}) '"'
/ '\'' $value({ (![<&"].)* #Value}) '\''
example AttributeListDeclaration ~9ed8f3 ATTLIST a b CDATA #REQUIRED
example AttributeListDeclaration ~a4844a ATTLIST a b CDATA #IMPLIED
example AttributeListDeclaration ~13c524 ATTLIST a b (a|b) #REQUIRED
example AttributeListDeclaration ~83503c ATTLIST a b CDATA #FIXED "c"
example AttributeListDeclaration ~4f7997 ATTLIST a b CDATA "c"
example AttributeListDeclaration ~73d62d '''
ATTLIST a
b CDATA #REQUIRED
c ID #IMPLIED
'''
/* Entity Declaration */
EntityDeclaration
= "ENTITY" (ExternalEntity /InternalEntity) _
ExternalEntity
= { $name(Name) _EntityDefinition #Entity} _
// Internal Entity is ignored
InternalEntity
= { "%" NAME _ IECONTENTS #Internal } _
_EntityDefinition
= $value(EntityValue)
/ EXID NDATADECL? //ignored
IECONTENTS
= STRINGCONTENT / EXID
EntityValue
= '"'{ (!["].)* #Value}'"'
EXID
= "SYSTEM" SLITERAL
/ "PUBLIC" PUBIDLITERAL _ SLITERAL
NDATADECL
= "NDATA" NAME
SLITERAL
= ( '\'' ( !'\'' . )* '\'')
/ ( '"' ( !'"' . )* '"')
PUBIDLITERAL
= '"' PUBLICCHAR* '"'
PUBLICCHAR
= [a-zA-Z0-9]
/ [-'()+,./:=?;!*#@$_% ]
/ [\xD] / [\xA]
example EntityDeclaration ~8116db ENTITY W3C "World Wide Web Consortium"
example EntityDeclaration ~99d221 '''
ENTITY open-hatch
SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml"
'''
example EntityDeclaration ~3c3c95 '''
ENTITY % ISOLat2
SYSTEM "http://www.xml.com/iso/isolat2-xml.entities"
'''
// Literal
Name
= { NAME #Name } _
NAME
= [A-Za-z:%_] ([-A-Za-z0-9:._%;])*
W
= [a-zA-Z0-9_:%]
String
= '"' { ( !'"' . )* #String } '"'
STRINGCONTENT
= '"' ( !'"' . )* '"'
// Code Layout
_
= (S / COMMENT)*
COMMENT
= '<!--' (!'-->' . )* '-->'
S = [ \t\r\n]