2 " Language: DTD (Document Type Definition for XML)
3 " Maintainer: Johannes Zellner <johannes@zellner.org>
4 " Author and previous maintainer:
5 " Daniel Amyot <damyot@site.uottawa.ca>
6 " Last Change: Wed, 06 Jun 2001 14:07:20 +0200
8 " URL: http://www.zellner.org/vim/syntax/dtd.vim
11 " http://www.w3.org/TR/html40/
12 " http://www.w3.org/TR/NOTE-html-970421
15 " - improve synchronizing.
19 let __dtd_cpo_save__ = &cpo
22 if exists("b:current_syntax")
25 let s:dtd_cpo_save = &cpo
29 if !exists("dtd_ignore_case")
30 " I prefer having the case takes into consideration.
37 " the following line makes the opening <! and
38 " closing > highlighted using 'dtdFunction'.
39 syn region dtdTag matchgroup=dtdFunction
40 \ start=+<!+ end=+>+ matchgroup=NONE
41 \ contains=dtdTag,dtdTagName,dtdError,dtdComment,dtdString,dtdAttrType,dtdAttrDef,dtdEnum,dtdParamEntityInst,dtdParamEntityDecl,dtdCard
43 if !exists("dtd_no_tag_errors")
44 " mark everything as an error which starts with a <!
45 " and is not overridden later. If this is annoying,
46 " it can be switched off by setting the variable
48 syn region dtdError contained start=+<!+lc=2 end=+>+
51 " if this is a html like comment hightlight also
52 " the opening <! and the closing > as Comment.
53 syn region dtdComment start=+<![ \t]*--+ end=+-->+ contains=dtdTodo
57 syn region dtdComment contained start=+--+ end=+--+ contains=dtdTodo
60 " Start tags (keywords). This is contained in dtdFunction.
61 " Note that everything not contained here will be marked
63 syn match dtdTagName contained +<!\(ATTLIST\|DOCTYPE\|ELEMENT\|ENTITY\|NOTATION\|SHORTREF\|USEMAP\|\[\)+lc=2,hs=s+2
66 " wildcards and operators
67 syn match dtdCard contained "|"
68 syn match dtdCard contained ","
69 " evenutally overridden by dtdEntity
70 syn match dtdCard contained "&"
71 syn match dtdCard contained "?"
72 syn match dtdCard contained "\*"
73 syn match dtdCard contained "+"
75 " ...and finally, special cases.
76 syn match dtdCard "ANY"
77 syn match dtdCard "EMPTY"
79 if !exists("dtd_no_param_entities")
81 " highlight parameter entity declarations
82 " and instances. Note that the closing `;'
86 syn region dtdParamEntityInst oneline matchgroup=dtdParamEntityPunct
87 \ start="%[-_a-zA-Z0-9.]\+"he=s+1,rs=s+1
88 \ skip=+[-_a-zA-Z0-9.]+
90 \ matchgroup=NONE contains=dtdParamEntityPunct
91 syn match dtdParamEntityPunct contained "\."
94 " syn region dtdParamEntityDecl oneline matchgroup=dtdParamEntityDPunct start=+<!ENTITY % +lc=8 skip=+[-_a-zA-Z0-9.]+ matchgroup=NONE end="\>" contains=dtdParamEntityDPunct
95 syn match dtdParamEntityDecl +<!ENTITY % [-_a-zA-Z0-9.]*+lc=8 contains=dtdParamEntityDPunct
96 syn match dtdParamEntityDPunct contained "%\|\."
100 " &entities; compare with xml
101 syn match dtdEntity "&[^; \t]*;" contains=dtdEntityPunct
102 syn match dtdEntityPunct contained "[&.;]"
104 " Strings are between quotes
105 syn region dtdString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=dtdAttrDef,dtdAttrType,dtdEnum,dtdParamEntityInst,dtdEntity,dtdCard
106 syn region dtdString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=dtdAttrDef,dtdAttrType,dtdEnum,dtdParamEntityInst,dtdEntity,dtdCard
108 " Enumeration of elements or data between parenthesis
109 syn region dtdEnum matchgroup=dtdType start="(" end=")" matchgroup=NONE contains=dtdEnum,dtdParamEntityInst,dtdCard
112 syn keyword dtdAttrType NMTOKEN ENTITIES NMTOKENS ID CDATA
113 syn keyword dtdAttrType IDREF IDREFS
114 " ENTITY has to treated special for not overriding <!ENTITY
115 syn match dtdAttrType +[^!]\<ENTITY+
117 "Attribute Definitions
118 syn match dtdAttrDef "#REQUIRED"
119 syn match dtdAttrDef "#IMPLIED"
120 syn match dtdAttrDef "#FIXED"
123 " define some common keywords to mark TODO
124 " and important sections inside comments.
125 syn keyword dtdTodo contained TODO FIXME XXX
129 " Define the default highlighting.
130 " For version 5.7 and earlier: only when not done already
131 " For version 5.8 and later: only when an item doesn't have highlighting yet
132 if version >= 508 || !exists("did_dtd_syn_inits")
134 let did_dtd_syn_inits = 1
135 command -nargs=+ HiLink hi link <args>
137 command -nargs=+ HiLink hi def link <args>
140 " The default highlighting.
141 HiLink dtdFunction Function
144 HiLink dtdAttrType dtdType
145 HiLink dtdAttrDef dtdType
146 HiLink dtdConstant Constant
147 HiLink dtdString dtdConstant
148 HiLink dtdEnum dtdConstant
149 HiLink dtdCard dtdFunction
151 HiLink dtdEntity Statement
152 HiLink dtdEntityPunct dtdType
153 HiLink dtdParamEntityInst dtdConstant
154 HiLink dtdParamEntityPunct dtdType
155 HiLink dtdParamEntityDecl dtdType
156 HiLink dtdParamEntityDPunct dtdComment
158 HiLink dtdComment Comment
159 HiLink dtdTagName Statement
160 HiLink dtdError Error
167 let &cpo = __dtd_cpo_save__
168 unlet __dtd_cpo_save__
170 let &cpo = s:dtd_cpo_save
174 let b:current_syntax = "dtd"