blob: 0f80e199c0169006be0daae7f57f3712594f59dc [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
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: Tue, 27 Apr 2004 14:54:59 CEST
7" Filenames: *.dtd
8"
9" REFERENCES:
10" http://www.w3.org/TR/html40/
11" http://www.w3.org/TR/NOTE-html-970421
12"
13" TODO:
14" - improve synchronizing.
15
16if version < 600
17 syntax clear
18 let __dtd_cpo_save__ = &cpo
19 set cpo&
20else
21 if exists("b:current_syntax")
22 finish
23 endif
24 let s:dtd_cpo_save = &cpo
25 set cpo&vim
26endif
27
28if !exists("dtd_ignore_case")
29 " I prefer having the case takes into consideration.
30 syn case match
31else
32 syn case ignore
33endif
34
35
36" the following line makes the opening <! and
37" closing > highlighted using 'dtdFunction'.
38"
39" PROVIDES: @dtdTagHook
40"
41syn region dtdTag matchgroup=dtdFunction
42 \ start=+<!+ end=+>+ matchgroup=NONE
43 \ contains=dtdTag,dtdTagName,dtdError,dtdComment,dtdString,dtdAttrType,dtdAttrDef,dtdEnum,dtdParamEntityInst,dtdParamEntityDecl,dtdCard,@dtdTagHook
44
45if !exists("dtd_no_tag_errors")
46 " mark everything as an error which starts with a <!
47 " and is not overridden later. If this is annoying,
48 " it can be switched off by setting the variable
49 " dtd_no_tag_errors.
50 syn region dtdError contained start=+<!+lc=2 end=+>+
51endif
52
53" if this is a html like comment hightlight also
54" the opening <! and the closing > as Comment.
55syn region dtdComment start=+<![ \t]*--+ end=+-->+ contains=dtdTodo
56
57
58" proper DTD comment
59syn region dtdComment contained start=+--+ end=+--+ contains=dtdTodo
60
61
62" Start tags (keywords). This is contained in dtdFunction.
63" Note that everything not contained here will be marked
64" as error.
65syn match dtdTagName contained +<!\(ATTLIST\|DOCTYPE\|ELEMENT\|ENTITY\|NOTATION\|SHORTREF\|USEMAP\|\[\)+lc=2,hs=s+2
66
67
68" wildcards and operators
69syn match dtdCard contained "|"
70syn match dtdCard contained ","
71" evenutally overridden by dtdEntity
72syn match dtdCard contained "&"
73syn match dtdCard contained "?"
74syn match dtdCard contained "\*"
75syn match dtdCard contained "+"
76
77" ...and finally, special cases.
78syn match dtdCard "ANY"
79syn match dtdCard "EMPTY"
80
81if !exists("dtd_no_param_entities")
82
83 " highlight parameter entity declarations
84 " and instances. Note that the closing `;'
85 " is optional.
86
87 " instances
88 syn region dtdParamEntityInst oneline matchgroup=dtdParamEntityPunct
89 \ start="%[-_a-zA-Z0-9.]\+"he=s+1,rs=s+1
90 \ skip=+[-_a-zA-Z0-9.]+
91 \ end=";\|\>"
92 \ matchgroup=NONE contains=dtdParamEntityPunct
93 syn match dtdParamEntityPunct contained "\."
94
95 " declarations
96 " syn region dtdParamEntityDecl oneline matchgroup=dtdParamEntityDPunct start=+<!ENTITY % +lc=8 skip=+[-_a-zA-Z0-9.]+ matchgroup=NONE end="\>" contains=dtdParamEntityDPunct
97 syn match dtdParamEntityDecl +<!ENTITY % [-_a-zA-Z0-9.]*+lc=8 contains=dtdParamEntityDPunct
98 syn match dtdParamEntityDPunct contained "%\|\."
99
100endif
101
102" &entities; compare with xml
103syn match dtdEntity "&[^; \t]*;" contains=dtdEntityPunct
104syn match dtdEntityPunct contained "[&.;]"
105
106" Strings are between quotes
107syn region dtdString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=dtdAttrDef,dtdAttrType,dtdEnum,dtdParamEntityInst,dtdEntity,dtdCard
108syn region dtdString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=dtdAttrDef,dtdAttrType,dtdEnum,dtdParamEntityInst,dtdEntity,dtdCard
109
110" Enumeration of elements or data between parenthesis
111"
112" PROVIDES: @dtdEnumHook
113"
114syn region dtdEnum matchgroup=dtdType start="(" end=")" matchgroup=NONE contains=dtdEnum,dtdParamEntityInst,dtdCard,@dtdEnumHook
115
116"Attribute types
117syn keyword dtdAttrType NMTOKEN ENTITIES NMTOKENS ID CDATA
118syn keyword dtdAttrType IDREF IDREFS
119" ENTITY has to treated special for not overriding <!ENTITY
120syn match dtdAttrType +[^!]\<ENTITY+
121
122"Attribute Definitions
123syn match dtdAttrDef "#REQUIRED"
124syn match dtdAttrDef "#IMPLIED"
125syn match dtdAttrDef "#FIXED"
126
127syn case match
128" define some common keywords to mark TODO
129" and important sections inside comments.
130syn keyword dtdTodo contained TODO FIXME XXX
131
132syn sync lines=250
133
134" Define the default highlighting.
135" For version 5.7 and earlier: only when not done already
136" For version 5.8 and later: only when an item doesn't have highlighting yet
137if version >= 508 || !exists("did_dtd_syn_inits")
138 if version < 508
139 let did_dtd_syn_inits = 1
140 command -nargs=+ HiLink hi link <args>
141 else
142 command -nargs=+ HiLink hi def link <args>
143 endif
144
145 " The default highlighting.
146 HiLink dtdFunction Function
147 HiLink dtdTag Normal
148 HiLink dtdType Type
149 HiLink dtdAttrType dtdType
150 HiLink dtdAttrDef dtdType
151 HiLink dtdConstant Constant
152 HiLink dtdString dtdConstant
153 HiLink dtdEnum dtdConstant
154 HiLink dtdCard dtdFunction
155
156 HiLink dtdEntity Statement
157 HiLink dtdEntityPunct dtdType
158 HiLink dtdParamEntityInst dtdConstant
159 HiLink dtdParamEntityPunct dtdType
160 HiLink dtdParamEntityDecl dtdType
161 HiLink dtdParamEntityDPunct dtdComment
162
163 HiLink dtdComment Comment
164 HiLink dtdTagName Statement
165 HiLink dtdError Error
166 HiLink dtdTodo Todo
167
168 delcommand HiLink
169endif
170
171if version < 600
172 let &cpo = __dtd_cpo_save__
173 unlet __dtd_cpo_save__
174else
175 let &cpo = s:dtd_cpo_save
176 unlet s:dtd_cpo_save
177endif
178
179let b:current_syntax = "dtd"
180
181" vim: ts=8