root/trunk/tdtd/tdtd-font-maker.el

Revision 5, 28.6 KB (checked in by tkg, 3 years ago)

Renamed make-regexp.el to tdtd-make-regexp.el since xslide uses file with same name.

Line 
1;;;; tdtd-font-maker.el --- Specify and generate font-lock keywords
2;; $Id: tdtd-font-maker.el,v 0.20 2001-08-31 23:16:19-04 tkg Exp $
3;; $Name: tdtd08b1 $
4
5;; Copyright (C) 1997, 1998, 1999, 2001, 2007 Tony Graham
6
7;; Author: Tony Graham <tkg@menteith.com>
8
9;;; This file is not part of GNU Emacs.
10
11;; This program is free software; you can redistribute it and/or
12;; modify it under the terms of the GNU General Public License
13;; as published by the Free Software Foundation; either version 2
14;; of the License, or (at your option) any later version.
15;;
16;; This program is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19;; GNU General Public License for more details.
20;;
21;; You should have received a copy of the GNU General Public License
22;; along with this program; if not, write to the Free Software
23;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25
26;;;; Commentary:
27
28;; `dtd-make-tdtd-font' in this file writes the tdtd-font.el file that
29;; contains the font-lock keywords for DTD mode.  The convoluted logic
30;; for the regular expressions for the font lock mode keywords for use
31;; when editing DTDs are contained in this file.  Changes to the DTD
32;; mode font-lock keywords should be made in this file and a new
33;; tdtd-font.el regenerated instead of changing tdtd-font.el directly
34;; (and if you've looked in tdtd-font.el, you'll know why).
35
36;; Use `dtd-submit-bug-report' to report bugs.
37
38;; The font lock keywords are complicated firstly by the need to match
39;; declaration formats and reserved names in XML DTDs, SGML DTDs, SGML
40;; Declarations, and SGML System Declarations, and secondly because we
41;; match on both complete declarations and reserved names such that
42;; the reserved names change colour as they are entered, then some or
43;; all of the declaration changes colour again when the closing
44;; delimiter is entered.  This makes the keywords more complicated,
45;; but it provides visual feedback that a declaration is complete.
46
47;; Reserved words in SGML, XML, and SGML Declarations
48;;
49;; Meaning of the columns:
50;; XML -- Allowed in XML DTDs
51;; SGML -- Allowed in SGML DTDs and LPDs
52;; Decl -- Allowed in SGML Declarations
53;; System -- Allowed in System Declarations
54;;
55;; Note that the font lock keywords for an SGML Declaration includes
56;; both the keywords identified as allowed in SGML Declarations and
57;; the keywords identified as allowed in SGML DTDs and LPDs since the
58;; SGML Declaration may be followed by a DTD or DTDs and LPD or LPDs.
59;;
60;; In several cases, keywords beginning with "#" (RNI) are shown as
61;; allowed in XML and SGML DTDs, and the word without the RNI is shown
62;; as allowed in SGML Declarations.  SGML's reserved words that are
63;; not used in the SGML Declaration may be redefined in the
64;; Declaration, hence the non-RNI form is a keyword in the Declaration
65;; (even though this font lock stuff doesn't match on the redefined
66;; reserved word).
67;;
68;;
69;;  Word                XML     SGML    Decl    System
70;;  -//                 x       x       x       x
71;;  +//                 x       x       x       x
72;;  +//IDN              x       x       x       x
73;;  //                  x       x       x       x
74;;  #ALL                        x
75;;  #CONREF                     x
76;;  #CURRENT                    x
77;;  #DEFAULT                    x
78;;  #EMPTY                      x       
79;;  #FIXED              x       x
80;;  #IMPLICIT                   x
81;;  #IMPLIED            x       x
82;;  #INITIAL                    x       
83;;  #NOTATION                   x
84;;  #PCDATA             x       x
85;;  #POSTLINK                   x
86;;  #REQUIRED           x       x
87;;  #RESTORE                    x
88;;  #SIMPLE                     x
89;;  #USELINK                    x
90;;  ALL                                 x       x
91;;  AND                                 x       x
92;;  ANY                 x       x       x       x
93;;  APPINFO                             x
94;;  ASN1                                        x
95;;  ATTCAP                              x       x
96;;  ATTCHCAP                            x       x
97;;  ATTCNT                              x       x
98;;  ATTLIST             x       x       x       x
99;;  ATTRIB                              x       x
100;;  ATTSPLEN                            x       x
101;;  AVGRPCAP                            x       x
102;;  BASESET                             x       x
103;;  BB                                  x       x
104;;  BSEQLEN                             x       x
105;;  CAPACITY                            x       x
106;;  CDATA               x       x       x       x
107;;  CHANGES                             x       x
108;;  CHARSET                             x       x
109;;  COM                                 x       x
110;;  CONCUR                              x
111;;  CONREF                      x       x       x
112;;  CONTROLS                            x       x
113;;  CRO                                 x       x
114;;  CURRENT                     x       x       x
115;;  DATA                        x       x       x
116;;  DATATAG                             x       x
117;;  DEFAULT                     x       x       x
118;;  DELIMLEN                                    x
119;;  DELIM                               x       x
120;;  DESCSET                             x       x
121;;  DOCTYPE             x       x       x       x
122;;  DOCUMENT                            x       x
123;;  DSC                                 x       x
124;;  DSO                                 x       x
125;;  DTAGLEN                             x       x
126;;  DTD                         x       x
127;;  DTEMPLEN                            x       x
128;;  DTGC                                x       x
129;;  DTGO                                x       x
130;;  ELEMCAP                             x
131;;  ELEMENT             x       x       x       x
132;;  EMPTY               x       x       x       x
133;;  EMPTYNRM                            x       x
134;;  ENDTAG                      x       x       x
135;;  ENTITIES            x       x       x       x
136;;  ENTITY              x       x       x       x
137;;  ENTLVL                              x       x
138;;  ENTCAP                              x       x
139;;  ENTCHCAP                            x       x
140;;  ERO                                 x       x
141;;  ETAGO                               x       x
142;;  EXCLUDE                                     x
143;;  EXGRPCAP                            x       x
144;;  EXNMCAP                             x       x
145;;  EXPLICIT                            x
146;;  FEATURES                            x       x
147;;  FIXED                               x       x
148;;  FORMAL                              x       x
149;;  FUNCHAR                             x       x
150;;  FUNCTION                            x       x
151;;  GENERAL                             x       x
152;;  GRPC                                x       x
153;;  GRPCNT                              x       x
154;;  GRPGTCNT                            x       x
155;;  GRPLVL                              x       x
156;;  GRPO                                x       x
157;;  HCRO                                x       x
158;;  ID                  x       x       x       x
159;;  IDCAP                               x       x
160;;  IDLINK                      x       x       x
161;;  IDREF               x       x       x       x
162;;  IDREFCAP                            x       x
163;;  IDREFS              x       x       x       x
164;;  IGNORE              x       x       x       x
165;;  IMPLIED                             x       x
166;;  IMPLICIT                            x       x
167;;  IMPLYDEF                            x       x
168;;  INCLUDE             x       x       x       x
169;;  INITIAL                             x       x
170;;  INSTANCE                            x       x
171;;  INTEGRAL                            x       x
172;;  INTERNAL                            x       x
173;;  ISO 8879-1986                       x       x
174;;  ISO 8879:1986                       x       x
175;;  KEEPRSRE                            x       x
176;;  LCNMCHAR                            x       x
177;;  LCNMSTRT                            x       x
178;;  LINK                                x       x
179;;  LINKTYPE                            x       x
180;;  LIT                                 x       x
181;;  LITA                                x       x
182;;  LITLEN                              x       x
183;;  LKNMCAP                             x       x
184;;  LKSETCAP                            x       x
185;;  MAPCAP                              x       x
186;;  MD                                  x       x
187;;  MDC                                 x       x
188;;  MDO                                 x       x
189;;  MINIMIZE                            x
190;;  MINUS                               x       x
191;;  MODEL                                       x
192;;  MSICHAR                             x
193;;  MSOCHAR                             x
194;;  MSSCHAR                             x
195;;  MS                                  x       x
196;;  MSC                                 x       x
197;;  NAME                        x       x       x
198;;  NAMECASE                            x       x
199;;  NAMECHAR                            x       x
200;;  NAMELEN                             x       x
201;;  NAMES                       x       x       x
202;;  NAMESTRT                            x       x
203;;  NAMING                              x       x
204;;  NDATA               x       x       x       x
205;;  NET                                 x       x
206;;  NESTC                               x       x
207;;  NETENABL                            x       x
208;;  NMTOKEN             x       x       x       x
209;;  NMTOKENS            x       x       x       x
210;;  NOASSERT                            x       x
211;;  NONE                                x       x
212;;  NONSGML                     x       x       x
213;;  NORMSEP                             x       x
214;;  NOTATION            x       x       x       x
215;;  NO                                  x       x
216;;  NOTCAP                              x       x
217;;  NOTCHCAP                            x       x
218;;  NUMBER                      x       x       x
219;;  NUMBERS                     x       x       x
220;;  NUTOKEN                     x       x       x
221;;  NUTOKENS                    x       x       x
222;;  O                                   x       x
223;;  OMITNAME                            x       x
224;;  OMITTAG                             x
225;;  OPT                                 x       x
226;;  OR                                  x       x
227;;  OTHER                               x
228;;  PACK                                        x
229;;  PCDATA              x       x       x       x
230;;  PERO                                x       x
231;;  PI                          x       x       x
232;;  PIC                                 x       x
233;;  PILEN                               x       x
234;;  PIO                                 x       x
235;;  PLUS                                x       x
236;;  POSTLINK                            x       x
237;;  PUBLIC              x       x       x       x
238;;  QUANTITY                            x       x
239;;  RANK                                x       x
240;;  RCDATA                      x       x       x
241;;  RE                          x       x       x
242;;  REF                                 x       x
243;;  REFC                                x       x
244;;  REP                                 x       x
245;;  REQUIRED                            x       x
246;;  RESTORE                             x       x
247;;  RNI                                 x       x
248;;  RS                          x       x       x
249;;  SCOPE                               x
250;;  SDATA                       x       x       x
251;;  SDIF                                        x
252;;  SEEALSO                             x       x
253;;  SEPCHAR                             x
254;;  SEQ                                 x       x
255;;  SEQUENCE                            x
256;;  SGML                                x       x
257;;  SGMLREF                             x       x
258;;  SHORTREF                    x       x       x
259;;  SHORTTAG                            x       x
260;;  SHUNCHAR                            x       x
261;;  SIMPLE                              x       x
262;;  SPACE                               x       x
263;;  SRCNT                               x       x
264;;  SRLEN                               x       x
265;;  STAGO                               x       x
266;;  STARTTAG                    x       x       x
267;;  SUBDOC                      x       x       x
268;;  SWITCHES                            x       x
269;;  SYNTAX                              x       x
270;;  SYSTEM              x       x       x       x
271;;  TEMP                        x       x       x
272;;  TAGC                                x       x
273;;  TAGLEN                              x       x
274;;  TAGLVL                              x       x
275;;  TAB                                 x       x
276;;  TOTALCAP                            x       x
277;;  TYPE                                x       x
278;;  UCNMCHAR                            x       x
279;;  UCNMSTRT                            x       x
280;;  UNCLOSED                            x       x
281;;  UNPACK                                      x
282;;  UNUSED                              x       x
283;;  URN                                 x       x
284;;  USELINK                     x       x       x
285;;  USEMAP                      x       x       x
286;;  VALIDATE                                    x
287;;  VALIDITY                            x       x
288;;  VALUE                               x       x
289;;  VI                                  x       x
290;;  XML                 x
291;;  xml                 x
292;;  xml:lang            x
293;;  xml:link            x
294;;  xml:space           x
295;;  YES                                 x       x
296
297;;;; Code:
298(eval-and-compile
299  (autoload 'tdtd-make-regexp "tdtd-make-regexp"))
300(eval-and-compile
301  (autoload 'tdtd-make-regexps "tdtd-make-regexp"))
302
303;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
304;; Lists of reserved names
305;;
306;; These lists of reserved names are used later in the declarations
307;; for parts of font lock keyword variables or in the declarations for
308;; complete font lock keywords.
309;;
310;; The XML and SGML keyword lists are kept separate, despite their
311;; overlap, for two reasons: (1) making extra variables to hold the
312;; lists of common keywords would complicate things beyond even the
313;; current level; and (2) XML may yet change its reserved names or add
314;; new ones.
315;;
316;; The lists of reserved names are further divided into those that
317;; begin with an Emacs-Lisp non-word character, those that contain a
318;; non-word character, and those that don't contain any non-word
319;; characters.  This is necessary since the keyword regular
320;; expressions are bracketed by "\\b", which is necessary so the
321;; regular expressions produced by `tdtd-make-regexps' match on the longest
322;; possible string.  I have previously tried producing font lock
323;; keywords regular expressions for these reserved names by hand, but
324;; they're not particularly readable or maintainable when done by
325;; hand.
326;;
327;; There are several lists of reserved names for portions of SGML
328;; Declarations and System Declarations.  This reflects the
329;; productions and tables in the SGML standard, and it makes it easier
330;; to keep track of why everything is included.
331
332;; Common reserved name lists
333
334(defconst dtd-public-text-class-keywords
335  (list
336   "CAPACITY" "CHARSET" "DOCUMENT" "DTD" "ELEMENTS" "ENTITIES" "LPD"
337   "NONSGML" "NOTATION" "SHORTREF" "SUBDOC" "SYNTAX" "TEXT")
338  "Reserved names for Public Text Class in a Formal Public Identifier.")
339
340;; XML DTD reserved name lists
341
342(defconst dtd-xml-keyword-list-1
343  (list
344   "-//" "\+//" "//" "\+//IDN"
345   )
346  "XML reserved names strings that don't start with word character.")
347
348(defconst dtd-xml-keyword-list-1-pound
349  (list
350   "DEFAULT" "FIXED" "IMPLIED" "NOTATION"
351   "PCDATA" "REQUIRED"
352   )
353  "XML reserved names strings that don't start with word character.")
354
355(defconst dtd-xml-keyword-list-2
356  (list
357   "xml:lang" "xml:link" "xml:space"
358   )
359  "XML reserved names containing non-word characters.")
360
361(defconst dtd-xml-keyword-list-3
362  (append
363   dtd-public-text-class-keywords
364   (list
365    "ANY" "ATTLIST" "CDATA" "DOCTYPE" "DTD" "ELEMENT" "EMPTY"
366    "ENTITIES" "ENTITY" "ID" "IDREF" "IDREFS" "INCLUDE" "IGNORE"
367    "NDATA" "NMTOKEN" "NMTOKENS" "NOTATION" "NUTOKEN" "NUTOKENS"
368    "PUBLIC" "SYSTEM" "XML" "xml"
369    )
370   )
371  "Reserved names significant in XML.")
372
373;; SGML DTD reserved name lists
374
375(defconst dtd-sgml-keyword-list-1
376  (list
377   "-//" "\+//" "//" "\+//IDN"
378   "#ALL" "#CONREF" "#CURRENT" "#DEFAULT"
379   "#FIXED" "#IMPLICIT" "#IMPLIED" "#INITIAL" "#NOTATION" "#PCDATA"
380   "#POSTLINK" "#REQUIRED" "#RESTORE" "#SIMPLE" "#USELINK"
381   )
382  "SGML reserved names and strings beginning with a non-word character.")
383
384
385(defconst dtd-sgml-keyword-list-2
386  (list
387   "ANY" "ATTLIST" "CDATA" "DATA" "DOCTYPE" "DTD" "ELEMENT" "EMPTY"
388   "ENTITIES" "ENTITY" "EXPLICIT" "ID" "IDLINK" "IDREF" "IDREFS"
389   "IMPLICIT" "LINKTYPE" "LINK" "NAME" "NAMECHAR" "NAMES" "NDATA"
390   "NMTOKEN" "NMTOKENS" "NOTATION" "NUMBER" "NUMBERS" "NUTOKEN"
391   "NUTOKENS" "POSTLINK" "PUBLIC" "RCDATA" "SDATA" "SHORTREF" "SIMPLE"
392   "SUBDOC" "SYSTEM" "TEMP" "USELINK" "USEMAP")
393  "SGML reserved names that do not contain any non-word characters.")
394
395;; SGML Declaration reserved name lists
396
397(defconst dtd-sgml-declaration-minimum-literal-keywords
398  (list
399   "ISO 8879:1986" "ISO 8879-1986" "ISO 8879:1986(ENR)"
400   "ISO 8879:1986(WWW)")
401  "Minimum literals at the start of an SGML Declaration.")
402
403(defconst dtd-delimiter-set-keywords
404  (append
405   ;; Non-shortref delimiters
406   (list
407    "AND" "COM" "CRO" "DSC" "DSO" "DTGC" "DTGO" "ERO" "ETAGO" "GRPC"
408    "GRPO" "LIT" "LITA" "MDC" "MDO" "MINUS" "MSC" "NET" "OPT" "OR"
409    "PERO" "PIC" "PIO" "PLUS" "REFC" "REP" "RNI" "SEQ"
410    "STAGO" "TAGC" "VI")
411   ;; Alphabetic short reference delimiters
412   (list "BB")
413   ;; Delimiters added with SGML TC2
414   (list "HCRO" "NESTC"))
415  "Reserved names for specifying delimiter set, including shortrefs."
416  )
417
418(defconst dtd-redefinable-reserved-name-keywords
419  (list
420   "ALL" "ANY" "ATTLIST" "CDATA" "CONREF" "CURRENT" "DEFAULT"
421   "DOCTYPE" "ELEMENT" "EMPTY" "ENDTAG" "ENTITIES" "ENTITY" "FIXED"
422   "ID" "IDLINK" "IDREF" "IDREFS" "IGNORE" "IMPLICIT" "IMPLIED"
423   "INCLUDE" "INITIAL" "LINK" "LINKTYPE" "MD" "MS" "NAME" "NAMES"
424   "NDATA" "NMTOKEN" "NMTOKENS" "NOTATION" "NUMBER" "NUMBERS"
425   "NUTOKEN" "NUTOKENS" "O" "PCDATA" "PI" "POSTLINK" "PUBLIC" "RCDATA"
426   "RE" "REQUIRED" "RESTORE" "RS" "SDATA" "SHORTREF" "SIMPLE" "SPACE"
427   "STARTTAG" "SUBDOC" "SYSTEM" "TEMP" "USELINK" "USEMAP")
428  "Reserved names that can be modified in NAMES portion of SGML Declaration.")
429
430(defconst dtd-quantity-set-keywords
431  (list
432   "ATTCNT" "ATTSPLEN" "BSEQLEN" "DTAGLEN" "DTEMPLEN" "ENTLVL"
433   "GRPCNT" "GRPGTCNT" "GRPLVL" "LITLEN" "NAMELEN" "NORMSEP"
434   "PILEN" "TAGLEN" "TAGLVL")
435  "Reserved names for specifying quantity set.")
436
437(defconst dtd-common-sgml-declaration-keywords
438  (list
439   "SGMLREF" "PUBLIC" "NONE" "NO" "YES")
440  "Reserved names common to multiple parts of an SGML Declaration.")
441
442(defconst dtd-charset-keywords
443  (list
444   "CHARSET" "BASESET" "DESCSET" "UNUSED")
445  "Reserved names used in describing the document character set.")
446
447(defconst dtd-capacity-set-keywords
448  (list
449   "CAPACITY" "TOTALCAP" "ENTCAP" "ENTCHCAP" "ELEMCAP" "GRPCAP"
450   "EXGRPCAP" "EXNMCAP" "ATTCAP" "ATTCHCAP" "AVGRPCAP" "NOTCAP"
451   "NOTCHCAP" "IDCAP" "IDREFCAP" "MAPCAP" "LKSETCAP" "LKNMCAP")
452  "Reserved names for specifying capacities.")
453
454(defconst dtd-concrete-syntax-scope-keywords
455  (list
456   "SCOPE" "DOCUMENT" "INSTANCE")
457  "Reserved names for specifying concrete syntax scope.")
458
459(defconst dtd-concrete-syntax-keywords
460  (append
461   (list
462    "SYNTAX" "SWITCHES")
463   (list
464    "SHUNCHAR" "CONTROLS")
465   (list
466    "FUNCTION" "RE" "RS" "SPACE" "FUNCHAR" "MSICHAR" "MSOCHAR"
467    "MSSCHAR" "SEPCHAR" "TAB")
468   (list
469    "NAMING" "LCNMSTRT" "UCNMSTRT" "NAMESTRT" "LCNMCHAR" "UCNMCHAR"
470    "NAMECHAR" "NAMECASE" "GENERAL" "ENTITY")
471   (append
472    (list
473     "DELIM" "GENERAL" "SHORTREF")
474    dtd-delimiter-set-keywords)
475   (append
476    (list
477     "NAMES")
478    dtd-redefinable-reserved-name-keywords)
479   (append
480    (list
481     "QUANTITY")
482    dtd-quantity-set-keywords))
483  "Reserved names in specifying a concrete syntax.")
484
485(defconst dtd-features-keywords
486  (append
487   (list
488    "FEATURES" "MINIMIZE" "DATATAG" "OMITTAG" "RANK" "SHORTTAG"
489    "LINK" "SIMPLE" "IMPLICIT" "EXPLICIT"
490    "OTHER" "CONCUR" "SUBDOC" "FORMAL")
491   ;; Reserved names added with SGML TC2
492   (list
493    "NETENABL" "IMMEDNET" "UNCLOSED" "ATTRIB" "OMITNAME" "VALUE"
494    "EMPTYNRM" "IMPLYDEF" "URN" "KEEPRSRE" "VALIDITY" "NOASSERT" "TYPE"
495    "REF" "INTERNAL" "INTEGRAL" "SEEALSO"))
496  "Reserved names in specifying SGML feature use.")
497
498(defconst dtd-appinfo-keywords
499  (list
500   "APPINFO")
501  "Reserved names in specifying application-specific information.")
502
503;; System Declaration reserved name lists
504
505(defconst dtd-system-declaration-keyword-list-1
506  (list
507   "-//" "\+//" "//" "\+//IDN")
508  "System Declaration reserved names beginning with a non-word character.")
509
510(defconst dtd-concrete-syntax-changes-keywords
511  (list
512   "CHANGES" "SWITCES" "DELIMLEN" "SEQUENCE" "SRCNT" "SRLEN")
513  "Reserved names for concrete syntax changes in System Declaration.")
514
515(defconst dtd-validation-services-keywords
516  (list
517   "VALIDATE" "GENERAL" "MODEL" "EXCLUDE" "CAPACITY" "NONSGML" "SGML"
518   "FORMAL")
519  "Reserved names for validation services in System Declaration.")
520
521(defconst dtd-sdif-support-keywords
522  (list
523   "ASN1" "PACK" "SDIF" "UNPACK")
524  "Reserved names for SDIF support in System Declaration.")
525
526;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
527;; Reusable portions of keyword variable declarations
528
529;; These are lists of patterns plus face assignments that can be
530;; plugged into the definition of the font lock keywords
531
532(defvar dtd-comment-declaration-keywords
533  (list
534   ;;
535   ;; XML comment and one style of SGML comment
536   ;;
537   ;; SGML-style comments within declarations are covered by
538   ;; a separate pattern that is not included in the XML font lock
539   ;; keywords.
540   ;;
541   ;; Put comment patterns first so they mask any declarations
542   ;; that might be inside the comment.
543   ;;
544   '("<!--[^-]*\\(-[^-]+\\)*-->" . font-lock-comment-face)
545   )
546  "XML comment and one style of SGML comment keywords.")
547
548(defvar dtd-comment-in-declaration-keywords
549  (list
550   ;;
551   ;; SGML-only comment within a declaration
552   ;;
553   '("--[^-]*\\(-[^-]+\\)*--" . font-lock-comment-face)
554   )
555  "SGML-only comment within a declaration keywords.")
556
557(defvar dtd-entity-reference-keywords
558  (list
559   ;;
560   ;; Entity references
561   ;; These come early so entity references as the names in element, etc.
562   ;; declarations retain their colour and don't get turned into
563   ;; font-lock-variable-name-face.  E.g:
564   ;; <!ENTITY % %entity; "..." >
565   ;;
566   '("[%&][^; \t]+;" . font-lock-reference-face)
567   )
568  "Font lock keywords pattern matching an entity reference.")
569
570(defvar dtd-common-font-lock-keywords-1
571  (append
572   dtd-comment-declaration-keywords
573   dtd-entity-reference-keywords
574   (list
575    ;;
576    ;; Lump together attribute, entity, and notation declarations
577    ;;
578    '("\\(<!\\(ATTLIST\\|ENTITY\\(\\s-+%\\|\\)\\|NOTATION\\)\\)\\s-+\\(\\S-+\\)[^>]+\\(>\\)"
579      (1 font-lock-keyword-face)
580      (4 font-lock-variable-name-face)
581      (5 font-lock-keyword-face))
582    ;;
583    ;; Doctype declaration
584    ;;
585    '("\\(<!DOCTYPE\\)\\s-+\\([^[]+\\)\\s-+\\(\\[\\)"
586      (1 font-lock-keyword-face)
587      (2 font-lock-variable-name-face)
588      (3 font-lock-keyword-face))
589    ;;
590    ;; XML element declaration and SGML element declaration without
591    ;; minimisation parameters
592    ;;
593    '("\\(<!ELEMENT\\)\\s-+\\([^ \t()|]+\\)\\s-+[^>]+\\(>\\)"
594      (1 font-lock-keyword-face)
595      (2 font-lock-variable-name-face)
596      (3 font-lock-keyword-face))
597    ;;
598    ;; Marked section start
599    ;;
600    '("\\(<!\\[\\)[^[]*\\(\\[\\)"
601      (1 font-lock-keyword-face)
602      (2 font-lock-keyword-face))
603    )
604   )
605  "Font lock keyword patterns common to XML and SGML DTDs to apply first.")
606
607(defvar dtd-common-font-lock-keywords-2
608  (list
609   ;;
610   ;; Declaration subset close and markup delimiter close
611   ;;
612   '("\\(\\]?\\]\\)\\s-*\\(>\\)"
613     (1 font-lock-keyword-face)
614     (2 font-lock-keyword-face))
615   ;;
616   ;; Mark the start and end of literals, but don't do anything to their
617   ;; contents
618   ;;
619   '("\\('\\)[^']*\\('\\)"
620     (1 font-lock-string-face)
621     (2 font-lock-string-face))
622   '("\\(\"\\)[^\"]*\\(\"\\)"
623     (1 font-lock-string-face)
624     (2 font-lock-string-face))
625   ;;
626   ;; Connectors
627   ;;
628   '("[,()|&]" . font-lock-function-name-face)
629   ;;
630   ;; Occurrence indicators
631   ;;
632   '("[+*?]" . font-lock-string-face)
633   ;;
634   )
635  "Common DTD font lock keyword patterns to apply last.")
636
637(defvar dtd-sgml-dtd-keywords
638  (list
639   ;;
640   ;; Lump together shortref and usemap declarations
641   ;;
642   '("\\(<!\\(SHORTREF\\|USEMAP\\)\\)\\s-+\\(\\S-+\\)[^>]+\\(>\\)"
643         (1 font-lock-keyword-face)
644         (3 font-lock-variable-name-face)
645         (4 font-lock-keyword-face))
646   ;;
647   ;; SGML element declaration
648   ;;
649   ;; Only match on same case of "O", i.e. "o o" or "O O", if both
650   ;; start-tag and end-tag are omissible.
651   ;;
652   '("\\(<!ELEMENT\\)\\s-+\\([^ \t()|]+\\)\\s-+\\(o\\s-+o\\|O\\s-+O\\|-\\s-+[oO]\\|[oO]\\s-+-\\)\\s-+[^>]+\\(>\\)"
653         (1 font-lock-keyword-face)
654         (2 font-lock-variable-name-face)
655         (3 font-lock-keyword-face)
656         (4 font-lock-keyword-face))
657   ;;
658   ;; Put exclusions in a face that will stand out
659   ;;
660   '("\\(\\(-\\|+\\)(\\)[^)]*\\()\\)"
661     (1 font-lock-variable-name-face)
662     (3 font-lock-variable-name-face))
663   ;;
664   ;; Implicit Link Specification
665   ;;
666   '("\\(<!LINKTYPE\\)\\s-+\\([^ \t]+\\)\\s-+\\([^ \t]+\\)\\s-+\\(\\#IMPLIED\\)[ \t\n]*\\(\\[\\)"
667         (1 font-lock-keyword-face)
668         (2 font-lock-variable-name-face)
669         (3 font-lock-variable-name-face)
670         (4 font-lock-keyword-face)
671         (5 font-lock-keyword-face))
672   ;;
673   ;; Explicit Link Specification
674   ;;
675   '("\\(<!LINKTYPE\\)\\s-+\\([^ \t]+\\)\\s-+\\([^ \t]+\\)\\s-+\\([^ \t]+\\)\\s-*\\(\\[\\)"
676         (1 font-lock-keyword-face)
677         (2 font-lock-variable-name-face)
678         (3 font-lock-variable-name-face)
679         (4 font-lock-type-face)
680         (5 font-lock-keyword-face))
681   ;;
682   ;; IDLINK link, will appear within an implicit or explicit link
683   ;; declaration
684   ;;
685   '("\\(<!IDLINK\\)\\b[^>]+\\(>\\)"
686         (1 font-lock-keyword-face)
687         (2 font-lock-keyword-face))
688   ;;
689   ;; SGML Processing instruction
690   ;;
691   '("\\(<\\?\\)\\([^ \t>]+\\)\\s-*[^>]*\\(>\\)"
692     (1 font-lock-keyword-face)
693     (2 font-lock-variable-name-face)
694     (3 font-lock-keyword-face))
695   )
696  "Font lock keyword patterns for declarations specific to SGML DTDs.")
697
698;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
699;; Complete font lock keywords variable declarations
700
701;; XML DTDs
702(defvar dtd-xml-font-lock-keywords
703  (append
704   dtd-common-font-lock-keywords-1
705   (list
706    ;;
707    ;; Reserved XML Processing instruction
708    ;;
709    ;; An 'XML Declaration' requires the version information, but a
710    ;; 'Text Declaration' does not, therefore don't require the version
711    ;; information.
712    '(
713      "\\(<\\?\\)\\(xml\\)\\(\\s-+version\\s-*=\\s-*\\('[^']+'\\|\"[^\"]+\"\\)\\)?\\(\\s-+encoding\\s-*=\\s-*\\('[^']+'\\|\"[^\"]+\"\\)\\)?\\(\\s-+standalone\\s-*=\\s-*\\('\\(yes\\|no\\)'\\|\"\\(yes\\|no\\)\"\\)\\)?\\s-*\\(\\?>\\)"
714      (1 font-lock-keyword-face)
715      (2 font-lock-type-face nil)
716      (3 font-lock-type-face nil t)
717      (5 font-lock-type-face nil t)
718      (7 font-lock-type-face nil t)
719      (11 font-lock-keyword-face))
720    ;;
721    ;; Non-reserved XML Processing instruction
722    ;; Any XML PI that doesn't start with "<?xml"
723    ;;
724    '(
725      "\\(<\\?\\)\\([^ \t?>]+\\)\\s-*\\([^?>]\\|\\?[^>]\\|>[^\n\r]\\)*\\(\\?>\\)"
726      (1 font-lock-keyword-face)
727      (2 font-lock-variable-name-face)
728      (4 font-lock-keyword-face))
729    ;;
730    ;; Keywords starting with a non-word character
731    ;;
732    (list
733     (concat
734      (regexp-opt
735       dtd-xml-keyword-list-1
736       t)
737      "\\b")
738     (list 1 font-lock-type-face))
739
740    (list
741     (concat
742      "\\(#"
743      (regexp-opt
744       dtd-xml-keyword-list-1-pound
745       t)
746      "\\)\\b")
747     (list 1 font-lock-type-face))
748
749    ;; Stupidity because I haven't found a better separator than "\\b"
750    ;; and the ":" in "xml:link", etc., counts as a "\\b" so "xml:link"
751    ;; can't be in the same keyword list as "xml".
752    ;;
753    ;; The alternative is constructing the regular expression by hand,
754    ;; which I've done before, but using `tdtd-make-regexps' should make more
755    ;; readable code.
756    (list
757     (concat
758      "\\b"
759      (regexp-opt dtd-xml-keyword-list-2 t)
760      "\\b")
761     (list 1 font-lock-type-face))
762
763    (list
764     (concat
765      "\\b"
766      (regexp-opt dtd-xml-keyword-list-3 t)
767      "\\b")
768     (list 1 font-lock-type-face))
769    )
770   dtd-common-font-lock-keywords-2
771   )
772  "Font lock keywords for use in XML DTDs.")
773
774;; SGML DTDs
775(defvar dtd-sgml-font-lock-keywords
776  (append
777   dtd-comment-declaration-keywords
778   dtd-comment-in-declaration-keywords
779   dtd-common-font-lock-keywords-1
780   dtd-sgml-dtd-keywords
781   (list
782    ;;
783    ;; Keywords
784    (tdtd-make-regexps
785     (list dtd-sgml-keyword-list-1
786           font-lock-type-face)
787     "\\b")
788    ;;
789    (tdtd-make-regexps "\\b"
790                       (list dtd-sgml-keyword-list-2
791                             font-lock-type-face)
792                       "\\b")
793    )
794   dtd-common-font-lock-keywords-2
795   )
796  "Font lock keywords for SGML DTDs.")
797
798;; SGML Declarations and SGML DTDs (since one can follow the other)
799(defvar dtd-decl-font-lock-keywords
800  (append
801   dtd-comment-in-declaration-keywords
802   dtd-common-font-lock-keywords-1
803   (list
804    ;;
805    ;; SGML Declaration start and end
806    ;;
807    '("\\(<!SGML\\)\\s-+\\([^>]\\|>[^$]\\)+\\(>$\\)"
808      (1 font-lock-keyword-face)
809      (3 font-lock-keyword-face))
810    ;;
811    ;; Keywords
812    (tdtd-make-regexps "\\b"
813                       (list
814                        (append
815                         dtd-common-sgml-declaration-keywords
816                         dtd-charset-keywords
817                         dtd-capacity-set-keywords
818                         dtd-concrete-syntax-scope-keywords
819                         dtd-concrete-syntax-keywords
820                         dtd-features-keywords
821                         dtd-appinfo-keywords
822                         dtd-public-text-class-keywords)
823                        font-lock-type-face)
824                       "\\b")
825    ;;
826    ;; Minimum literal keywords
827    ;;
828    (tdtd-make-regexps (list
829                        dtd-sgml-declaration-minimum-literal-keywords
830                        font-lock-type-face))
831    ;;
832    ;; Reserved names beginning with a non-word characters
833    ;;
834    (tdtd-make-regexps
835     (list dtd-xml-keyword-list-1
836           font-lock-type-face)
837     "\\b")
838    )
839   dtd-common-font-lock-keywords-2
840   )
841  "Font lock keywords for SGML Declarations.")
842
843;; SGML System Declarations
844(defvar dtd-sys-decl-font-lock-keywords
845  (append
846   dtd-comment-in-declaration-keywords
847   dtd-entity-reference-keywords
848   (list
849    ;;
850    ;; System Declaration start and end
851    ;;
852    '("\\(<!SYSTEM\\)\\([^>]\\|>[^$]\\)+\\(>$\\)"
853      (1 font-lock-keyword-face)
854      (3 font-lock-keyword-face))
855    ;;
856    ;; Keywords
857    ;;
858    ;; Keywords starting with a non-word character
859    ;;
860    (tdtd-make-regexps
861     (list dtd-system-declaration-keyword-list-1
862           font-lock-type-face)
863     "\\b")
864    ;;
865    ;; Other keywords
866    ;;
867    (tdtd-make-regexps "\\b"
868                       (list
869                        (append
870                         dtd-common-sgml-declaration-keywords
871                         dtd-charset-keywords
872                         dtd-capacity-set-keywords
873                         dtd-concrete-syntax-scope-keywords
874                         dtd-concrete-syntax-changes-keywords
875                         dtd-concrete-syntax-keywords
876                         dtd-features-keywords
877                         dtd-validation-services-keywords
878                         dtd-sdif-support-keywords
879                         dtd-public-text-class-keywords)
880                        font-lock-type-face)
881                       "\\b")
882    ;;
883    ;; Minimum literal keywords
884    ;;
885    (tdtd-make-regexps (list
886                        dtd-sgml-declaration-minimum-literal-keywords
887                        font-lock-type-face))
888    ;;
889    )
890   dtd-common-font-lock-keywords-2
891   )
892  "Font lock keywords for System Declarations.")
893
894(defun dtd-make-tdtd-font ()
895  "Generate the file \"tdtd-font.el\"."
896  (interactive)
897  (find-file "tdtd-font.el")
898  (kill-region (point-min) (point-max))
899  (insert ";;;; tdtd-font.el --- Font-lock keywords for Tony's DTD mode\n")
900  (insert ";; $\Id$\n")
901  (insert ";; $\Name$\n")
902  (insert ";;\n")
903  (insert ";; Copyright (C) 1999, 2001 Tony Graham\n")
904  (insert ";;\n")
905  (insert ";; Author: Tony Graham <tkg@menteith.com>\n")
906  (insert "\n")
907  (insert ";; Generated by tdtd-font-maker.el\n")
908  (insert ";; Do not modify this file.  Make changes in tdtd-font-maker.el\n")
909  (insert ";; and regenerate.\n")
910  (insert "\n")
911  (insert ";;; This file is not part of GNU Emacs.\n")
912  (insert "\n")
913  (insert ";; This program is free software; you can redistribute it and/or\n")
914  (insert ";; modify it under the terms of the GNU General Public License\n")
915  (insert ";; as published by the Free Software Foundation; either version 2\n")
916  (insert ";; of the License, or (at your option) any later version.\n")
917  (insert ";;\n")
918  (insert ";; This program is distributed in the hope that it will be useful,\n")
919  (insert ";; but WITHOUT ANY WARRANTY; without even the implied warranty of\n")
920  (insert ";; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n")
921  (insert ";; GNU General Public License for more details.\n")
922  (insert ";;\n")
923  (insert ";; You should have received a copy of the GNU General Public License\n")
924  (insert ";; along with this program; if not, write to the Free Software\n")
925  (insert ";; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n")
926  (insert "\n")
927  (insert ";; Send bugs to tdtd-bug@menteith.com\n")
928  (insert "\n\n")
929  (insert (format "(defvar dtd-sgml-font-lock-keywords\n  '%s)\n\n"
930                  (dtd-make-safe-var-def dtd-sgml-font-lock-keywords)))
931  (insert (format "(defvar dtd-xml-font-lock-keywords\n  '%s)\n\n"
932                  (dtd-make-safe-var-def dtd-xml-font-lock-keywords)))
933  (insert (format "(defvar dtd-decl-font-lock-keywords\n  '%s)\n\n"
934                  (dtd-make-safe-var-def dtd-decl-font-lock-keywords)))
935  (insert (format "(defvar dtd-sys-decl-font-lock-keywords\n  '%s)\n\n"
936                  (dtd-make-safe-var-def dtd-sys-decl-font-lock-keywords)))
937  (insert "(provide 'tdtd-font)\n")
938  ;; Don't bother saving a backup
939  (setq backup-inhibited t)
940  (save-buffer)
941  (kill-buffer (current-buffer)))
942
943(defun dtd-make-safe-var-def (var)
944  "Tidy up a variable's definition so it's safe to output in a defun."
945  (let ((var-string (format "%S" var)))
946    (while (string-match "\t" var-string)
947      (setq var-string (replace-match "\\t" nil t var-string)))
948    (while (string-match "\n" var-string)
949      (setq var-string (replace-match "\\n" nil t var-string)))
950    (while (string-match "\r" var-string)
951      (setq var-string (replace-match "\\r" nil t var-string)))
952    (format "%s" var-string)))
953
954(provide 'tdtd-font-maker)
Note: See TracBrowser for help on using the browser.