blob: c0c3643dd29d5f3f9e7bde47781c9e127ee843a6 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" 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
Bram Moolenaar5c736222010-01-06 20:54:52 +01006" $Id: sgml.vim,v 1.1 2004/06/13 17:52:57 vimboss Exp $
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
8" For version 5.x: Clear all syntax items
9" For version 6.x: Quit when a syntax file was already loaded
10if version < 600
11 syntax clear
12elseif exists("b:current_syntax")
13 finish
14endif
15
16let s:sgml_cpo_save = &cpo
17set cpo&vim
18
19syn case match
20
21" mark illegal characters
22syn 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"
33syn match sgmlUnicodeNumberAttr +\\u\x\{4}+ contained contains=sgmlUnicodeSpecifierAttr
34syn match sgmlUnicodeSpecifierAttr +\\u+ contained
35syn match sgmlUnicodeNumberData +\\u\x\{4}+ contained contains=sgmlUnicodeSpecifierData
36syn match sgmlUnicodeSpecifierData +\\u+ contained
37
38
39" strings inside character data or comments
40"
41syn region sgmlString contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=sgmlEntity,sgmlUnicodeNumberAttr display
42syn region sgmlString contained start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=sgmlEntity,sgmlUnicodeNumberAttr display
43
44" punctuation (within attributes) e.g. <tag sgml:foo.attribute ...>
45" ^ ^
46syn match sgmlAttribPunct +[:.]+ contained display
47
48
49" no highlighting for sgmlEqual (sgmlEqual has no highlighting group)
50syn match sgmlEqual +=+
51
52
53" attribute, everything before the '='
54"
55" PROVIDES: @sgmlAttribHook
56"
57" EXAMPLE:
58"
59" <tag foo.attribute = "value">
60" ^^^^^^^^^^^^^
61"
62syn 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"
78syn 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"
96syn region sgmlValue contained start=+"+ skip=+\\\\\|\\"+ end=+"+
97 \ contains=sgmlEntity,sgmlUnicodeNumberAttr,@sgmlValueHook
98syn 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"
112syn 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"
125syn 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"
138syn 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"
152syn 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"
165syn 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 '/'
174syn 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"
188syn 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"
216syn 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
232syn match sgmlEmptyRegion
233 \ +<[^ /!?>"']\(\_[^"'<>]\|"\_[^"]*"\|'\_[^']*'\)*/>+
234 \ contains=sgmlEmptyTag
235
236
237" cluster which contains the above two elements
238syn cluster sgmlRegionCluster contains=sgmlRegion,sgmlEmptyRegion,sgmlAbbrRegion
239
240
241" &entities; compare with dtd
242syn match sgmlEntity "&[^; \t]*;" contains=sgmlEntityPunct
243syn 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.
248syn region sgmlComment start=+<!+ end=+>+ contains=sgmlCommentPart,sgmlString,sgmlCommentError,sgmlTodo
249syn keyword sgmlTodo contained TODO FIXME XXX display
250syn match sgmlCommentError contained "[^><!]"
251syn region sgmlCommentPart contained start=+--+ end=+--+
252
253
254" CData sections
255"
256" PROVIDES: @sgmlCdataHook
257"
258syn 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
266syn match sgmlCdataStart +<!\[CDATA\[+ contained contains=sgmlCdataCdata
267syn keyword sgmlCdataCdata CDATA contained
268syn match sgmlCdataEnd +]]>+ contained
269
270
271" Processing instructions
272" This allows "?>" inside strings -- good idea?
273syn region sgmlProcessing matchgroup=sgmlProcessingDelim start="<?" end="?>" contains=sgmlAttrib,sgmlEqualValue
274
275
276" DTD -- we use dtd.vim here
277syn region sgmlDocType matchgroup=sgmlDocTypeDecl start="\c<!DOCTYPE"he=s+2,rs=s+2 end=">" contains=sgmlDocTypeKeyword,sgmlInlineDTD,sgmlString
278syn keyword sgmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM
279syn region sgmlInlineDTD contained start="\[" end="]" contains=@sgmlDTD
280syn include @sgmlDTD <sfile>:p:h/dtd.vim
281
282
283" synchronizing
284" TODO !!! to be improved !!!
285
286syn sync match sgmlSyncDT grouphere sgmlDocType +\_.\(<!DOCTYPE\)\@=+
287" syn sync match sgmlSyncDT groupthere NONE +]>+
288
289syn sync match sgmlSync grouphere sgmlRegion +\_.\(<[^ /!?>"']\+\)\@=+
290" syn sync match sgmlSync grouphere sgmlRegion "<[^ /!?>"']*>"
291syn sync match sgmlSync groupthere sgmlRegion +</[^ /!?>"']\+>+
292
293syn sync minlines=100
294
295
296" The default highlighting.
297hi def link sgmlTodo Todo
298hi def link sgmlTag Function
299hi def link sgmlEndTag Identifier
300" SGML specifig
301hi def link sgmlAbbrEndTag Identifier
302hi def link sgmlEmptyTag Function
303hi def link sgmlEntity Statement
304hi def link sgmlEntityPunct Type
305
306hi def link sgmlAttribPunct Comment
307hi def link sgmlAttrib Type
308
309hi def link sgmlValue String
310hi def link sgmlString String
311hi def link sgmlComment Comment
312hi def link sgmlCommentPart Comment
313hi def link sgmlCommentError Error
314hi def link sgmlError Error
315
316hi def link sgmlProcessingDelim Comment
317hi def link sgmlProcessing Type
318
319hi def link sgmlCdata String
320hi def link sgmlCdataCdata Statement
321hi def link sgmlCdataStart Type
322hi def link sgmlCdataEnd Type
323
324hi def link sgmlDocTypeDecl Function
325hi def link sgmlDocTypeKeyword Statement
326hi def link sgmlInlineDTD Function
327hi def link sgmlUnicodeNumberAttr Number
328hi def link sgmlUnicodeSpecifierAttr SpecialChar
329hi def link sgmlUnicodeNumberData Number
330hi def link sgmlUnicodeSpecifierData SpecialChar
331
332let b:current_syntax = "sgml"
333
334let &cpo = s:sgml_cpo_save
335unlet s:sgml_cpo_save
336
337" vim: ts=8