7
|
1 " Vim syntax file
|
|
2 " Language: SGML
|
|
3 " Maintainer: Johannes Zellner <johannes@zellner.org>
|
|
4 " Last Change: Tue, 27 Apr 2004 15:05:21 CEST
|
|
5 " Filenames: *.sgml,*.sgm
|
2034
|
6 " $Id: sgml.vim,v 1.1 2004/06/13 17:52:57 vimboss Exp $
|
7
|
7
|
|
8 " For version 5.x: Clear all syntax items
|
|
9 " For version 6.x: Quit when a syntax file was already loaded
|
|
10 if version < 600
|
|
11 syntax clear
|
|
12 elseif exists("b:current_syntax")
|
|
13 finish
|
|
14 endif
|
|
15
|
|
16 let s:sgml_cpo_save = &cpo
|
|
17 set cpo&vim
|
|
18
|
|
19 syn case match
|
|
20
|
|
21 " mark illegal characters
|
|
22 syn match sgmlError "[<&]"
|
|
23
|
|
24
|
|
25 " unicode numbers:
|
|
26 " provide different highlithing for unicode characters
|
|
27 " inside strings and in plain text (character data).
|
|
28 "
|
|
29 " EXAMPLE:
|
|
30 "
|
|
31 " \u4e88
|
|
32 "
|
|
33 syn match sgmlUnicodeNumberAttr +\\u\x\{4}+ contained contains=sgmlUnicodeSpecifierAttr
|
|
34 syn match sgmlUnicodeSpecifierAttr +\\u+ contained
|
|
35 syn match sgmlUnicodeNumberData +\\u\x\{4}+ contained contains=sgmlUnicodeSpecifierData
|
|
36 syn match sgmlUnicodeSpecifierData +\\u+ contained
|
|
37
|
|
38
|
|
39 " strings inside character data or comments
|
|
40 "
|
|
41 syn region sgmlString contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=sgmlEntity,sgmlUnicodeNumberAttr display
|
|
42 syn region sgmlString contained start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=sgmlEntity,sgmlUnicodeNumberAttr display
|
|
43
|
|
44 " punctuation (within attributes) e.g. <tag sgml:foo.attribute ...>
|
|
45 " ^ ^
|
|
46 syn match sgmlAttribPunct +[:.]+ contained display
|
|
47
|
|
48
|
|
49 " no highlighting for sgmlEqual (sgmlEqual has no highlighting group)
|
|
50 syn match sgmlEqual +=+
|
|
51
|
|
52
|
|
53 " attribute, everything before the '='
|
|
54 "
|
|
55 " PROVIDES: @sgmlAttribHook
|
|
56 "
|
|
57 " EXAMPLE:
|
|
58 "
|
|
59 " <tag foo.attribute = "value">
|
|
60 " ^^^^^^^^^^^^^
|
|
61 "
|
|
62 syn match sgmlAttrib
|
|
63 \ +[^-'"<]\@<=\<[a-zA-Z0-9.:]\+\>\([^'">]\@=\|$\)+
|
|
64 \ contained
|
|
65 \ contains=sgmlAttribPunct,@sgmlAttribHook
|
|
66 \ display
|
|
67
|
|
68
|
|
69 " UNQUOTED value (not including the '=' -- sgmlEqual)
|
|
70 "
|
|
71 " PROVIDES: @sgmlValueHook
|
|
72 "
|
|
73 " EXAMPLE:
|
|
74 "
|
|
75 " <tag foo.attribute = value>
|
|
76 " ^^^^^
|
|
77 "
|
|
78 syn match sgmlValue
|
|
79 \ +[^"' =/!?<>][^ =/!?<>]*+
|
|
80 \ contained
|
|
81 \ contains=sgmlEntity,sgmlUnicodeNumberAttr,@sgmlValueHook
|
|
82 \ display
|
|
83
|
|
84
|
|
85 " QUOTED value (not including the '=' -- sgmlEqual)
|
|
86 "
|
|
87 " PROVIDES: @sgmlValueHook
|
|
88 "
|
|
89 " EXAMPLE:
|
|
90 "
|
|
91 " <tag foo.attribute = "value">
|
|
92 " ^^^^^^^
|
|
93 " <tag foo.attribute = 'value'>
|
|
94 " ^^^^^^^
|
|
95 "
|
|
96 syn region sgmlValue contained start=+"+ skip=+\\\\\|\\"+ end=+"+
|
|
97 \ contains=sgmlEntity,sgmlUnicodeNumberAttr,@sgmlValueHook
|
|
98 syn region sgmlValue contained start=+'+ skip=+\\\\\|\\'+ end=+'+
|
|
99 \ contains=sgmlEntity,sgmlUnicodeNumberAttr,@sgmlValueHook
|
|
100
|
|
101
|
|
102 " value, everything after (and including) the '='
|
|
103 " no highlighting!
|
|
104 "
|
|
105 " EXAMPLE:
|
|
106 "
|
|
107 " <tag foo.attribute = "value">
|
|
108 " ^^^^^^^^^
|
|
109 " <tag foo.attribute = value>
|
|
110 " ^^^^^^^
|
|
111 "
|
|
112 syn match sgmlEqualValue
|
|
113 \ +=\s*[^ =/!?<>]\++
|
|
114 \ contained
|
|
115 \ contains=sgmlEqual,sgmlString,sgmlValue
|
|
116 \ display
|
|
117
|
|
118
|
|
119 " start tag
|
|
120 " use matchgroup=sgmlTag to skip over the leading '<'
|
|
121 " see also sgmlEmptyTag below.
|
|
122 "
|
|
123 " PROVIDES: @sgmlTagHook
|
|
124 "
|
|
125 syn region sgmlTag
|
|
126 \ matchgroup=sgmlTag start=+<[^ /!?"']\@=+
|
|
127 \ matchgroup=sgmlTag end=+>+
|
|
128 \ contained
|
|
129 \ contains=sgmlError,sgmlAttrib,sgmlEqualValue,@sgmlTagHook
|
|
130
|
|
131
|
|
132 " tag content for empty tags. This is the same as sgmlTag
|
|
133 " above, except the `matchgroup=sgmlEndTag for highlighting
|
|
134 " the end '/>' differently.
|
|
135 "
|
|
136 " PROVIDES: @sgmlTagHook
|
|
137 "
|
|
138 syn region sgmlEmptyTag
|
|
139 \ matchgroup=sgmlTag start=+<[^ /!?"']\@=+
|
|
140 \ matchgroup=sgmlEndTag end=+/>+
|
|
141 \ contained
|
|
142 \ contains=sgmlError,sgmlAttrib,sgmlEqualValue,@sgmlTagHook
|
|
143
|
|
144
|
|
145 " end tag
|
|
146 " highlight everything but not the trailing '>' which
|
|
147 " was already highlighted by the containing sgmlRegion.
|
|
148 "
|
|
149 " PROVIDES: @sgmlTagHook
|
|
150 " (should we provide a separate @sgmlEndTagHook ?)
|
|
151 "
|
|
152 syn match sgmlEndTag
|
|
153 \ +</[^ /!?>"']\+>+
|
|
154 \ contained
|
|
155 \ contains=@sgmlTagHook
|
|
156
|
|
157
|
|
158 " [-- SGML SPECIFIC --]
|
|
159
|
|
160 " SGML specific
|
|
161 " tag content for abbreviated regions
|
|
162 "
|
|
163 " PROVIDES: @sgmlTagHook
|
|
164 "
|
|
165 syn region sgmlAbbrTag
|
|
166 \ matchgroup=sgmlTag start=+<[^ /!?"']\@=+
|
|
167 \ matchgroup=sgmlTag end=+/+
|
|
168 \ contained
|
|
169 \ contains=sgmlError,sgmlAttrib,sgmlEqualValue,@sgmlTagHook
|
|
170
|
|
171
|
|
172 " SGML specific
|
|
173 " just highlight the trailing '/'
|
|
174 syn match sgmlAbbrEndTag +/+
|
|
175
|
|
176
|
|
177 " SGML specific
|
|
178 " abbreviated regions
|
|
179 "
|
|
180 " No highlighing, highlighing is done by contained elements.
|
|
181 "
|
|
182 " PROVIDES: @sgmlRegionHook
|
|
183 "
|
|
184 " EXAMPLE:
|
|
185 "
|
|
186 " <bold/Im Anfang war das Wort/
|
|
187 "
|
|
188 syn match sgmlAbbrRegion
|
|
189 \ +<[^/!?>"']\+/\_[^/]\+/+
|
|
190 \ contains=sgmlAbbrTag,sgmlAbbrEndTag,sgmlCdata,sgmlComment,sgmlEntity,sgmlUnicodeNumberData,@sgmlRegionHook
|
|
191
|
|
192 " [-- END OF SGML SPECIFIC --]
|
|
193
|
|
194
|
|
195 " real (non-empty) elements. We cannot do syntax folding
|
|
196 " as in xml, because end tags may be optional in sgml depending
|
|
197 " on the dtd.
|
|
198 " No highlighing, highlighing is done by contained elements.
|
|
199 "
|
|
200 " PROVIDES: @sgmlRegionHook
|
|
201 "
|
|
202 " EXAMPLE:
|
|
203 "
|
|
204 " <tag id="whoops">
|
|
205 " <!-- comment -->
|
|
206 " <another.tag></another.tag>
|
|
207 " <another.tag/>
|
|
208 " some data
|
|
209 " </tag>
|
|
210 "
|
|
211 " SGML specific:
|
|
212 " compared to xmlRegion:
|
|
213 " - removed folding
|
|
214 " - added a single '/'in the start pattern
|
|
215 "
|
|
216 syn region sgmlRegion
|
|
217 \ start=+<\z([^ /!?>"']\+\)\(\(\_[^/>]*[^/!?]>\)\|>\)+
|
|
218 \ end=+</\z1>+
|
|
219 \ contains=sgmlTag,sgmlEndTag,sgmlCdata,@sgmlRegionCluster,sgmlComment,sgmlEntity,sgmlUnicodeNumberData,@sgmlRegionHook
|
|
220 \ keepend
|
|
221 \ extend
|
|
222
|
|
223
|
|
224 " empty tags. Just a container, no highlighting.
|
|
225 " Compare this with sgmlTag.
|
|
226 "
|
|
227 " EXAMPLE:
|
|
228 "
|
|
229 " <tag id="lola"/>
|
|
230 "
|
|
231 " TODO use sgmlEmptyTag intead of sgmlTag
|
|
232 syn match sgmlEmptyRegion
|
|
233 \ +<[^ /!?>"']\(\_[^"'<>]\|"\_[^"]*"\|'\_[^']*'\)*/>+
|
|
234 \ contains=sgmlEmptyTag
|
|
235
|
|
236
|
|
237 " cluster which contains the above two elements
|
|
238 syn cluster sgmlRegionCluster contains=sgmlRegion,sgmlEmptyRegion,sgmlAbbrRegion
|
|
239
|
|
240
|
|
241 " &entities; compare with dtd
|
|
242 syn match sgmlEntity "&[^; \t]*;" contains=sgmlEntityPunct
|
|
243 syn match sgmlEntityPunct contained "[&.;]"
|
|
244
|
|
245
|
|
246 " The real comments (this implements the comments as defined by sgml,
|
|
247 " but not all sgml pages actually conform to it. Errors are flagged.
|
|
248 syn region sgmlComment start=+<!+ end=+>+ contains=sgmlCommentPart,sgmlString,sgmlCommentError,sgmlTodo
|
|
249 syn keyword sgmlTodo contained TODO FIXME XXX display
|
|
250 syn match sgmlCommentError contained "[^><!]"
|
|
251 syn region sgmlCommentPart contained start=+--+ end=+--+
|
|
252
|
|
253
|
|
254 " CData sections
|
|
255 "
|
|
256 " PROVIDES: @sgmlCdataHook
|
|
257 "
|
|
258 syn region sgmlCdata
|
|
259 \ start=+<!\[CDATA\[+
|
|
260 \ end=+]]>+
|
|
261 \ contains=sgmlCdataStart,sgmlCdataEnd,@sgmlCdataHook
|
|
262 \ keepend
|
|
263 \ extend
|
|
264 " using the following line instead leads to corrupt folding at CDATA regions
|
|
265 " syn match sgmlCdata +<!\[CDATA\[\_.\{-}]]>+ contains=sgmlCdataStart,sgmlCdataEnd,@sgmlCdataHook
|
|
266 syn match sgmlCdataStart +<!\[CDATA\[+ contained contains=sgmlCdataCdata
|
|
267 syn keyword sgmlCdataCdata CDATA contained
|
|
268 syn match sgmlCdataEnd +]]>+ contained
|
|
269
|
|
270
|
|
271 " Processing instructions
|
|
272 " This allows "?>" inside strings -- good idea?
|
|
273 syn region sgmlProcessing matchgroup=sgmlProcessingDelim start="<?" end="?>" contains=sgmlAttrib,sgmlEqualValue
|
|
274
|
|
275
|
|
276 " DTD -- we use dtd.vim here
|
|
277 syn region sgmlDocType matchgroup=sgmlDocTypeDecl start="\c<!DOCTYPE"he=s+2,rs=s+2 end=">" contains=sgmlDocTypeKeyword,sgmlInlineDTD,sgmlString
|
|
278 syn keyword sgmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM
|
|
279 syn region sgmlInlineDTD contained start="\[" end="]" contains=@sgmlDTD
|
|
280 syn include @sgmlDTD <sfile>:p:h/dtd.vim
|
|
281
|
|
282
|
|
283 " synchronizing
|
|
284 " TODO !!! to be improved !!!
|
|
285
|
|
286 syn sync match sgmlSyncDT grouphere sgmlDocType +\_.\(<!DOCTYPE\)\@=+
|
|
287 " syn sync match sgmlSyncDT groupthere NONE +]>+
|
|
288
|
|
289 syn sync match sgmlSync grouphere sgmlRegion +\_.\(<[^ /!?>"']\+\)\@=+
|
|
290 " syn sync match sgmlSync grouphere sgmlRegion "<[^ /!?>"']*>"
|
|
291 syn sync match sgmlSync groupthere sgmlRegion +</[^ /!?>"']\+>+
|
|
292
|
|
293 syn sync minlines=100
|
|
294
|
|
295
|
|
296 " The default highlighting.
|
|
297 hi def link sgmlTodo Todo
|
|
298 hi def link sgmlTag Function
|
|
299 hi def link sgmlEndTag Identifier
|
|
300 " SGML specifig
|
|
301 hi def link sgmlAbbrEndTag Identifier
|
|
302 hi def link sgmlEmptyTag Function
|
|
303 hi def link sgmlEntity Statement
|
|
304 hi def link sgmlEntityPunct Type
|
|
305
|
|
306 hi def link sgmlAttribPunct Comment
|
|
307 hi def link sgmlAttrib Type
|
|
308
|
|
309 hi def link sgmlValue String
|
|
310 hi def link sgmlString String
|
|
311 hi def link sgmlComment Comment
|
|
312 hi def link sgmlCommentPart Comment
|
|
313 hi def link sgmlCommentError Error
|
|
314 hi def link sgmlError Error
|
|
315
|
|
316 hi def link sgmlProcessingDelim Comment
|
|
317 hi def link sgmlProcessing Type
|
|
318
|
|
319 hi def link sgmlCdata String
|
|
320 hi def link sgmlCdataCdata Statement
|
|
321 hi def link sgmlCdataStart Type
|
|
322 hi def link sgmlCdataEnd Type
|
|
323
|
|
324 hi def link sgmlDocTypeDecl Function
|
|
325 hi def link sgmlDocTypeKeyword Statement
|
|
326 hi def link sgmlInlineDTD Function
|
|
327 hi def link sgmlUnicodeNumberAttr Number
|
|
328 hi def link sgmlUnicodeSpecifierAttr SpecialChar
|
|
329 hi def link sgmlUnicodeNumberData Number
|
|
330 hi def link sgmlUnicodeSpecifierData SpecialChar
|
|
331
|
|
332 let b:current_syntax = "sgml"
|
|
333
|
|
334 let &cpo = s:sgml_cpo_save
|
|
335 unlet s:sgml_cpo_save
|
|
336
|
|
337 " vim: ts=8
|