1 ;;; ebnf-dtd.el --- parser for DTD (Data Type Description for XML)
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8 ;; Keywords: wp, ebnf, PostScript
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; This is part of ebnf2ps package.
35 ;; This package defines a parser for DTD (Data Type Description for XML).
37 ;; See ebnf2ps.el for documentation.
44 ;; `http://www.w3.org/TR/2004/REC-xml-20040204/'
45 ;; (Extensible Markup Language (XML) 1.0 (Third Edition))
46 ;; `http://www.w3.org/TR/html40/'
47 ;; (HTML 4.01 Specification)
48 ;; `http://www.w3.org/TR/NOTE-html-970421'
49 ;; (HTML DTD with support for Style Sheets)
54 ;; document ::= prolog element Misc*
55 ;; /* Note that *only* the prolog will be parsed */
60 ;; Char ::= #x9 | #xA | #xD
61 ;; | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
62 ;; /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
66 ;; Document authors are encouraged to avoid "compatibility characters", as
67 ;; defined in section 6.8 of [Unicode] (see also D21 in section 3.6 of
68 ;; [Unicode3]). The characters defined in the following ranges are also
69 ;; discouraged. They are either control characters or permanently undefined
70 ;; Unicode characters:
72 ;; [#x7F-#x84], [#x86-#x9F], [#xFDD0-#xFDDF],
73 ;; [#1FFFE-#x1FFFF], [#2FFFE-#x2FFFF], [#3FFFE-#x3FFFF],
74 ;; [#4FFFE-#x4FFFF], [#5FFFE-#x5FFFF], [#6FFFE-#x6FFFF],
75 ;; [#7FFFE-#x7FFFF], [#8FFFE-#x8FFFF], [#9FFFE-#x9FFFF],
76 ;; [#AFFFE-#xAFFFF], [#BFFFE-#xBFFFF], [#CFFFE-#xCFFFF],
77 ;; [#DFFFE-#xDFFFF], [#EFFFE-#xEFFFF], [#FFFFE-#xFFFFF],
78 ;; [#10FFFE-#x10FFFF]. */
83 ;; S ::= (#x20 | #x9 | #xD | #xA)+
86 ;; /* Names and Tokens */
88 ;; NameChar ::= Letter | Digit | '.' | '-' | '_' | ':'
89 ;; | CombiningChar | Extender
91 ;; Name ::= (Letter | '_' | ':') (NameChar)*
93 ;; Names ::= Name (#x20 Name)*
95 ;; Nmtoken ::= (NameChar)+
97 ;; Nmtokens ::= Nmtoken (#x20 Nmtoken)*
102 ;; EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
103 ;; | "'" ([^%&'] | PEReference | Reference)* "'"
105 ;; AttValue ::= '"' ([^<&"] | Reference)* '"'
106 ;; | "'" ([^<&'] | Reference)* "'"
108 ;; SystemLiteral ::= ('"' [^"]* '"')
111 ;; PubidLiteral ::= '"' PubidChar* '"'
112 ;; | "'" (PubidChar - "'")* "'"
114 ;; PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
118 ;; Although the EntityValue production allows the definition of a general
119 ;; entity consisting of a single explicit < in the literal (e.g., <!ENTITY
120 ;; mylt "<">), it is strongly advised to avoid this practice since any
121 ;; reference to that entity will cause a well-formedness error. */
124 ;; /* Character Data */
126 ;; CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
131 ;; Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
134 ;; /* Processing Instructions */
136 ;; PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
138 ;; PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
141 ;; /* CDATA Sections */
143 ;; CDSect ::= CDStart CData CDEnd
145 ;; CDStart ::= '<![CDATA['
147 ;; CData ::= (Char* - (Char* ']]>' Char*))
154 ;; prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
156 ;; XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
158 ;; VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
162 ;; VersionNum ::= '1.0'
164 ;; Misc ::= Comment | PI | S
167 ;; /* Document Type Definition */
169 ;; doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
170 ;; ('[' intSubset ']' S?)? '>'
171 ;; [VC: Root Element Type]
172 ;; [WFC: External Subset]
174 ;; DeclSep ::= PEReference | S
175 ;; [WFC: PE Between Declarations]
177 ;; intSubset ::= (markupdecl | DeclSep)*
179 ;; markupdecl ::= elementdecl | AttlistDecl | EntityDecl
180 ;; | NotationDecl | PI | Comment
181 ;; [VC: Proper Declaration/PE Nesting]
182 ;; [WFC: PEs in Internal Subset]
185 ;; /* External Subset */
187 ;; extSubset ::= TextDecl? extSubsetDecl
189 ;; extSubsetDecl ::= ( markupdecl | conditionalSect | DeclSep)*
192 ;; /* Standalone Document Declaration */
194 ;; SDDecl ::= S 'standalone' Eq
195 ;; (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
196 ;; [VC: Standalone Document Declaration]
201 ;; element ::= EmptyElemTag | STag content ETag
202 ;; [WFC: Element Type Match]
203 ;; [VC: Element Valid]
208 ;; STag ::= '<' Name (S Attribute)* S? '>'
209 ;; [WFC: Unique Att Spec]
211 ;; Attribute ::= Name Eq AttValue
212 ;; [VC: Attribute Value Type]
213 ;; [WFC: No External Entity References]
214 ;; [WFC: No < in Attribute Values]
219 ;; ETag ::= '</' Name S? '>'
222 ;; /* Content of Elements */
224 ;; content ::= CharData?
225 ;; ((element | Reference | CDSect | PI | Comment) CharData?)*
228 ;; /* Tags for Empty Elements */
230 ;; EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
231 ;; [WFC: Unique Att Spec]
234 ;; /* Element Type Declaration */
236 ;; elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
237 ;; [VC: Unique Element Type Declaration]
239 ;; contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
242 ;; /* Element-content Models */
244 ;; children ::= (choice | seq) ('?' | '*' | '+')?
246 ;; cp ::= (Name | choice | seq) ('?' | '*' | '+')?
248 ;; choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
249 ;; [VC: Proper Group/PE Nesting]
251 ;; seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
252 ;; [VC: Proper Group/PE Nesting]
255 ;; /* Mixed-content Declaration */
257 ;; Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*'
258 ;; | '(' S? '#PCDATA' S? ')'
259 ;; [VC: Proper Group/PE Nesting]
260 ;; [VC: No Duplicate Types]
263 ;; /* Attribute-list Declaration */
265 ;; AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
267 ;; AttDef ::= S Name S AttType S DefaultDecl
270 ;; /* Attribute Types */
272 ;; AttType ::= StringType | TokenizedType | EnumeratedType
274 ;; StringType ::= 'CDATA'
276 ;; TokenizedType ::= 'ID' [VC: ID]
277 ;; [VC: One ID per Element Type]
278 ;; [VC: ID Attribute Default]
279 ;; | 'IDREF' [VC: IDREF]
280 ;; | 'IDREFS' [VC: IDREF]
281 ;; | 'ENTITY' [VC: Entity Name]
282 ;; | 'ENTITIES' [VC: Entity Name]
283 ;; | 'NMTOKEN' [VC: Name Token]
284 ;; | 'NMTOKENS' [VC: Name Token]
287 ;; /* Enumerated Attribute Types */
289 ;; EnumeratedType ::= NotationType | Enumeration
291 ;; NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
292 ;; [VC: Notation Attributes]
293 ;; [VC: One Notation Per Element Type]
294 ;; [VC: No Notation on Empty Element]
295 ;; [VC: No Duplicate Tokens]
297 ;; Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
299 ;; [VC: No Duplicate Tokens]
302 ;; /* Attribute Defaults */
304 ;; DefaultDecl ::= '#REQUIRED' | '#IMPLIED'
305 ;; | (('#FIXED' S)? AttValue)
306 ;; [VC: Required Attribute]
307 ;; [VC: Attribute Default Value Syntactically Correct]
308 ;; [WFC: No < in Attribute Values]
309 ;; [VC: Fixed Attribute Default]
312 ;; /* Conditional Section */
314 ;; conditionalSect ::= includeSect | ignoreSect
316 ;; includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
317 ;; [VC: Proper Conditional Section/PE Nesting]
319 ;; ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
320 ;; [VC: Proper Conditional Section/PE Nesting]
322 ;; ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
324 ;; Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
327 ;; /* Character Reference */
329 ;; CharRef ::= '&#' [0-9]+ ';'
330 ;; | '&#x' [0-9a-fA-F]+ ';'
331 ;; [WFC: Legal Character]
334 ;; /* Entity Reference */
336 ;; Reference ::= EntityRef | CharRef
338 ;; EntityRef ::= '&' Name ';'
339 ;; [WFC: Entity Declared]
340 ;; [VC: Entity Declared]
341 ;; [WFC: Parsed Entity]
342 ;; [WFC: No Recursion]
344 ;; PEReference ::= '%' Name ';'
345 ;; [VC: Entity Declared]
346 ;; [WFC: No Recursion]
350 ;; /* Entity Declaration */
352 ;; EntityDecl ::= GEDecl | PEDecl
354 ;; GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
356 ;; PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
358 ;; EntityDef ::= EntityValue | (ExternalID NDataDecl?)
360 ;; PEDef ::= EntityValue | ExternalID
363 ;; /* External Entity Declaration */
365 ;; ExternalID ::= 'SYSTEM' S SystemLiteral
366 ;; | 'PUBLIC' S PubidLiteral S SystemLiteral
368 ;; NDataDecl ::= S 'NDATA' S Name
369 ;; [VC: Notation Declared]
372 ;; /* Text Declaration */
374 ;; TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
377 ;; /* Well-Formed External Parsed Entity */
379 ;; extParsedEnt ::= TextDecl? content
382 ;; /* Encoding Declaration */
384 ;; EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
386 ;; EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
387 ;; /* Encoding name contains only Latin characters */
390 ;; /* Notation Declarations */
392 ;; NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
393 ;; [VC: Unique Notation Name]
395 ;; PublicID ::= 'PUBLIC' S PubidLiteral
400 ;; Letter ::= BaseChar | Ideographic
402 ;; BaseChar ::= [#x0041-#x005A] | [#x0061-#x007A] | [#x00C0-#x00D6]
403 ;; | [#x00D8-#x00F6] | [#x00F8-#x00FF] | [#x0100-#x0131]
404 ;; | [#x0134-#x013E] | [#x0141-#x0148] | [#x014A-#x017E]
405 ;; | [#x0180-#x01C3] | [#x01CD-#x01F0] | [#x01F4-#x01F5]
406 ;; | [#x01FA-#x0217] | [#x0250-#x02A8] | [#x02BB-#x02C1]
407 ;; | #x0386 | [#x0388-#x038A] | #x038C
408 ;; | [#x038E-#x03A1] | [#x03A3-#x03CE] | [#x03D0-#x03D6]
409 ;; | #x03DA | #x03DC | #x03DE
410 ;; | #x03E0 | [#x03E2-#x03F3] | [#x0401-#x040C]
411 ;; | [#x040E-#x044F] | [#x0451-#x045C] | [#x045E-#x0481]
412 ;; | [#x0490-#x04C4] | [#x04C7-#x04C8] | [#x04CB-#x04CC]
413 ;; | [#x04D0-#x04EB] | [#x04EE-#x04F5] | [#x04F8-#x04F9]
414 ;; | [#x0531-#x0556] | #x0559 | [#x0561-#x0586]
415 ;; | [#x05D0-#x05EA] | [#x05F0-#x05F2] | [#x0621-#x063A]
416 ;; | [#x0641-#x064A] | [#x0671-#x06B7] | [#x06BA-#x06BE]
417 ;; | [#x06C0-#x06CE] | [#x06D0-#x06D3] | #x06D5
418 ;; | [#x06E5-#x06E6] | [#x0905-#x0939] | #x093D
419 ;; | [#x0958-#x0961] | [#x0985-#x098C] | [#x098F-#x0990]
420 ;; | [#x0993-#x09A8] | [#x09AA-#x09B0] | #x09B2
421 ;; | [#x09B6-#x09B9] | [#x09DC-#x09DD] | [#x09DF-#x09E1]
422 ;; | [#x09F0-#x09F1] | [#x0A05-#x0A0A] | [#x0A0F-#x0A10]
423 ;; | [#x0A13-#x0A28] | [#x0A2A-#x0A30] | [#x0A32-#x0A33]
424 ;; | [#x0A35-#x0A36] | [#x0A38-#x0A39] | [#x0A59-#x0A5C]
425 ;; | #x0A5E | [#x0A72-#x0A74] | [#x0A85-#x0A8B]
426 ;; | #x0A8D | [#x0A8F-#x0A91] | [#x0A93-#x0AA8]
427 ;; | [#x0AAA-#x0AB0] | [#x0AB2-#x0AB3] | [#x0AB5-#x0AB9]
428 ;; | #x0ABD | #x0AE0 | [#x0B05-#x0B0C]
429 ;; | [#x0B0F-#x0B10] | [#x0B13-#x0B28] | [#x0B2A-#x0B30]
430 ;; | [#x0B32-#x0B33] | [#x0B36-#x0B39] | #x0B3D
431 ;; | [#x0B5C-#x0B5D] | [#x0B5F-#x0B61] | [#x0B85-#x0B8A]
432 ;; | [#x0B8E-#x0B90] | [#x0B92-#x0B95] | [#x0B99-#x0B9A]
433 ;; | #x0B9C | [#x0B9E-#x0B9F] | [#x0BA3-#x0BA4]
434 ;; | [#x0BA8-#x0BAA] | [#x0BAE-#x0BB5] | [#x0BB7-#x0BB9]
435 ;; | [#x0C05-#x0C0C] | [#x0C0E-#x0C10] | [#x0C12-#x0C28]
436 ;; | [#x0C2A-#x0C33] | [#x0C35-#x0C39] | [#x0C60-#x0C61]
437 ;; | [#x0C85-#x0C8C] | [#x0C8E-#x0C90] | [#x0C92-#x0CA8]
438 ;; | [#x0CAA-#x0CB3] | [#x0CB5-#x0CB9] | #x0CDE
439 ;; | [#x0CE0-#x0CE1] | [#x0D05-#x0D0C] | [#x0D0E-#x0D10]
440 ;; | [#x0D12-#x0D28] | [#x0D2A-#x0D39] | [#x0D60-#x0D61]
441 ;; | [#x0E01-#x0E2E] | #x0E30 | [#x0E32-#x0E33]
442 ;; | [#x0E40-#x0E45] | [#x0E81-#x0E82] | #x0E84
443 ;; | [#x0E87-#x0E88] | #x0E8A | #x0E8D
444 ;; | [#x0E94-#x0E97] | [#x0E99-#x0E9F] | [#x0EA1-#x0EA3]
445 ;; | #x0EA5 | #x0EA7 | [#x0EAA-#x0EAB]
446 ;; | [#x0EAD-#x0EAE] | #x0EB0 | [#x0EB2-#x0EB3]
447 ;; | #x0EBD | [#x0EC0-#x0EC4] | [#x0F40-#x0F47]
448 ;; | [#x0F49-#x0F69] | [#x10A0-#x10C5] | [#x10D0-#x10F6]
449 ;; | #x1100 | [#x1102-#x1103] | [#x1105-#x1107]
450 ;; | #x1109 | [#x110B-#x110C] | [#x110E-#x1112]
451 ;; | #x113C | #x113E | #x1140
452 ;; | #x114C | #x114E | #x1150
453 ;; | [#x1154-#x1155] | #x1159 | [#x115F-#x1161]
454 ;; | #x1163 | #x1165 | #x1167
455 ;; | #x1169 | [#x116D-#x116E] | [#x1172-#x1173]
456 ;; | #x1175 | #x119E | #x11A8
457 ;; | #x11AB | [#x11AE-#x11AF] | [#x11B7-#x11B8]
458 ;; | #x11BA | [#x11BC-#x11C2] | #x11EB
459 ;; | #x11F0 | #x11F9 | [#x1E00-#x1E9B]
460 ;; | [#x1EA0-#x1EF9] | [#x1F00-#x1F15] | [#x1F18-#x1F1D]
461 ;; | [#x1F20-#x1F45] | [#x1F48-#x1F4D] | [#x1F50-#x1F57]
462 ;; | #x1F59 | #x1F5B | #x1F5D
463 ;; | [#x1F5F-#x1F7D] | [#x1F80-#x1FB4] | [#x1FB6-#x1FBC]
464 ;; | #x1FBE | [#x1FC2-#x1FC4] | [#x1FC6-#x1FCC]
465 ;; | [#x1FD0-#x1FD3] | [#x1FD6-#x1FDB] | [#x1FE0-#x1FEC]
466 ;; | [#x1FF2-#x1FF4] | [#x1FF6-#x1FFC] | #x2126
467 ;; | [#x212A-#x212B] | #x212E | [#x2180-#x2182]
468 ;; | [#x3041-#x3094] | [#x30A1-#x30FA] | [#x3105-#x312C]
471 ;; Ideographic ::= [#x4E00-#x9FA5] | #x3007 | [#x3021-#x3029]
473 ;; CombiningChar ::= [#x0300-#x0345] | [#x0360-#x0361] | [#x0483-#x0486]
474 ;; | [#x0591-#x05A1] | [#x05A3-#x05B9] | [#x05BB-#x05BD]
475 ;; | #x05BF | [#x05C1-#x05C2] | #x05C4
476 ;; | [#x064B-#x0652] | #x0670 | [#x06D6-#x06DC]
477 ;; | [#x06DD-#x06DF] | [#x06E0-#x06E4] | [#x06E7-#x06E8]
478 ;; | [#x06EA-#x06ED] | [#x0901-#x0903] | #x093C
479 ;; | [#x093E-#x094C] | #x094D | [#x0951-#x0954]
480 ;; | [#x0962-#x0963] | [#x0981-#x0983] | #x09BC
481 ;; | #x09BE | #x09BF | [#x09C0-#x09C4]
482 ;; | [#x09C7-#x09C8] | [#x09CB-#x09CD] | #x09D7
483 ;; | [#x09E2-#x09E3] | #x0A02 | #x0A3C
484 ;; | #x0A3E | #x0A3F | [#x0A40-#x0A42]
485 ;; | [#x0A47-#x0A48] | [#x0A4B-#x0A4D] | [#x0A70-#x0A71]
486 ;; | [#x0A81-#x0A83] | #x0ABC | [#x0ABE-#x0AC5]
487 ;; | [#x0AC7-#x0AC9] | [#x0ACB-#x0ACD] | [#x0B01-#x0B03]
488 ;; | #x0B3C | [#x0B3E-#x0B43] | [#x0B47-#x0B48]
489 ;; | [#x0B4B-#x0B4D] | [#x0B56-#x0B57] | [#x0B82-#x0B83]
490 ;; | [#x0BBE-#x0BC2] | [#x0BC6-#x0BC8] | [#x0BCA-#x0BCD]
491 ;; | #x0BD7 | [#x0C01-#x0C03] | [#x0C3E-#x0C44]
492 ;; | [#x0C46-#x0C48] | [#x0C4A-#x0C4D] | [#x0C55-#x0C56]
493 ;; | [#x0C82-#x0C83] | [#x0CBE-#x0CC4] | [#x0CC6-#x0CC8]
494 ;; | [#x0CCA-#x0CCD] | [#x0CD5-#x0CD6] | [#x0D02-#x0D03]
495 ;; | [#x0D3E-#x0D43] | [#x0D46-#x0D48] | [#x0D4A-#x0D4D]
496 ;; | #x0D57 | #x0E31 | [#x0E34-#x0E3A]
497 ;; | [#x0E47-#x0E4E] | #x0EB1 | [#x0EB4-#x0EB9]
498 ;; | [#x0EBB-#x0EBC] | [#x0EC8-#x0ECD] | [#x0F18-#x0F19]
499 ;; | #x0F35 | #x0F37 | #x0F39
500 ;; | #x0F3E | #x0F3F | [#x0F71-#x0F84]
501 ;; | [#x0F86-#x0F8B] | [#x0F90-#x0F95] | #x0F97
502 ;; | [#x0F99-#x0FAD] | [#x0FB1-#x0FB7] | #x0FB9
503 ;; | [#x20D0-#x20DC] | #x20E1 | [#x302A-#x302F]
506 ;; Digit ::= [#x0030-#x0039] | [#x0660-#x0669] | [#x06F0-#x06F9]
507 ;; | [#x0966-#x096F] | [#x09E6-#x09EF] | [#x0A66-#x0A6F]
508 ;; | [#x0AE6-#x0AEF] | [#x0B66-#x0B6F] | [#x0BE7-#x0BEF]
509 ;; | [#x0C66-#x0C6F] | [#x0CE6-#x0CEF] | [#x0D66-#x0D6F]
510 ;; | [#x0E50-#x0E59] | [#x0ED0-#x0ED9] | [#x0F20-#x0F29]
512 ;; Extender ::= #x00B7 | #x02D0 | #x02D1 | #x0387 | #x0640 | #x0E46 | #x0EC6
513 ;; | #x3005 | [#x3031-#x3035] | [#x309D-#x309E] | [#x30FC-#x30FE]
519 ;; At moment, only the `<!ELEMENT' generates a syntactic chart. The
520 ;; `<!ATTLIST', `<!NOTATION' and `<!ENTITY' are syntacticly checked but they
521 ;; don't generate a syntactic chart.
523 ;; Besides the syntax above, ebnf-dtd also accepts a `pure' dtd file. An
524 ;; example of a `pure' dtd file is:
526 ;; <?xml version="1.0" encoding="UTF-8"?>
530 ;; <!ELEMENT workflow (registers?, trigger-functions?, initial-actions,
531 ;; steps, splits?, joins?)>
533 ;; An action that can be executed (id must be unique among actions for
534 ;; the enclosing step).
537 ;; <!ELEMENT action (restrict-to, validators?, pre-functions?, results,
540 ;; id CDATA #REQUIRED
541 ;; name CDATA #REQUIRED
545 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
553 (defvar ebnf-dtd-lex nil
554 "Value returned by `ebnf-dtd-lex' function.")
557 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
558 ;; Syntactic analyzer
561 ;;; document ::= prolog element Misc*
562 ;;; /* Note that *only* the prolog will be parsed */
564 (defun ebnf-dtd-parser (start)
566 (let ((total (+ (- ebnf-limit start
) 1))
569 rule-list token rule the-end
)
571 (setq token
(ebnf-dtd-lex))
572 (and (eq token
'end-of-input
)
573 (error "Empty DTD file"))
574 (setq token
(ebnf-dtd-prolog token
))
575 (unless (eq (car token
) 'end-prolog
)
576 (setq the-end
(cdr token
)
578 (while (not (eq token the-end
))
581 (/ (* (- (point) bias
) 100.0) total
))
582 (setq token
(ebnf-dtd-intsubset token
)
586 (ebnf-add-empty-rule-list rule
)
587 (setq rule-list
(cons rule rule-list
))))
588 (or (eq the-end
'end-of-input
)
589 (eq (ebnf-dtd-lex) 'end-decl
)
590 (error "Missing end of DOCTYPE"))
591 ;; adjust message, 'cause *only* prolog will be parsed
592 (ebnf-message-float "Parsing...%s%%" 100.0))
597 ;;; prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
599 ;;; XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
601 ;;; VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
605 ;;; VersionNum ::= '1.0'
607 ;;; Misc ::= Comment | PI | S
609 ;;; EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
611 ;;; EncName ::= [A-Za-z] ([-A-Za-z0-9._])*
612 ;;; /* Encoding name contains only Latin characters */
614 ;;; SDDecl ::= S 'standalone' Eq
615 ;;; (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
617 ;;; doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
618 ;;; ('[' intSubset ']' S?)? '>'
621 (defun ebnf-dtd-prolog (token)
622 (when (and (eq token
'begin-pi
) (string= ebnf-dtd-lex
"xml"))
624 (setq token
(ebnf-dtd-attribute (ebnf-dtd-lex) 'version-attr
625 "^1\\.0$" "XML version"))
626 ;; ( encoding = "encoding name" )?
627 (setq token
(ebnf-dtd-attribute-optional
629 "^[A-Za-z][-A-Za-z0-9._]*$" "XML encoding"))
630 ;; ( standalone = ( "yes" | "no" ) )?
631 (setq token
(ebnf-dtd-attribute-optional
632 token
'standalone-attr
633 "^yes|no$" "XML standalone"))
634 (or (eq token
'end-pi
)
635 (error "Missing end of XML processing instruction")))
636 ;; processing instructions
637 (setq token
(ebnf-dtd-pi (ebnf-dtd-lex)))
640 ((eq token
'doctype-decl
)
641 (or (eq (ebnf-dtd-lex) 'name
)
642 (error "Document type name is missing"))
643 (cons (if (eq (ebnf-dtd-externalid) 'begin-subset
)
647 ((memq token
'(element-decl attlist-decl entity-decl notation-decl
))
648 (cons token
'end-of-input
))
650 '(end-prolog . end-subset
))
654 (defun ebnf-dtd-attribute (token attr match attr-name
)
656 (error "%s attribute is missing" attr-name
))
657 (ebnf-dtd-attribute-optional token attr match attr-name
))
660 (defun ebnf-dtd-attribute-optional (token attr match attr-name
)
661 (when (eq token attr
)
662 (or (and (eq (ebnf-dtd-lex) 'equal
)
663 (eq (ebnf-dtd-lex) 'string
)
664 (string-match match ebnf-dtd-lex
))
665 (error "XML %s attribute is invalid" attr-name
))
666 (setq token
(ebnf-dtd-lex)))
670 ;;; ExternalID ::= 'SYSTEM' S SystemLiteral
671 ;;; | 'PUBLIC' S PubidLiteral S SystemLiteral
674 (defun ebnf-dtd-externalid (&optional token
)
675 (let ((must-have token
))
676 (or token
(setq token
(ebnf-dtd-lex)))
677 (cond ((eq token
'system
)
678 (ebnf-dtd-systemliteral))
680 (ebnf-dtd-pubidliteral)
681 (ebnf-dtd-systemliteral))
683 (error "Missing `SYSTEM' or `PUBLIC' in external id"))
688 ;;; SystemLiteral ::= ('"' [^"]* '"')
689 ;;; | ("'" [^']* "'")
692 (defun ebnf-dtd-systemliteral ()
693 (or (eq (ebnf-dtd-lex) 'string
)
694 (error "System identifier is invalid"))
698 ;;; PubidLiteral ::= '"' PubidChar* '"'
699 ;;; | "'" (PubidChar - "'")* "'"
701 ;;; PubidChar ::= [-'()+,./:=?;!*#@$_%\n\r a-zA-Z0-9]
704 (defun ebnf-dtd-pubidliteral ()
705 (or (and (eq (ebnf-dtd-lex) 'string
)
706 (string-match "^[-'()+,./:=?;!*#@$_%\n\r a-zA-Z0-9]*$"
708 (error "Public identifier is invalid")))
711 ;;; PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
713 ;;; PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
716 (defun ebnf-dtd-pi (token)
717 (while (eq token
'begin-pi
)
718 (and (string-match "^[xX][mM][lL]$" ebnf-dtd-lex
)
719 (error "Processing instruction name can not be `XML'"))
720 (while (not (eq (ebnf-dtd-lex) 'end-pi
)))
721 (setq token
(ebnf-dtd-lex)))
725 ;;; doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
726 ;;; ('[' intSubset ']' S?)? '>'
728 ;;; intSubset ::= (markupdecl | DeclSep)*
730 ;;; DeclSep ::= PEReference | S
732 ;;; markupdecl ::= elementdecl | AttlistDecl | EntityDecl
733 ;;; | NotationDecl | PI | Comment
736 (defun ebnf-dtd-intsubset (token)
737 ;; PI - Processing Instruction
738 (and (eq token
'begin-pi
)
739 (setq token
(ebnf-dtd-pi token
)))
741 ((memq token
'(end-subset end-of-input
))
744 (cons (ebnf-dtd-lex) nil
)) ; annotation
745 ((eq token
'element-decl
)
746 (ebnf-dtd-elementdecl)) ; rule
747 ((eq token
'attlist-decl
)
748 (ebnf-dtd-attlistdecl)) ; annotation
749 ((eq token
'entity-decl
)
750 (ebnf-dtd-entitydecl)) ; annotation
751 ((eq token
'notation-decl
)
752 (ebnf-dtd-notationdecl)) ; annotation
754 (error "Invalid DOCTYPE element"))
758 ;;; elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
760 ;;; contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
762 ;;; Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*'
763 ;;; | '(' S? '#PCDATA' S? ')'
765 ;;; children ::= (choice | seq) ('?' | '*' | '+')?
767 ;;; choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
769 ;;; seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
771 ;;; cp ::= (Name | choice | seq) ('?' | '*' | '+')?
774 (defun ebnf-dtd-elementdecl ()
775 (let ((action ebnf-action
)
777 (setq ebnf-action nil
)
778 (or (eq (ebnf-dtd-lex) 'name
)
779 (error "Invalid ELEMENT name"))
780 (setq name ebnf-dtd-lex
782 body
(cond ((memq token
'(empty any
))
783 (let ((term (ebnf-make-terminal ebnf-dtd-lex
)))
784 (cons (ebnf-dtd-lex) term
)))
785 ((eq token
'begin-group
)
786 (setq token
(ebnf-dtd-lex))
787 (if (eq token
'pcdata
)
789 (ebnf-dtd-children token
)))
791 (error "Invalid ELEMENT content"))
793 (or (eq (car body
) 'end-decl
)
794 (error "Missing `>' in ELEMENT declaration"))
795 (ebnf-eps-add-production name
)
797 (ebnf-make-production name
(cdr body
) action
))))
800 ;;; Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*'
801 ;;; | '(' S? '#PCDATA' S? ')'
804 (defun ebnf-dtd-mixed ()
805 (let* ((alt (cons (ebnf-make-terminal ebnf-dtd-lex
) nil
))
806 (token (ebnf-dtd-lex))
807 (has-alternative (eq token
'alternative
)))
808 (while (eq token
'alternative
)
809 (or (eq (ebnf-dtd-lex) 'name
)
810 (error "Invalid name"))
811 (setq alt
(cons ebnf-dtd-lex alt
)
812 token
(ebnf-dtd-lex)))
813 (or (eq token
'end-group
)
814 (error "Missing `)'"))
816 (or (eq (ebnf-dtd-lex) 'zero-or-more
)
817 (error "Missing `*'")))
818 (ebnf-token-alternative alt
(cons (ebnf-dtd-lex) nil
))))
821 ;;; children ::= (choice | seq) ('?' | '*' | '+')?
824 (defun ebnf-dtd-children (token)
825 (ebnf-dtd-operators (ebnf-dtd-choice-seq token
)))
828 ;;; choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
830 ;;; seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
833 (defun ebnf-dtd-choice-seq (token)
834 (setq token
(ebnf-dtd-cp token
))
838 ((eq (car token
) 'alternative
)
839 (while (eq (car token
) 'alternative
)
840 (setq elist
(cons (cdr token
) elist
)
841 token
(ebnf-dtd-cp (ebnf-dtd-lex))))
842 (setq elist
(ebnf-token-alternative elist token
)))
844 ((eq (car token
) 'comma
)
845 (while (eq (car token
) 'comma
)
846 (setq elist
(cons (cdr token
) elist
)
847 token
(ebnf-dtd-cp (ebnf-dtd-lex))))
848 (setq elist
(ebnf-token-sequence (cons (cdr token
) elist
))))
851 (setq elist
(cdr token
))))
852 (or (eq (car token
) 'end-group
)
853 (error "Missing `)' in ELEMENT content"))
857 ;;; cp ::= (Name | choice | seq) ('?' | '*' | '+')?
860 (defun ebnf-dtd-cp (token)
861 (ebnf-dtd-operators (cond ((eq token
'name
)
862 (ebnf-make-terminal ebnf-dtd-lex
))
863 ((eq token
'begin-group
)
864 (ebnf-dtd-choice-seq (ebnf-dtd-lex)))
866 (error "Invalid element"))
870 ;;; elm ('?' | '*' | '+')?
873 (defun ebnf-dtd-operators (elm)
874 (let ((token (ebnf-dtd-lex)))
875 (cond ((eq token
'optional
) ; ? - optional
876 (cons (ebnf-dtd-lex) (ebnf-token-optional elm
)))
877 ((eq token
'zero-or-more
) ; * - zero or more
878 (cons (ebnf-dtd-lex) (ebnf-make-zero-or-more elm
)))
879 ((eq token
'one-or-more
) ; + - one or more
880 (cons (ebnf-dtd-lex) (ebnf-make-one-or-more elm
)))
886 ;;; AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
888 ;;; AttDef ::= S Name S AttType S DefaultDecl
890 ;;; AttType ::= StringType | TokenizedType | EnumeratedType
892 ;;; StringType ::= 'CDATA'
894 ;;; TokenizedType ::= 'ID'
902 ;;; EnumeratedType ::= NotationType | Enumeration
904 ;;; NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
906 ;;; Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
908 ;;; DefaultDecl ::= '#REQUIRED'
910 ;;; | (('#FIXED' S)? AttValue)
913 ;;; AttValue ::= '"' ([^<&"] | Reference)* '"'
914 ;;; | "'" ([^<&'] | Reference)* "'"
916 ;;; Reference ::= EntityRef | CharRef
918 ;;; EntityRef ::= '&' Name ';'
920 ;;; CharRef ::= '&#' [0-9]+ ';'
921 ;;; | '&#x' [0-9a-fA-F]+ ';'
923 ;;; "^\\(&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^<&]\\)*$"
926 (defun ebnf-dtd-attlistdecl ()
927 (or (eq (ebnf-dtd-lex) 'name
)
928 (error "Invalid ATTLIST name"))
930 (while (eq (setq token
(ebnf-dtd-lex)) 'name
)
932 (setq token
(ebnf-dtd-lex))
934 ((eq token
'notation
)
935 (or (eq (ebnf-dtd-lex) 'begin-group
)
936 (error "Missing `(' in NOTATION type in ATTLIST declaration"))
937 (ebnf-dtd-namelist "NOTATION" '(name)))
938 ((eq token
'begin-group
)
939 (ebnf-dtd-namelist "enumeration" '(name name-char
)))
941 '(cdata id idref idrefs entity entities nmtoken nmtokens
)))
943 (error "Invalid type in ATTLIST declaration")))
945 (setq token
(ebnf-dtd-lex))
946 (unless (memq token
'(required implied
))
947 (and (eq token
'fixed
)
948 (setq token
(ebnf-dtd-lex)))
949 (or (and (eq token
'string
)
951 "^\\(&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^<&]\\)*$"
953 (error "Invalid default value in ATTLIST declaration"))))
954 (or (eq token
'end-decl
)
955 (error "Missing `>' in end of ATTLIST"))
956 (cons (ebnf-dtd-lex) nil
)))
959 (defun ebnf-dtd-namelist (type name-list
)
962 (or (memq (ebnf-dtd-lex) name-list
)
963 (error "Invalid name in %s type in ATTLIST declaration" type
))
964 (eq (setq token
(ebnf-dtd-lex)) 'alternative
)))
965 (or (eq token
'end-group
)
966 (error "Missing `)' in %s type in ATTLIST declaration" type
))))
969 ;;; EntityDecl ::= GEDecl | PEDecl
971 ;;; GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
973 ;;; PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
975 ;;; EntityDef ::= EntityValue | (ExternalID NDataDecl?)
977 ;;; PEDef ::= EntityValue | ExternalID
979 ;;; NDataDecl ::= S 'NDATA' S Name
982 ;;; EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
983 ;;; | "'" ([^%&'] | PEReference | Reference)* "'"
985 ;;; PEReference ::= '%' Name ';'
987 ;;; Reference ::= EntityRef | CharRef
989 ;;; EntityRef ::= '&' Name ';'
991 ;;; CharRef ::= '&#' [0-9]+ ';'
992 ;;; | '&#x' [0-9a-fA-F]+ ';'
994 ;;; "^\\(%[A-Za-z_:][-A-Za-z0-9._:]*;\\|&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^%&]\\)*$"
997 (defun ebnf-dtd-entitydecl ()
998 (let* ((token (ebnf-dtd-lex))
999 (pedecl (eq token
'percent
)))
1001 (setq token
(ebnf-dtd-lex)))
1002 (or (eq token
'name
)
1003 (error "Invalid name of ENTITY"))
1004 (setq token
(ebnf-dtd-lex))
1005 (if (eq token
'string
)
1007 "^\\(%[A-Za-z_:][-A-Za-z0-9._:]*;\\|&\\([A-Za-z_:][-A-Za-z0-9._:]*\\|#\\(x[0-9a-fA-F]+\\|[0-9]+\\)\\);\\|[^%&]\\)*$"
1009 (setq token
(ebnf-dtd-lex))
1010 (error "Invalid ENTITY definition"))
1011 (setq token
(ebnf-dtd-externalid token
))
1012 (when (and (not pedecl
) (eq token
'ndata
))
1013 (or (eq (ebnf-dtd-lex) 'name
)
1014 (error "Invalid NDATA name"))
1015 (setq token
(ebnf-dtd-lex))))
1016 (or (eq token
'end-decl
)
1017 (error "Missing `>' in end of ENTITY"))
1018 (cons (ebnf-dtd-lex) nil
)))
1021 ;;; NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
1023 ;;; PublicID ::= 'PUBLIC' S PubidLiteral
1026 (defun ebnf-dtd-notationdecl ()
1027 (or (eq (ebnf-dtd-lex) 'name
)
1028 (error "Invalid name NOTATION"))
1029 (or (eq (ebnf-dtd-externalid-or-publicid) 'end-decl
)
1030 (error "Missing `>' in end of NOTATION"))
1031 (cons (ebnf-dtd-lex) nil
))
1034 ;;; ExternalID ::= 'SYSTEM' S SystemLiteral
1035 ;;; | 'PUBLIC' S PubidLiteral S SystemLiteral
1037 ;;; PublicID ::= 'PUBLIC' S PubidLiteral
1040 (defun ebnf-dtd-externalid-or-publicid ()
1041 (let ((token (ebnf-dtd-lex)))
1042 (cond ((eq token
'system
)
1043 (ebnf-dtd-systemliteral))
1045 (ebnf-dtd-pubidliteral)
1046 (and (eq (setq token
(ebnf-dtd-lex)) 'string
)
1047 (setq token
(ebnf-dtd-lex)))
1050 (error "Missing `SYSTEM' or `PUBLIC'")))))
1053 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1057 (defconst ebnf-dtd-token-table
(make-vector 256 'error
)
1058 "Vector used to map characters to a lexical token.")
1061 (defun ebnf-dtd-initialize ()
1062 "Initialize EBNF token table."
1063 ;; control character & control 8-bit character are set to `error'
1066 (while (< char ?
\072)
1067 (aset ebnf-dtd-token-table char
'name-char
)
1068 (setq char
(1+ char
)))
1069 ;; printable character: A-Z
1071 (while (< char ?
\133)
1072 (aset ebnf-dtd-token-table char
'name
)
1073 (setq char
(1+ char
)))
1074 ;; printable character: a-z
1076 (while (< char ?
\173)
1077 (aset ebnf-dtd-token-table char
'name
)
1078 (setq char
(1+ char
)))
1079 ;; European 8-bit accentuated characters:
1081 (while (< char ?
\400)
1082 (aset ebnf-dtd-token-table char
'name
)
1083 (setq char
(1+ char
)))
1084 ;; Override name characters:
1085 (aset ebnf-dtd-token-table ?_
'name
)
1086 (aset ebnf-dtd-token-table ?
: 'name
)
1087 (aset ebnf-dtd-token-table ?.
'name-char
)
1088 (aset ebnf-dtd-token-table ?-
'name-char
)
1089 ;; Override space characters:
1090 (aset ebnf-dtd-token-table ?
\n 'space
) ; [NL] linefeed
1091 (aset ebnf-dtd-token-table ?
\r 'space
) ; [CR] carriage return
1092 (aset ebnf-dtd-token-table ?
\t 'space
) ; [HT] horizontal tab
1093 (aset ebnf-dtd-token-table ?\
'space
) ; [SP] space
1094 ;; Override other lexical characters:
1095 (aset ebnf-dtd-token-table ?
= 'equal
)
1096 (aset ebnf-dtd-token-table ?
, 'comma
)
1097 (aset ebnf-dtd-token-table ?
* 'zero-or-more
)
1098 (aset ebnf-dtd-token-table ?
+ 'one-or-more
)
1099 (aset ebnf-dtd-token-table ?|
'alternative
)
1100 (aset ebnf-dtd-token-table ?%
'percent
)
1101 (aset ebnf-dtd-token-table ?
& 'ampersand
)
1102 (aset ebnf-dtd-token-table ?
# 'hash
)
1103 (aset ebnf-dtd-token-table ?
\? 'interrogation
)
1104 (aset ebnf-dtd-token-table ?
\" 'double-quote
)
1105 (aset ebnf-dtd-token-table ?
\' 'single-quote
)
1106 (aset ebnf-dtd-token-table ?
< 'less-than
)
1107 (aset ebnf-dtd-token-table ?
> 'end-decl
)
1108 (aset ebnf-dtd-token-table ?\
( 'begin-group
)
1109 (aset ebnf-dtd-token-table ?\
) 'end-group
)
1110 (aset ebnf-dtd-token-table ?\
[ 'begin-subset
)
1111 (aset ebnf-dtd-token-table ?\
] 'end-subset
)))
1114 ;; replace the range "\240-\377" (see `ebnf-range-regexp').
1115 (defconst ebnf-dtd-name-chars
1116 (ebnf-range-regexp "-._:0-9A-Za-z" ?
\240 ?
\377))
1119 (defconst ebnf-dtd-decl-alist
1120 '(("ATTLIST" . attlist-decl
)
1121 ("DOCTYPE" . doctype-decl
)
1122 ("ELEMENT" . element-decl
)
1123 ("ENTITY" . entity-decl
)
1124 ("NOTATION" . notation-decl
)))
1127 (defconst ebnf-dtd-element-alist
1128 '(("#FIXED" . fixed
)
1129 ("#IMPLIED" . implied
)
1130 ("#PCDATA" . pcdata
)
1131 ("#REQUIRED" . required
)))
1134 (defconst ebnf-dtd-name-alist
1138 ("ENTITIES" . entities
)
1144 ("NMTOKEN" . nmtoken
)
1145 ("NMTOKENS" . nmtokens
)
1146 ("NOTATION" . notation
)
1149 ("encoding" . encoding-attr
)
1150 ("standalone" . standalone-attr
)
1151 ("version" . version-attr
)))
1154 (defun ebnf-dtd-lex ()
1155 "Lexical analyzer for DTD.
1157 Return a lexical token.
1159 See documentation for variable `ebnf-dtd-lex'."
1160 (if (>= (point) ebnf-limit
)
1163 ;; skip spaces and comments
1164 (while (if (> (following-char) 255)
1168 (setq token
(aref ebnf-dtd-token-table
(following-char)))
1171 (skip-chars-forward " \n\r\t" ebnf-limit
)
1172 (< (point) ebnf-limit
))
1173 ((and (eq token
'less-than
)
1174 (looking-at "<!--"))
1175 (ebnf-dtd-skip-comment))
1180 ((>= (point) ebnf-limit
)
1184 (error "Invalid character"))
1185 ;; beginning of declaration:
1186 ;; <?name, <!ATTLIST, <!DOCTYPE, <!ELEMENT, <!ENTITY, <!NOTATION
1187 ((eq token
'less-than
)
1189 (let ((char (following-char)))
1190 (cond ((= char ?
\?) ; <?
1192 (setq ebnf-dtd-lex
(ebnf-buffer-substring ebnf-dtd-name-chars
))
1196 (let ((decl (ebnf-buffer-substring ebnf-dtd-name-chars
)))
1197 (or (cdr (assoc decl ebnf-dtd-decl-alist
))
1198 (error "Invalid declaration name `%s'" decl
))))
1200 (error "Invalid declaration `<%c'" char
)))))
1202 ((memq token
'(name name-char
))
1203 (setq ebnf-dtd-lex
(ebnf-buffer-substring ebnf-dtd-name-chars
))
1204 (or (cdr (assoc ebnf-dtd-lex ebnf-dtd-name-alist
))
1207 ((eq token
'interrogation
)
1209 (if (/= (following-char) ?
>)
1213 ;; #FIXED, #IMPLIED, #PCDATA, #REQUIRED
1217 (concat "#" (ebnf-buffer-substring ebnf-dtd-name-chars
)))
1218 (or (cdr (assoc ebnf-dtd-lex ebnf-dtd-element-alist
))
1219 (error "Invalid element `%s'" ebnf-dtd-lex
)))
1221 ((eq token
'double-quote
)
1222 (setq ebnf-dtd-lex
(ebnf-dtd-string ?
\"))
1225 ((eq token
'single-quote
)
1226 (setq ebnf-dtd-lex
(ebnf-dtd-string ?
\'))
1229 ((eq token
'percent
)
1231 (if (looking-at "[ \n\r\t]")
1233 (setq ebnf-dtd-lex
(ebnf-dtd-name-ref "%"))
1235 ;; &#...;, &#x...;, &name;
1236 ((eq token
'ampersand
)
1238 (if (/= (following-char) ?
#)
1241 (setq ebnf-dtd-lex
(ebnf-dtd-name-ref "&"))
1245 (setq ebnf-dtd-lex
(if (/= (following-char) ?x
)
1246 (ebnf-dtd-char-ref "&#" "0-9")
1248 (ebnf-dtd-char-ref "&#x" "0-9a-fA-F")))
1250 ;; miscellaneous: (, ), [, ], =, |, *, +, >, `,'
1257 (defun ebnf-dtd-name-ref (start)
1258 (ebnf-dtd-char-ref start ebnf-dtd-name-chars
))
1261 (defun ebnf-dtd-char-ref (start chars
)
1262 (let ((char (ebnf-buffer-substring chars
)))
1263 (or (= (following-char) ?\
;)
1264 (error "Invalid element `%s%s%c'" start char
(following-char)))
1266 (format "%s%s;" start char
)))
1269 ;; replace the range "\240-\377" (see `ebnf-range-regexp').
1270 (defconst ebnf-dtd-double-string-chars
1271 (ebnf-range-regexp "\t -!#-~" ?
\240 ?
\377))
1272 (defconst ebnf-dtd-single-string-chars
1273 (ebnf-range-regexp "\t -&(-~" ?
\240 ?
\377))
1276 (defun ebnf-dtd-string (delim)
1277 (buffer-substring-no-properties
1282 (skip-chars-forward (if (= delim ?
\")
1283 ebnf-dtd-double-string-chars
1284 ebnf-dtd-single-string-chars
)
1286 (or (= (following-char) delim
)
1287 (error "Missing string delimiter `%c'" delim
))
1293 ;; replace the range "\177-\237" (see `ebnf-range-regexp').
1294 (defconst ebnf-dtd-comment-chars
1295 (ebnf-range-regexp "^-\000-\010\013\014\016-\037" ?
\177 ?
\237))
1296 (defconst ebnf-dtd-filename-chars
1297 (ebnf-range-regexp "^-\000-\037" ?
\177 ?
\237))
1300 (defun ebnf-dtd-skip-comment ()
1301 (forward-char 4) ; <!--
1304 ((and ebnf-eps-executing
(= (following-char) ?\
[))
1305 (ebnf-eps-add-context (ebnf-dtd-eps-filename)))
1307 ((and ebnf-eps-executing
(= (following-char) ?\
]))
1308 (ebnf-eps-remove-context (ebnf-dtd-eps-filename)))
1310 ((and ebnf-eps-executing
(= (following-char) ?H
))
1311 (ebnf-eps-header-comment (ebnf-dtd-eps-filename)))
1313 ((and ebnf-eps-executing
(= (following-char) ?F
))
1314 (ebnf-eps-footer-comment (ebnf-dtd-eps-filename)))
1315 ;; any other action in comment
1317 (setq ebnf-action
(aref ebnf-comment-table
(following-char))))
1320 (skip-chars-forward ebnf-dtd-comment-chars ebnf-limit
)
1321 (and (< (point) ebnf-limit
)
1322 (not (looking-at "-->"))))
1323 (skip-chars-forward "-" ebnf-limit
))
1324 ;; check for a valid end of comment
1325 (cond ((>= (point) ebnf-limit
)
1331 (error "Invalid character"))
1335 (defun ebnf-dtd-eps-filename ()
1341 (ebnf-buffer-substring ebnf-dtd-filename-chars
)))
1342 (and (< (point) ebnf-limit
)
1343 (= (following-char) ?-
) ; may be \n, \t, \r
1344 (not (looking-at "-->"))))
1345 (setq fname
(concat fname
(ebnf-buffer-substring "-"))))
1349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1354 ;;; arch-tag: c21bb640-135f-4afa-8712-fa11d86301c4
1355 ;;; ebnf-dtd.el ends here