]> code.delx.au - gnu-emacs/blob - lisp/progmodes/ebnf-dtd.el
(gud-tooltip-dereference): Add missing optional argument.
[gnu-emacs] / lisp / progmodes / ebnf-dtd.el
1 ;;; ebnf-dtd.el --- parser for DTD (Data Type Description for XML)
2
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
4 ;; Free Sofware Foundation, Inc.
5
6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8 ;; Time-stamp: <2004/04/04 21:50:16 vinicius>
9 ;; Keywords: wp, ebnf, PostScript
10 ;; Version: 1.0
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;;; Commentary:
30
31 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 ;;
33 ;;
34 ;; This is part of ebnf2ps package.
35 ;;
36 ;; This package defines a parser for DTD (Data Type Description for XML).
37 ;;
38 ;; See ebnf2ps.el for documentation.
39 ;;
40 ;;
41 ;; DTD Syntax
42 ;; ----------
43 ;;
44 ;; See the URLs:
45 ;; `http://www.w3.org/TR/2004/REC-xml-20040204/'
46 ;; (Extensible Markup Language (XML) 1.0 (Third Edition))
47 ;; `http://www.w3.org/TR/html40/'
48 ;; (HTML 4.01 Specification)
49 ;; `http://www.w3.org/TR/NOTE-html-970421'
50 ;; (HTML DTD with support for Style Sheets)
51 ;;
52 ;;
53 ;; /* Document */
54 ;;
55 ;; document ::= prolog element Misc*
56 ;; /* Note that *only* the prolog will be parsed */
57 ;;
58 ;;
59 ;; /* Characters */
60 ;;
61 ;; Char ::= #x9 | #xA | #xD
62 ;; | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
63 ;; /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
64 ;;
65 ;; /* NOTE:
66 ;;
67 ;; Document authors are encouraged to avoid "compatibility characters", as
68 ;; defined in section 6.8 of [Unicode] (see also D21 in section 3.6 of
69 ;; [Unicode3]). The characters defined in the following ranges are also
70 ;; discouraged. They are either control characters or permanently undefined
71 ;; Unicode characters:
72 ;;
73 ;; [#x7F-#x84], [#x86-#x9F], [#xFDD0-#xFDDF],
74 ;; [#1FFFE-#x1FFFF], [#2FFFE-#x2FFFF], [#3FFFE-#x3FFFF],
75 ;; [#4FFFE-#x4FFFF], [#5FFFE-#x5FFFF], [#6FFFE-#x6FFFF],
76 ;; [#7FFFE-#x7FFFF], [#8FFFE-#x8FFFF], [#9FFFE-#x9FFFF],
77 ;; [#AFFFE-#xAFFFF], [#BFFFE-#xBFFFF], [#CFFFE-#xCFFFF],
78 ;; [#DFFFE-#xDFFFF], [#EFFFE-#xEFFFF], [#FFFFE-#xFFFFF],
79 ;; [#10FFFE-#x10FFFF]. */
80 ;;
81 ;;
82 ;; /* White Space */
83 ;;
84 ;; S ::= (#x20 | #x9 | #xD | #xA)+
85 ;;
86 ;;
87 ;; /* Names and Tokens */
88 ;;
89 ;; NameChar ::= Letter | Digit | '.' | '-' | '_' | ':'
90 ;; | CombiningChar | Extender
91 ;;
92 ;; Name ::= (Letter | '_' | ':') (NameChar)*
93 ;;
94 ;; Names ::= Name (#x20 Name)*
95 ;;
96 ;; Nmtoken ::= (NameChar)+
97 ;;
98 ;; Nmtokens ::= Nmtoken (#x20 Nmtoken)*
99 ;;
100 ;;
101 ;; /* Literals */
102 ;;
103 ;; EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
104 ;; | "'" ([^%&'] | PEReference | Reference)* "'"
105 ;;
106 ;; AttValue ::= '"' ([^<&"] | Reference)* '"'
107 ;; | "'" ([^<&'] | Reference)* "'"
108 ;;
109 ;; SystemLiteral ::= ('"' [^"]* '"')
110 ;; | ("'" [^']* "'")
111 ;;
112 ;; PubidLiteral ::= '"' PubidChar* '"'
113 ;; | "'" (PubidChar - "'")* "'"
114 ;;
115 ;; PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
116 ;;
117 ;; /* NOTE:
118 ;;
119 ;; Although the EntityValue production allows the definition of a general
120 ;; entity consisting of a single explicit < in the literal (e.g., <!ENTITY
121 ;; mylt "<">), it is strongly advised to avoid this practice since any
122 ;; reference to that entity will cause a well-formedness error. */
123 ;;
124 ;;
125 ;; /* Character Data */
126 ;;
127 ;; CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
128 ;;
129 ;;
130 ;; /* Comments */
131 ;;
132 ;; Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
133 ;;
134 ;;
135 ;; /* Processing Instructions */
136 ;;
137 ;; PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
138 ;;
139 ;; PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
140 ;;
141 ;;
142 ;; /* CDATA Sections */
143 ;;
144 ;; CDSect ::= CDStart CData CDEnd
145 ;;
146 ;; CDStart ::= '<![CDATA['
147 ;;
148 ;; CData ::= (Char* - (Char* ']]>' Char*))
149 ;;
150 ;; CDEnd ::= ']]>'
151 ;;
152 ;;
153 ;; /* Prolog */
154 ;;
155 ;; prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
156 ;;
157 ;; XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
158 ;;
159 ;; VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
160 ;;
161 ;; Eq ::= S? '=' S?
162 ;;
163 ;; VersionNum ::= '1.0'
164 ;;
165 ;; Misc ::= Comment | PI | S
166 ;;
167 ;;
168 ;; /* Document Type Definition */
169 ;;
170 ;; doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
171 ;; ('[' intSubset ']' S?)? '>'
172 ;; [VC: Root Element Type]
173 ;; [WFC: External Subset]
174 ;;
175 ;; DeclSep ::= PEReference | S
176 ;; [WFC: PE Between Declarations]
177 ;;
178 ;; intSubset ::= (markupdecl | DeclSep)*
179 ;;
180 ;; markupdecl ::= elementdecl | AttlistDecl | EntityDecl
181 ;; | NotationDecl | PI | Comment
182 ;; [VC: Proper Declaration/PE Nesting]
183 ;; [WFC: PEs in Internal Subset]
184 ;;
185 ;;
186 ;; /* External Subset */
187 ;;
188 ;; extSubset ::= TextDecl? extSubsetDecl
189 ;;
190 ;; extSubsetDecl ::= ( markupdecl | conditionalSect | DeclSep)*
191 ;;
192 ;;
193 ;; /* Standalone Document Declaration */
194 ;;
195 ;; SDDecl ::= S 'standalone' Eq
196 ;; (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
197 ;; [VC: Standalone Document Declaration]
198 ;;
199 ;;
200 ;; /* Element */
201 ;;
202 ;; element ::= EmptyElemTag | STag content ETag
203 ;; [WFC: Element Type Match]
204 ;; [VC: Element Valid]
205 ;;
206 ;;
207 ;; /* Start-tag */
208 ;;
209 ;; STag ::= '<' Name (S Attribute)* S? '>'
210 ;; [WFC: Unique Att Spec]
211 ;;
212 ;; Attribute ::= Name Eq AttValue
213 ;; [VC: Attribute Value Type]
214 ;; [WFC: No External Entity References]
215 ;; [WFC: No < in Attribute Values]
216 ;;
217 ;;
218 ;; /* End-tag */
219 ;;
220 ;; ETag ::= '</' Name S? '>'
221 ;;
222 ;;
223 ;; /* Content of Elements */
224 ;;
225 ;; content ::= CharData?
226 ;; ((element | Reference | CDSect | PI | Comment) CharData?)*
227 ;;
228 ;;
229 ;; /* Tags for Empty Elements */
230 ;;
231 ;; EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
232 ;; [WFC: Unique Att Spec]
233 ;;
234 ;;
235 ;; /* Element Type Declaration */
236 ;;
237 ;; elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
238 ;; [VC: Unique Element Type Declaration]
239 ;;
240 ;; contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
241 ;;
242 ;;
243 ;; /* Element-content Models */
244 ;;
245 ;; children ::= (choice | seq) ('?' | '*' | '+')?
246 ;;
247 ;; cp ::= (Name | choice | seq) ('?' | '*' | '+')?
248 ;;
249 ;; choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
250 ;; [VC: Proper Group/PE Nesting]
251 ;;
252 ;; seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
253 ;; [VC: Proper Group/PE Nesting]
254 ;;
255 ;;
256 ;; /* Mixed-content Declaration */
257 ;;
258 ;; Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*'
259 ;; | '(' S? '#PCDATA' S? ')'
260 ;; [VC: Proper Group/PE Nesting]
261 ;; [VC: No Duplicate Types]
262 ;;
263 ;;
264 ;; /* Attribute-list Declaration */
265 ;;
266 ;; AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
267 ;;
268 ;; AttDef ::= S Name S AttType S DefaultDecl
269 ;;
270 ;;
271 ;; /* Attribute Types */
272 ;;
273 ;; AttType ::= StringType | TokenizedType | EnumeratedType
274 ;;
275 ;; StringType ::= 'CDATA'
276 ;;
277 ;; TokenizedType ::= 'ID' [VC: ID]
278 ;; [VC: One ID per Element Type]
279 ;; [VC: ID Attribute Default]
280 ;; | 'IDREF' [VC: IDREF]
281 ;; | 'IDREFS' [VC: IDREF]
282 ;; | 'ENTITY' [VC: Entity Name]
283 ;; | 'ENTITIES' [VC: Entity Name]
284 ;; | 'NMTOKEN' [VC: Name Token]
285 ;; | 'NMTOKENS' [VC: Name Token]
286 ;;
287 ;;
288 ;; /* Enumerated Attribute Types */
289 ;;
290 ;; EnumeratedType ::= NotationType | Enumeration
291 ;;
292 ;; NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
293 ;; [VC: Notation Attributes]
294 ;; [VC: One Notation Per Element Type]
295 ;; [VC: No Notation on Empty Element]
296 ;; [VC: No Duplicate Tokens]
297 ;;
298 ;; Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
299 ;; [VC: Enumeration]
300 ;; [VC: No Duplicate Tokens]
301 ;;
302 ;;
303 ;; /* Attribute Defaults */
304 ;;
305 ;; DefaultDecl ::= '#REQUIRED' | '#IMPLIED'
306 ;; | (('#FIXED' S)? AttValue)
307 ;; [VC: Required Attribute]
308 ;; [VC: Attribute Default Value Syntactically Correct]
309 ;; [WFC: No < in Attribute Values]
310 ;; [VC: Fixed Attribute Default]
311 ;;
312 ;;
313 ;; /* Conditional Section */
314 ;;
315 ;; conditionalSect ::= includeSect | ignoreSect
316 ;;
317 ;; includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
318 ;; [VC: Proper Conditional Section/PE Nesting]
319 ;;
320 ;; ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
321 ;; [VC: Proper Conditional Section/PE Nesting]
322 ;;
323 ;; ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
324 ;;
325 ;; Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
326 ;;
327 ;;
328 ;; /* Character Reference */
329 ;;
330 ;; CharRef ::= '&#' [0-9]+ ';'
331 ;; | '&#x' [0-9a-fA-F]+ ';'
332 ;; [WFC: Legal Character]
333 ;;
334 ;;
335 ;; /* Entity Reference */
336 ;;
337 ;; Reference ::= EntityRef | CharRef
338 ;;
339 ;; EntityRef ::= '&' Name ';'
340 ;; [WFC: Entity Declared]
341 ;; [VC: Entity Declared]
342 ;; [WFC: Parsed Entity]
343 ;; [WFC: No Recursion]
344 ;;
345 ;; PEReference ::= '%' Name ';'
346 ;; [VC: Entity Declared]
347 ;; [WFC: No Recursion]
348 ;; [WFC: In DTD]
349 ;;
350 ;;
351 ;; /* Entity Declaration */
352 ;;
353 ;; EntityDecl ::= GEDecl | PEDecl
354 ;;
355 ;; GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
356 ;;
357 ;; PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
358 ;;
359 ;; EntityDef ::= EntityValue | (ExternalID NDataDecl?)
360 ;;
361 ;; PEDef ::= EntityValue | ExternalID
362 ;;
363 ;;
364 ;; /* External Entity Declaration */
365 ;;
366 ;; ExternalID ::= 'SYSTEM' S SystemLiteral
367 ;; | 'PUBLIC' S PubidLiteral S SystemLiteral
368 ;;
369 ;; NDataDecl ::= S 'NDATA' S Name
370 ;; [VC: Notation Declared]
371 ;;
372 ;;
373 ;; /* Text Declaration */
374 ;;
375 ;; TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
376 ;;
377 ;;
378 ;; /* Well-Formed External Parsed Entity */
379 ;;
380 ;; extParsedEnt ::= TextDecl? content
381 ;;
382 ;;
383 ;; /* Encoding Declaration */
384 ;;
385 ;; EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
386 ;;
387 ;; EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
388 ;; /* Encoding name contains only Latin characters */
389 ;;
390 ;;
391 ;; /* Notation Declarations */
392 ;;
393 ;; NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
394 ;; [VC: Unique Notation Name]
395 ;;
396 ;; PublicID ::= 'PUBLIC' S PubidLiteral
397 ;;
398 ;;
399 ;; /* Characters */
400 ;;
401 ;; Letter ::= BaseChar | Ideographic
402 ;;
403 ;; BaseChar ::= [#x0041-#x005A] | [#x0061-#x007A] | [#x00C0-#x00D6]
404 ;; | [#x00D8-#x00F6] | [#x00F8-#x00FF] | [#x0100-#x0131]
405 ;; | [#x0134-#x013E] | [#x0141-#x0148] | [#x014A-#x017E]
406 ;; | [#x0180-#x01C3] | [#x01CD-#x01F0] | [#x01F4-#x01F5]
407 ;; | [#x01FA-#x0217] | [#x0250-#x02A8] | [#x02BB-#x02C1]
408 ;; | #x0386 | [#x0388-#x038A] | #x038C
409 ;; | [#x038E-#x03A1] | [#x03A3-#x03CE] | [#x03D0-#x03D6]
410 ;; | #x03DA | #x03DC | #x03DE
411 ;; | #x03E0 | [#x03E2-#x03F3] | [#x0401-#x040C]
412 ;; | [#x040E-#x044F] | [#x0451-#x045C] | [#x045E-#x0481]
413 ;; | [#x0490-#x04C4] | [#x04C7-#x04C8] | [#x04CB-#x04CC]
414 ;; | [#x04D0-#x04EB] | [#x04EE-#x04F5] | [#x04F8-#x04F9]
415 ;; | [#x0531-#x0556] | #x0559 | [#x0561-#x0586]
416 ;; | [#x05D0-#x05EA] | [#x05F0-#x05F2] | [#x0621-#x063A]
417 ;; | [#x0641-#x064A] | [#x0671-#x06B7] | [#x06BA-#x06BE]
418 ;; | [#x06C0-#x06CE] | [#x06D0-#x06D3] | #x06D5
419 ;; | [#x06E5-#x06E6] | [#x0905-#x0939] | #x093D
420 ;; | [#x0958-#x0961] | [#x0985-#x098C] | [#x098F-#x0990]
421 ;; | [#x0993-#x09A8] | [#x09AA-#x09B0] | #x09B2
422 ;; | [#x09B6-#x09B9] | [#x09DC-#x09DD] | [#x09DF-#x09E1]
423 ;; | [#x09F0-#x09F1] | [#x0A05-#x0A0A] | [#x0A0F-#x0A10]
424 ;; | [#x0A13-#x0A28] | [#x0A2A-#x0A30] | [#x0A32-#x0A33]
425 ;; | [#x0A35-#x0A36] | [#x0A38-#x0A39] | [#x0A59-#x0A5C]
426 ;; | #x0A5E | [#x0A72-#x0A74] | [#x0A85-#x0A8B]
427 ;; | #x0A8D | [#x0A8F-#x0A91] | [#x0A93-#x0AA8]
428 ;; | [#x0AAA-#x0AB0] | [#x0AB2-#x0AB3] | [#x0AB5-#x0AB9]
429 ;; | #x0ABD | #x0AE0 | [#x0B05-#x0B0C]
430 ;; | [#x0B0F-#x0B10] | [#x0B13-#x0B28] | [#x0B2A-#x0B30]
431 ;; | [#x0B32-#x0B33] | [#x0B36-#x0B39] | #x0B3D
432 ;; | [#x0B5C-#x0B5D] | [#x0B5F-#x0B61] | [#x0B85-#x0B8A]
433 ;; | [#x0B8E-#x0B90] | [#x0B92-#x0B95] | [#x0B99-#x0B9A]
434 ;; | #x0B9C | [#x0B9E-#x0B9F] | [#x0BA3-#x0BA4]
435 ;; | [#x0BA8-#x0BAA] | [#x0BAE-#x0BB5] | [#x0BB7-#x0BB9]
436 ;; | [#x0C05-#x0C0C] | [#x0C0E-#x0C10] | [#x0C12-#x0C28]
437 ;; | [#x0C2A-#x0C33] | [#x0C35-#x0C39] | [#x0C60-#x0C61]
438 ;; | [#x0C85-#x0C8C] | [#x0C8E-#x0C90] | [#x0C92-#x0CA8]
439 ;; | [#x0CAA-#x0CB3] | [#x0CB5-#x0CB9] | #x0CDE
440 ;; | [#x0CE0-#x0CE1] | [#x0D05-#x0D0C] | [#x0D0E-#x0D10]
441 ;; | [#x0D12-#x0D28] | [#x0D2A-#x0D39] | [#x0D60-#x0D61]
442 ;; | [#x0E01-#x0E2E] | #x0E30 | [#x0E32-#x0E33]
443 ;; | [#x0E40-#x0E45] | [#x0E81-#x0E82] | #x0E84
444 ;; | [#x0E87-#x0E88] | #x0E8A | #x0E8D
445 ;; | [#x0E94-#x0E97] | [#x0E99-#x0E9F] | [#x0EA1-#x0EA3]
446 ;; | #x0EA5 | #x0EA7 | [#x0EAA-#x0EAB]
447 ;; | [#x0EAD-#x0EAE] | #x0EB0 | [#x0EB2-#x0EB3]
448 ;; | #x0EBD | [#x0EC0-#x0EC4] | [#x0F40-#x0F47]
449 ;; | [#x0F49-#x0F69] | [#x10A0-#x10C5] | [#x10D0-#x10F6]
450 ;; | #x1100 | [#x1102-#x1103] | [#x1105-#x1107]
451 ;; | #x1109 | [#x110B-#x110C] | [#x110E-#x1112]
452 ;; | #x113C | #x113E | #x1140
453 ;; | #x114C | #x114E | #x1150
454 ;; | [#x1154-#x1155] | #x1159 | [#x115F-#x1161]
455 ;; | #x1163 | #x1165 | #x1167
456 ;; | #x1169 | [#x116D-#x116E] | [#x1172-#x1173]
457 ;; | #x1175 | #x119E | #x11A8
458 ;; | #x11AB | [#x11AE-#x11AF] | [#x11B7-#x11B8]
459 ;; | #x11BA | [#x11BC-#x11C2] | #x11EB
460 ;; | #x11F0 | #x11F9 | [#x1E00-#x1E9B]
461 ;; | [#x1EA0-#x1EF9] | [#x1F00-#x1F15] | [#x1F18-#x1F1D]
462 ;; | [#x1F20-#x1F45] | [#x1F48-#x1F4D] | [#x1F50-#x1F57]
463 ;; | #x1F59 | #x1F5B | #x1F5D
464 ;; | [#x1F5F-#x1F7D] | [#x1F80-#x1FB4] | [#x1FB6-#x1FBC]
465 ;; | #x1FBE | [#x1FC2-#x1FC4] | [#x1FC6-#x1FCC]
466 ;; | [#x1FD0-#x1FD3] | [#x1FD6-#x1FDB] | [#x1FE0-#x1FEC]
467 ;; | [#x1FF2-#x1FF4] | [#x1FF6-#x1FFC] | #x2126
468 ;; | [#x212A-#x212B] | #x212E | [#x2180-#x2182]
469 ;; | [#x3041-#x3094] | [#x30A1-#x30FA] | [#x3105-#x312C]
470 ;; | [#xAC00-#xD7A3]
471 ;;
472 ;; Ideographic ::= [#x4E00-#x9FA5] | #x3007 | [#x3021-#x3029]
473 ;;
474 ;; CombiningChar ::= [#x0300-#x0345] | [#x0360-#x0361] | [#x0483-#x0486]
475 ;; | [#x0591-#x05A1] | [#x05A3-#x05B9] | [#x05BB-#x05BD]
476 ;; | #x05BF | [#x05C1-#x05C2] | #x05C4
477 ;; | [#x064B-#x0652] | #x0670 | [#x06D6-#x06DC]
478 ;; | [#x06DD-#x06DF] | [#x06E0-#x06E4] | [#x06E7-#x06E8]
479 ;; | [#x06EA-#x06ED] | [#x0901-#x0903] | #x093C
480 ;; | [#x093E-#x094C] | #x094D | [#x0951-#x0954]
481 ;; | [#x0962-#x0963] | [#x0981-#x0983] | #x09BC
482 ;; | #x09BE | #x09BF | [#x09C0-#x09C4]
483 ;; | [#x09C7-#x09C8] | [#x09CB-#x09CD] | #x09D7
484 ;; | [#x09E2-#x09E3] | #x0A02 | #x0A3C
485 ;; | #x0A3E | #x0A3F | [#x0A40-#x0A42]
486 ;; | [#x0A47-#x0A48] | [#x0A4B-#x0A4D] | [#x0A70-#x0A71]
487 ;; | [#x0A81-#x0A83] | #x0ABC | [#x0ABE-#x0AC5]
488 ;; | [#x0AC7-#x0AC9] | [#x0ACB-#x0ACD] | [#x0B01-#x0B03]
489 ;; | #x0B3C | [#x0B3E-#x0B43] | [#x0B47-#x0B48]
490 ;; | [#x0B4B-#x0B4D] | [#x0B56-#x0B57] | [#x0B82-#x0B83]
491 ;; | [#x0BBE-#x0BC2] | [#x0BC6-#x0BC8] | [#x0BCA-#x0BCD]
492 ;; | #x0BD7 | [#x0C01-#x0C03] | [#x0C3E-#x0C44]
493 ;; | [#x0C46-#x0C48] | [#x0C4A-#x0C4D] | [#x0C55-#x0C56]
494 ;; | [#x0C82-#x0C83] | [#x0CBE-#x0CC4] | [#x0CC6-#x0CC8]
495 ;; | [#x0CCA-#x0CCD] | [#x0CD5-#x0CD6] | [#x0D02-#x0D03]
496 ;; | [#x0D3E-#x0D43] | [#x0D46-#x0D48] | [#x0D4A-#x0D4D]
497 ;; | #x0D57 | #x0E31 | [#x0E34-#x0E3A]
498 ;; | [#x0E47-#x0E4E] | #x0EB1 | [#x0EB4-#x0EB9]
499 ;; | [#x0EBB-#x0EBC] | [#x0EC8-#x0ECD] | [#x0F18-#x0F19]
500 ;; | #x0F35 | #x0F37 | #x0F39
501 ;; | #x0F3E | #x0F3F | [#x0F71-#x0F84]
502 ;; | [#x0F86-#x0F8B] | [#x0F90-#x0F95] | #x0F97
503 ;; | [#x0F99-#x0FAD] | [#x0FB1-#x0FB7] | #x0FB9
504 ;; | [#x20D0-#x20DC] | #x20E1 | [#x302A-#x302F]
505 ;; | #x3099 | #x309A
506 ;;
507 ;; Digit ::= [#x0030-#x0039] | [#x0660-#x0669] | [#x06F0-#x06F9]
508 ;; | [#x0966-#x096F] | [#x09E6-#x09EF] | [#x0A66-#x0A6F]
509 ;; | [#x0AE6-#x0AEF] | [#x0B66-#x0B6F] | [#x0BE7-#x0BEF]
510 ;; | [#x0C66-#x0C6F] | [#x0CE6-#x0CEF] | [#x0D66-#x0D6F]
511 ;; | [#x0E50-#x0E59] | [#x0ED0-#x0ED9] | [#x0F20-#x0F29]
512 ;;
513 ;; Extender ::= #x00B7 | #x02D0 | #x02D1 | #x0387 | #x0640 | #x0E46 | #x0EC6
514 ;; | #x3005 | [#x3031-#x3035] | [#x309D-#x309E] | [#x30FC-#x30FE]
515 ;;
516 ;;
517 ;; NOTES
518 ;; -----
519 ;;
520 ;; At moment, only the `<!ELEMENT' generates a syntactic chart. The
521 ;; `<!ATTLIST', `<!NOTATION' and `<!ENTITY' are syntacticly checked but they
522 ;; don't generate a syntactic chart.
523 ;;
524 ;; Besides the syntax above, ebnf-dtd also accepts a `pure' dtd file. An
525 ;; example of a `pure' dtd file is:
526 ;;
527 ;; <?xml version="1.0" encoding="UTF-8"?>
528 ;; <!--
529 ;; The main element.
530 ;; -->
531 ;; <!ELEMENT workflow (registers?, trigger-functions?, initial-actions,
532 ;; steps, splits?, joins?)>
533 ;; <!--
534 ;; An action that can be executed (id must be unique among actions for
535 ;; the enclosing step).
536 ;; Used in: actions
537 ;; -->
538 ;; <!ELEMENT action (restrict-to, validators?, pre-functions?, results,
539 ;; post-functions?)>
540 ;; <!ATTLIST action
541 ;; id CDATA #REQUIRED
542 ;; name CDATA #REQUIRED
543 ;; >
544 ;;
545 ;;
546 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
547
548 ;;; Code:
549
550
551 (require 'ebnf-otz)
552
553
554 (defvar ebnf-dtd-lex nil
555 "Value returned by `ebnf-dtd-lex' function.")
556
557 \f
558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
559 ;; Syntactic analyzer
560
561
562 ;;; document ::= prolog element Misc*
563 ;;; /* Note that *only* the prolog will be parsed */
564
565 (defun ebnf-dtd-parser (start)
566 "DTD parser."
567 (let ((total (+ (- ebnf-limit start) 1))
568 (bias (1- start))
569 (origin (point))
570 rule-list token rule the-end)
571 (goto-char start)
572 (setq token (ebnf-dtd-lex))
573 (and (eq token 'end-of-input)
574 (error "Empty DTD file"))
575 (setq token (ebnf-dtd-prolog token))
576 (unless (eq (car token) 'end-prolog)
577 (setq the-end (cdr token)
578 token (car token))
579 (while (not (eq token the-end))
580 (ebnf-message-float
581 "Parsing...%s%%"
582 (/ (* (- (point) bias) 100.0) total))
583 (setq token (ebnf-dtd-intsubset token)
584 rule (cdr token)
585 token (car token))
586 (or (null rule)
587 (ebnf-add-empty-rule-list rule)
588 (setq rule-list (cons rule rule-list))))
589 (or (eq the-end 'end-of-input)
590 (eq (ebnf-dtd-lex) 'end-decl)
591 (error "Missing end of DOCTYPE"))
592 ;; adjust message, 'cause *only* prolog will be parsed
593 (ebnf-message-float "Parsing...%s%%" 100.0))
594 (goto-char origin)
595 rule-list))
596
597
598 ;;; prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
599 ;;;
600 ;;; XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
601 ;;;
602 ;;; VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
603 ;;;
604 ;;; Eq ::= S? '=' S?
605 ;;;
606 ;;; VersionNum ::= '1.0'
607 ;;;
608 ;;; Misc ::= Comment | PI | S
609 ;;;
610 ;;; EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
611 ;;;
612 ;;; EncName ::= [A-Za-z] ([-A-Za-z0-9._])*
613 ;;; /* Encoding name contains only Latin characters */
614 ;;;
615 ;;; SDDecl ::= S 'standalone' Eq
616 ;;; (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
617 ;;;
618 ;;; doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
619 ;;; ('[' intSubset ']' S?)? '>'
620
621
622 (defun ebnf-dtd-prolog (token)
623 (when (and (eq token 'begin-pi) (string= ebnf-dtd-lex "xml"))
624 ;; version = "1.0"
625 (setq token (ebnf-dtd-attribute (ebnf-dtd-lex) 'version-attr
626 "^1\\.0$" "XML version"))
627 ;; ( encoding = "encoding name" )?
628 (setq token (ebnf-dtd-attribute-optional
629 token 'encoding-attr
630 "^[A-Za-z][-A-Za-z0-9._]*$" "XML encoding"))
631 ;; ( standalone = ( "yes" | "no" ) )?
632 (setq token (ebnf-dtd-attribute-optional
633 token 'standalone-attr
634 "^yes|no$" "XML standalone"))
635 (or (eq token 'end-pi)
636 (error "Missing end of XML processing instruction")))
637 ;; processing instructions
638 (setq token (ebnf-dtd-pi (ebnf-dtd-lex)))
639 (cond
640 ;; DOCTYPE
641 ((eq token 'doctype-decl)
642 (or (eq (ebnf-dtd-lex) 'name)
643 (error "Document type name is missing"))
644 (cons (if (eq (ebnf-dtd-externalid) 'begin-subset)
645 (ebnf-dtd-lex)
646 'end-prolog)
647 'end-subset))
648 ((memq token '(element-decl attlist-decl entity-decl notation-decl))
649 (cons token 'end-of-input))
650 (t
651 '(end-prolog . end-subset))
652 ))
653
654
655 (defun ebnf-dtd-attribute (token attr match attr-name)
656 (or (eq token attr)
657 (error "%s attribute is missing" attr-name))
658 (ebnf-dtd-attribute-optional token attr match attr-name))
659
660
661 (defun ebnf-dtd-attribute-optional (token attr match attr-name)
662 (when (eq token attr)
663 (or (and (eq (ebnf-dtd-lex) 'equal)
664 (eq (ebnf-dtd-lex) 'string)
665 (string-match match ebnf-dtd-lex))
666 (error "XML %s attribute is invalid" attr-name))
667 (setq token (ebnf-dtd-lex)))
668 token)
669
670
671 ;;; ExternalID ::= 'SYSTEM' S SystemLiteral
672 ;;; | 'PUBLIC' S PubidLiteral S SystemLiteral
673
674
675 (defun ebnf-dtd-externalid (&optional token)
676 (let ((must-have token))
677 (or token (setq token (ebnf-dtd-lex)))
678 (cond ((eq token 'system)
679 (ebnf-dtd-systemliteral))
680 ((eq token 'public)
681 (ebnf-dtd-pubidliteral)
682 (ebnf-dtd-systemliteral))
683 (must-have
684 (error "Missing `SYSTEM' or `PUBLIC' in external id"))
685 (t
686 token))))
687
688
689 ;;; SystemLiteral ::= ('"' [^"]* '"')
690 ;;; | ("'" [^']* "'")
691
692
693 (defun ebnf-dtd-systemliteral ()
694 (or (eq (ebnf-dtd-lex) 'string)
695 (error "System identifier is invalid"))
696 (ebnf-dtd-lex))
697
698
699 ;;; PubidLiteral ::= '"' PubidChar* '"'
700 ;;; | "'" (PubidChar - "'")* "'"
701 ;;;
702 ;;; PubidChar ::= [-'()+,./:=?;!*#@$_%\n\r a-zA-Z0-9]
703
704
705 (defun ebnf-dtd-pubidliteral ()
706 (or (and (eq (ebnf-dtd-lex) 'string)
707 (string-match "^[-'()+,./:=?;!*#@$_%\n\r a-zA-Z0-9]*$"
708 ebnf-dtd-lex))
709 (error "Public identifier is invalid")))
710
711
712 ;;; PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
713 ;;;
714 ;;; PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
715
716
717 (defun ebnf-dtd-pi (token)
718 (while (eq token 'begin-pi)
719 (and (string-match "^[xX][mM][lL]$" ebnf-dtd-lex)
720 (error "Processing instruction name can not be `XML'"))
721 (while (not (eq (ebnf-dtd-lex) 'end-pi)))
722 (setq token (ebnf-dtd-lex)))
723 token)
724
725
726 ;;; doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
727 ;;; ('[' intSubset ']' S?)? '>'
728 ;;;
729 ;;; intSubset ::= (markupdecl | DeclSep)*
730 ;;;
731 ;;; DeclSep ::= PEReference | S
732 ;;;
733 ;;; markupdecl ::= elementdecl | AttlistDecl | EntityDecl
734 ;;; | NotationDecl | PI | Comment
735
736
737 (defun ebnf-dtd-intsubset (token)
738 ;; PI - Processing Instruction
739 (and (eq token 'begin-pi)
740 (setq token (ebnf-dtd-pi token)))
741 (cond
742 ((memq token '(end-subset end-of-input))
743 (cons token nil))
744 ((eq token 'pe-ref)
745 (cons (ebnf-dtd-lex) nil)) ; annotation
746 ((eq token 'element-decl)
747 (ebnf-dtd-elementdecl)) ; rule
748 ((eq token 'attlist-decl)
749 (ebnf-dtd-attlistdecl)) ; annotation
750 ((eq token 'entity-decl)
751 (ebnf-dtd-entitydecl)) ; annotation
752 ((eq token 'notation-decl)
753 (ebnf-dtd-notationdecl)) ; annotation
754 (t
755 (error "Invalid DOCTYPE element"))
756 ))
757
758
759 ;;; elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
760 ;;;
761 ;;; contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
762 ;;;
763 ;;; Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*'
764 ;;; | '(' S? '#PCDATA' S? ')'
765 ;;;
766 ;;; children ::= (choice | seq) ('?' | '*' | '+')?
767 ;;;
768 ;;; choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
769 ;;;
770 ;;; seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
771 ;;;
772 ;;; cp ::= (Name | choice | seq) ('?' | '*' | '+')?
773
774
775 (defun ebnf-dtd-elementdecl ()
776 (let ((action ebnf-action)
777 name token body)
778 (setq ebnf-action nil)
779 (or (eq (ebnf-dtd-lex) 'name)
780 (error "Invalid ELEMENT name"))
781 (setq name ebnf-dtd-lex
782 token (ebnf-dtd-lex)
783 body (cond ((memq token '(empty any))
784 (let ((term (ebnf-make-terminal ebnf-dtd-lex)))
785 (cons (ebnf-dtd-lex) term)))
786 ((eq token 'begin-group)
787 (setq token (ebnf-dtd-lex))
788 (if (eq token 'pcdata)
789 (ebnf-dtd-mixed)
790 (ebnf-dtd-children token)))
791 (t
792 (error "Invalid ELEMENT content"))
793 ))
794 (or (eq (car body) 'end-decl)
795 (error "Missing `>' in ELEMENT declaration"))
796 (ebnf-eps-add-production name)
797 (cons (ebnf-dtd-lex)
798 (ebnf-make-production name (cdr body) action))))
799
800
801 ;;; Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*'
802 ;;; | '(' S? '#PCDATA' S? ')'
803
804
805 (defun ebnf-dtd-mixed ()
806 (let* ((alt (cons (ebnf-make-terminal ebnf-dtd-lex) nil))
807 (token (ebnf-dtd-lex))
808 (has-alternative (eq token 'alternative)))
809 (while (eq token 'alternative)
810 (or (eq (ebnf-dtd-lex) 'name)
811 (error "Invalid name"))
812 (setq alt (cons ebnf-dtd-lex alt)
813 token (ebnf-dtd-lex)))
814 (or (eq token 'end-group)
815 (error "Missing `)'"))
816 (and has-alternative
817 (or (eq (ebnf-dtd-lex) 'zero-or-more)
818 (error "Missing `*'")))
819 (ebnf-token-alternative alt (cons (ebnf-dtd-lex) nil))))
820
821
822 ;;; children ::= (choice | seq) ('?' | '*' | '+')?
823
824
825 (defun ebnf-dtd-children (token)
826 (ebnf-dtd-operators (ebnf-dtd-choice-seq token)))
827
828
829 ;;; choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
830 ;;;
831 ;;; seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
832
833
834 (defun ebnf-dtd-choice-seq (token)
835 (setq token (ebnf-dtd-cp token))
836 (let (elist)
837 (cond
838 ;; choice
839 ((eq (car token) 'alternative)
840 (while (eq (car token) 'alternative)
841 (setq elist (cons (cdr token) elist)
842 token (ebnf-dtd-cp (ebnf-dtd-lex))))
843 (setq elist (ebnf-token-alternative elist token)))
844 ;; seq
845 ((eq (car token) 'comma)
846 (while (eq (car token) 'comma)
847 (setq elist (cons (cdr token) elist)
848 token (ebnf-dtd-cp (ebnf-dtd-lex))))
849 (setq elist (ebnf-token-sequence (cons (cdr token) elist))))
850 ;; only one element
851 (t
852 (setq elist (cdr token))))
853 (or (eq (car token) 'end-group)
854 (error "Missing `)' in ELEMENT content"))
855 elist))
856
857
858 ;;; cp ::= (Name | choice | seq) ('?' | '*' | '+')?
859
860
861 (defun ebnf-dtd-cp (token)
862 (ebnf-dtd-operators (cond ((eq token 'name)
863 (ebnf-make-terminal ebnf-dtd-lex))
864 ((eq token 'begin-group)
865 (ebnf-dtd-choice-seq (ebnf-dtd-lex)))
866 (t
867 (error "Invalid element"))
868 )))
869
870
871 ;;; elm ('?' | '*' | '+')?
872
873
874 (defun ebnf-dtd-operators (elm)
875 (let ((token (ebnf-dtd-lex)))
876 (cond ((eq token 'optional) ; ? - optional
877 (cons (ebnf-dtd-lex) (ebnf-token-optional elm)))
878 ((eq token 'zero-or-more) ; * - zero or more
879 (cons (ebnf-dtd-lex) (ebnf-make-zero-or-more elm)))
880 ((eq token 'one-or-more) ; + - one or more
881 (cons (ebnf-dtd-lex) (ebnf-make-one-or-more elm)))
882 (t ; only element
883 (cons token elm))
884 )))
885
886
887 ;;; AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
888 ;;;
889 ;;; AttDef ::= S Name S AttType S DefaultDecl
890 ;;;
891 ;;; AttType ::= StringType | TokenizedType | EnumeratedType
892 ;;;
893 ;;; StringType ::= 'CDATA'
894 ;;;
895 ;;; TokenizedType ::= 'ID'
896 ;;; | 'IDREF'
897 ;;; | 'IDREFS'
898 ;;; | 'ENTITY'
899 ;;; | 'ENTITIES'
900 ;;; | 'NMTOKEN'
901 ;;; | 'NMTOKENS'
902 ;;;
903 ;;; EnumeratedType ::= NotationType | Enumeration
904 ;;;
905 ;;; NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
906 ;;;
907 ;;; Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
908 ;;;
909 ;;; DefaultDecl ::= '#REQUIRED'
910 ;;; | '#IMPLIED'
911 ;;; | (('#FIXED' S)? AttValue)
912 ;;;
913 ;;;
914 ;;; AttValue ::= '"' ([^<&"] | Reference)* '"'
915 ;;; | "'" ([^<&'] | Reference)* "'"
916 ;;;
917 ;;; Reference ::= EntityRef | CharRef
918 ;;;
919 ;;; EntityRef ::= '&' Name ';'
920 ;;;
921 ;;; CharRef ::= '&#' [0-9]+ ';'
922 ;;; | '&#x' [0-9a-fA-F]+ ';'
923
924 ;;; "^\\(&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^<&]\\)*$"
925
926
927 (defun ebnf-dtd-attlistdecl ()
928 (or (eq (ebnf-dtd-lex) 'name)
929 (error "Invalid ATTLIST name"))
930 (let (token)
931 (while (eq (setq token (ebnf-dtd-lex)) 'name)
932 ;; type
933 (setq token (ebnf-dtd-lex))
934 (cond
935 ((eq token 'notation)
936 (or (eq (ebnf-dtd-lex) 'begin-group)
937 (error "Missing `(' in NOTATION type in ATTLIST declaration"))
938 (ebnf-dtd-namelist "NOTATION" '(name)))
939 ((eq token 'begin-group)
940 (ebnf-dtd-namelist "enumeration" '(name name-char)))
941 ((memq token
942 '(cdata id idref idrefs entity entities nmtoken nmtokens)))
943 (t
944 (error "Invalid type in ATTLIST declaration")))
945 ;; default value
946 (setq token (ebnf-dtd-lex))
947 (unless (memq token '(required implied))
948 (and (eq token 'fixed)
949 (setq token (ebnf-dtd-lex)))
950 (or (and (eq token 'string)
951 (string-match
952 "^\\(&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^<&]\\)*$"
953 ebnf-dtd-lex))
954 (error "Invalid default value in ATTLIST declaration"))))
955 (or (eq token 'end-decl)
956 (error "Missing `>' in end of ATTLIST"))
957 (cons (ebnf-dtd-lex) nil)))
958
959
960 (defun ebnf-dtd-namelist (type name-list)
961 (let (token)
962 (while (progn
963 (or (memq (ebnf-dtd-lex) name-list)
964 (error "Invalid name in %s type in ATTLIST declaration" type))
965 (eq (setq token (ebnf-dtd-lex)) 'alternative)))
966 (or (eq token 'end-group)
967 (error "Missing `)' in %s type in ATTLIST declaration" type))))
968
969
970 ;;; EntityDecl ::= GEDecl | PEDecl
971 ;;;
972 ;;; GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
973 ;;;
974 ;;; PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
975 ;;;
976 ;;; EntityDef ::= EntityValue | (ExternalID NDataDecl?)
977 ;;;
978 ;;; PEDef ::= EntityValue | ExternalID
979 ;;;
980 ;;; NDataDecl ::= S 'NDATA' S Name
981 ;;;
982 ;;;
983 ;;; EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
984 ;;; | "'" ([^%&'] | PEReference | Reference)* "'"
985 ;;;
986 ;;; PEReference ::= '%' Name ';'
987 ;;;
988 ;;; Reference ::= EntityRef | CharRef
989 ;;;
990 ;;; EntityRef ::= '&' Name ';'
991 ;;;
992 ;;; CharRef ::= '&#' [0-9]+ ';'
993 ;;; | '&#x' [0-9a-fA-F]+ ';'
994
995 ;;; "^\\(%[A-Za-z_:][-A-Za-z0-9._:]*;\\|&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^%&]\\)*$"
996
997
998 (defun ebnf-dtd-entitydecl ()
999 (let* ((token (ebnf-dtd-lex))
1000 (pedecl (eq token 'percent)))
1001 (and pedecl
1002 (setq token (ebnf-dtd-lex)))
1003 (or (eq token 'name)
1004 (error "Invalid name of ENTITY"))
1005 (setq token (ebnf-dtd-lex))
1006 (if (eq token 'string)
1007 (if (string-match
1008 "^\\(%[A-Za-z_:][-A-Za-z0-9._:]*;\\|&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^%&]\\)*$"
1009 ebnf-dtd-lex)
1010 (setq token (ebnf-dtd-lex))
1011 (error "Invalid ENTITY definition"))
1012 (setq token (ebnf-dtd-externalid token))
1013 (when (and (not pedecl) (eq token 'ndata))
1014 (or (eq (ebnf-dtd-lex) 'name)
1015 (error "Invalid NDATA name"))
1016 (setq token (ebnf-dtd-lex))))
1017 (or (eq token 'end-decl)
1018 (error "Missing `>' in end of ENTITY"))
1019 (cons (ebnf-dtd-lex) nil)))
1020
1021
1022 ;;; NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
1023 ;;;
1024 ;;; PublicID ::= 'PUBLIC' S PubidLiteral
1025
1026
1027 (defun ebnf-dtd-notationdecl ()
1028 (or (eq (ebnf-dtd-lex) 'name)
1029 (error "Invalid name NOTATION"))
1030 (or (eq (ebnf-dtd-externalid-or-publicid) 'end-decl)
1031 (error "Missing `>' in end of NOTATION"))
1032 (cons (ebnf-dtd-lex) nil))
1033
1034
1035 ;;; ExternalID ::= 'SYSTEM' S SystemLiteral
1036 ;;; | 'PUBLIC' S PubidLiteral S SystemLiteral
1037 ;;;
1038 ;;; PublicID ::= 'PUBLIC' S PubidLiteral
1039
1040
1041 (defun ebnf-dtd-externalid-or-publicid ()
1042 (let ((token (ebnf-dtd-lex)))
1043 (cond ((eq token 'system)
1044 (ebnf-dtd-systemliteral))
1045 ((eq token 'public)
1046 (ebnf-dtd-pubidliteral)
1047 (and (eq (setq token (ebnf-dtd-lex)) 'string)
1048 (setq token (ebnf-dtd-lex)))
1049 token)
1050 (t
1051 (error "Missing `SYSTEM' or `PUBLIC'")))))
1052
1053 \f
1054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1055 ;; Lexical analyzer
1056
1057
1058 (defconst ebnf-dtd-token-table (make-vector 256 'error)
1059 "Vector used to map characters to a lexical token.")
1060
1061
1062 (defun ebnf-dtd-initialize ()
1063 "Initialize EBNF token table."
1064 ;; control character & control 8-bit character are set to `error'
1065 (let ((char ?\060))
1066 ;; digits: 0-9
1067 (while (< char ?\072)
1068 (aset ebnf-dtd-token-table char 'name-char)
1069 (setq char (1+ char)))
1070 ;; printable character: A-Z
1071 (setq char ?\101)
1072 (while (< char ?\133)
1073 (aset ebnf-dtd-token-table char 'name)
1074 (setq char (1+ char)))
1075 ;; printable character: a-z
1076 (setq char ?\141)
1077 (while (< char ?\173)
1078 (aset ebnf-dtd-token-table char 'name)
1079 (setq char (1+ char)))
1080 ;; European 8-bit accentuated characters:
1081 (setq char ?\240)
1082 (while (< char ?\400)
1083 (aset ebnf-dtd-token-table char 'name)
1084 (setq char (1+ char)))
1085 ;; Override name characters:
1086 (aset ebnf-dtd-token-table ?_ 'name)
1087 (aset ebnf-dtd-token-table ?: 'name)
1088 (aset ebnf-dtd-token-table ?. 'name-char)
1089 (aset ebnf-dtd-token-table ?- 'name-char)
1090 ;; Override space characters:
1091 (aset ebnf-dtd-token-table ?\n 'space) ; [NL] linefeed
1092 (aset ebnf-dtd-token-table ?\r 'space) ; [CR] carriage return
1093 (aset ebnf-dtd-token-table ?\t 'space) ; [HT] horizontal tab
1094 (aset ebnf-dtd-token-table ?\ 'space) ; [SP] space
1095 ;; Override other lexical characters:
1096 (aset ebnf-dtd-token-table ?= 'equal)
1097 (aset ebnf-dtd-token-table ?, 'comma)
1098 (aset ebnf-dtd-token-table ?* 'zero-or-more)
1099 (aset ebnf-dtd-token-table ?+ 'one-or-more)
1100 (aset ebnf-dtd-token-table ?| 'alternative)
1101 (aset ebnf-dtd-token-table ?% 'percent)
1102 (aset ebnf-dtd-token-table ?& 'ampersand)
1103 (aset ebnf-dtd-token-table ?# 'hash)
1104 (aset ebnf-dtd-token-table ?\? 'interrogation)
1105 (aset ebnf-dtd-token-table ?\" 'double-quote)
1106 (aset ebnf-dtd-token-table ?\' 'single-quote)
1107 (aset ebnf-dtd-token-table ?< 'less-than)
1108 (aset ebnf-dtd-token-table ?> 'end-decl)
1109 (aset ebnf-dtd-token-table ?\( 'begin-group)
1110 (aset ebnf-dtd-token-table ?\) 'end-group)
1111 (aset ebnf-dtd-token-table ?\[ 'begin-subset)
1112 (aset ebnf-dtd-token-table ?\] 'end-subset)))
1113
1114
1115 ;; replace the range "\240-\377" (see `ebnf-range-regexp').
1116 (defconst ebnf-dtd-name-chars
1117 (ebnf-range-regexp "-._:0-9A-Za-z" ?\240 ?\377))
1118
1119
1120 (defconst ebnf-dtd-decl-alist
1121 '(("ATTLIST" . attlist-decl)
1122 ("DOCTYPE" . doctype-decl)
1123 ("ELEMENT" . element-decl)
1124 ("ENTITY" . entity-decl)
1125 ("NOTATION" . notation-decl)))
1126
1127
1128 (defconst ebnf-dtd-element-alist
1129 '(("#FIXED" . fixed)
1130 ("#IMPLIED" . implied)
1131 ("#PCDATA" . pcdata)
1132 ("#REQUIRED" . required)))
1133
1134
1135 (defconst ebnf-dtd-name-alist
1136 '(("ANY" . any)
1137 ("CDATA" . cdata)
1138 ("EMPTY" . empty)
1139 ("ENTITIES" . entities)
1140 ("ENTITY" . entity)
1141 ("ID" . id)
1142 ("IDREF" . idref)
1143 ("IDREFS" . idrefs)
1144 ("NDATA" . ndata)
1145 ("NMTOKEN" . nmtoken)
1146 ("NMTOKENS" . nmtokens)
1147 ("NOTATION" . notation)
1148 ("PUBLIC" . public)
1149 ("SYSTEM" . system)
1150 ("encoding" . encoding-attr)
1151 ("standalone" . standalone-attr)
1152 ("version" . version-attr)))
1153
1154
1155 (defun ebnf-dtd-lex ()
1156 "Lexical analyzer for DTD.
1157
1158 Return a lexical token.
1159
1160 See documentation for variable `ebnf-dtd-lex'."
1161 (if (>= (point) ebnf-limit)
1162 'end-of-input
1163 (let (token)
1164 ;; skip spaces and comments
1165 (while (if (> (following-char) 255)
1166 (progn
1167 (setq token 'error)
1168 nil)
1169 (setq token (aref ebnf-dtd-token-table (following-char)))
1170 (cond
1171 ((eq token 'space)
1172 (skip-chars-forward " \n\r\t" ebnf-limit)
1173 (< (point) ebnf-limit))
1174 ((and (eq token 'less-than)
1175 (looking-at "<!--"))
1176 (ebnf-dtd-skip-comment))
1177 (t nil)
1178 )))
1179 (cond
1180 ;; end of input
1181 ((>= (point) ebnf-limit)
1182 'end-of-input)
1183 ;; error
1184 ((eq token 'error)
1185 (error "Invalid character"))
1186 ;; beginning of declaration:
1187 ;; <?name, <!ATTLIST, <!DOCTYPE, <!ELEMENT, <!ENTITY, <!NOTATION
1188 ((eq token 'less-than)
1189 (forward-char)
1190 (let ((char (following-char)))
1191 (cond ((= char ?\?) ; <?
1192 (forward-char)
1193 (setq ebnf-dtd-lex (ebnf-buffer-substring ebnf-dtd-name-chars))
1194 'begin-pi)
1195 ((= char ?!) ; <!
1196 (forward-char)
1197 (let ((decl (ebnf-buffer-substring ebnf-dtd-name-chars)))
1198 (or (cdr (assoc decl ebnf-dtd-decl-alist))
1199 (error "Invalid declaration name `%s'" decl))))
1200 (t ; <x
1201 (error "Invalid declaration `<%c'" char)))))
1202 ;; name, namechar
1203 ((memq token '(name name-char))
1204 (setq ebnf-dtd-lex (ebnf-buffer-substring ebnf-dtd-name-chars))
1205 (or (cdr (assoc ebnf-dtd-lex ebnf-dtd-name-alist))
1206 token))
1207 ;; ?, ?>
1208 ((eq token 'interrogation)
1209 (forward-char)
1210 (if (/= (following-char) ?>)
1211 'optional
1212 (forward-char)
1213 'end-pi))
1214 ;; #FIXED, #IMPLIED, #PCDATA, #REQUIRED
1215 ((eq token 'hash)
1216 (forward-char)
1217 (setq ebnf-dtd-lex
1218 (concat "#" (ebnf-buffer-substring ebnf-dtd-name-chars)))
1219 (or (cdr (assoc ebnf-dtd-lex ebnf-dtd-element-alist))
1220 (error "Invalid element `%s'" ebnf-dtd-lex)))
1221 ;; "string"
1222 ((eq token 'double-quote)
1223 (setq ebnf-dtd-lex (ebnf-dtd-string ?\"))
1224 'string)
1225 ;; 'string'
1226 ((eq token 'single-quote)
1227 (setq ebnf-dtd-lex (ebnf-dtd-string ?\'))
1228 'string)
1229 ;; %, %name;
1230 ((eq token 'percent)
1231 (forward-char)
1232 (if (looking-at "[ \n\r\t]")
1233 'percent
1234 (setq ebnf-dtd-lex (ebnf-dtd-name-ref "%"))
1235 'pe-ref))
1236 ;; &#...;, &#x...;, &name;
1237 ((eq token 'ampersand)
1238 (forward-char)
1239 (if (/= (following-char) ?#)
1240 (progn
1241 ;; &name;
1242 (setq ebnf-dtd-lex (ebnf-dtd-name-ref "&"))
1243 'entity-ref)
1244 ;; &#...;, &#x...;
1245 (forward-char)
1246 (setq ebnf-dtd-lex (if (/= (following-char) ?x)
1247 (ebnf-dtd-char-ref "&#" "0-9")
1248 (forward-char)
1249 (ebnf-dtd-char-ref "&#x" "0-9a-fA-F")))
1250 'char-ref))
1251 ;; miscellaneous: (, ), [, ], =, |, *, +, >, `,'
1252 (t
1253 (forward-char)
1254 token)
1255 ))))
1256
1257
1258 (defun ebnf-dtd-name-ref (start)
1259 (ebnf-dtd-char-ref start ebnf-dtd-name-chars))
1260
1261
1262 (defun ebnf-dtd-char-ref (start chars)
1263 (let ((char (ebnf-buffer-substring chars)))
1264 (or (= (following-char) ?\;)
1265 (error "Invalid element `%s%s%c'" start char (following-char)))
1266 (forward-char)
1267 (format "%s%s;" start char)))
1268
1269
1270 ;; replace the range "\240-\377" (see `ebnf-range-regexp').
1271 (defconst ebnf-dtd-double-string-chars
1272 (ebnf-range-regexp "\t -!#-~" ?\240 ?\377))
1273 (defconst ebnf-dtd-single-string-chars
1274 (ebnf-range-regexp "\t -&(-~" ?\240 ?\377))
1275
1276
1277 (defun ebnf-dtd-string (delim)
1278 (buffer-substring-no-properties
1279 (progn
1280 (forward-char)
1281 (point))
1282 (progn
1283 (skip-chars-forward (if (= delim ?\")
1284 ebnf-dtd-double-string-chars
1285 ebnf-dtd-single-string-chars)
1286 ebnf-limit)
1287 (or (= (following-char) delim)
1288 (error "Missing string delimiter `%c'" delim))
1289 (prog1
1290 (point)
1291 (forward-char)))))
1292
1293
1294 ;; replace the range "\177-\237" (see `ebnf-range-regexp').
1295 (defconst ebnf-dtd-comment-chars
1296 (ebnf-range-regexp "^-\000-\010\013\014\016-\037" ?\177 ?\237))
1297 (defconst ebnf-dtd-filename-chars
1298 (ebnf-range-regexp "^-\000-\037" ?\177 ?\237))
1299
1300
1301 (defun ebnf-dtd-skip-comment ()
1302 (forward-char 4) ; <!--
1303 (cond
1304 ;; open EPS file
1305 ((and ebnf-eps-executing (= (following-char) ?\[))
1306 (ebnf-eps-add-context (ebnf-dtd-eps-filename)))
1307 ;; close EPS file
1308 ((and ebnf-eps-executing (= (following-char) ?\]))
1309 (ebnf-eps-remove-context (ebnf-dtd-eps-filename)))
1310 ;; any other action in comment
1311 (t
1312 (setq ebnf-action (aref ebnf-comment-table (following-char))))
1313 )
1314 (while (progn
1315 (skip-chars-forward ebnf-dtd-comment-chars ebnf-limit)
1316 (and (< (point) ebnf-limit)
1317 (not (looking-at "-->"))))
1318 (skip-chars-forward "-" ebnf-limit))
1319 ;; check for a valid end of comment
1320 (cond ((>= (point) ebnf-limit)
1321 nil)
1322 ((looking-at "-->")
1323 (forward-char 3)
1324 t)
1325 (t
1326 (error "Invalid character"))
1327 ))
1328
1329
1330 (defun ebnf-dtd-eps-filename ()
1331 (forward-char)
1332 (let (fname)
1333 (while (progn
1334 (setq fname
1335 (concat fname
1336 (ebnf-buffer-substring ebnf-dtd-filename-chars)))
1337 (and (< (point) ebnf-limit)
1338 (= (following-char) ?-) ; may be \n, \t, \r
1339 (not (looking-at "-->"))))
1340 (setq fname (concat fname (ebnf-buffer-substring "-"))))
1341 fname))
1342
1343 \f
1344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1345
1346
1347 (provide 'ebnf-dtd)
1348
1349 ;;; arch-tag: c21bb640-135f-4afa-8712-fa11d86301c4
1350 ;;; ebnf-dtd.el ends here