3 " Maintainer: Johannes Zellner <johannes@zellner.org>
4 " Last Change: Tue, 27 Apr 2004 15:05:21 CEST
5 " Filenames: *.sgml,*.sgm
6 " $Id: sgml.vim,v 1.1 2004/06/13 17:52:57 vimboss Exp $
8 " For version 5.x: Clear all syntax items
9 " For version 6.x: Quit when a syntax file was already loaded
12 elseif exists("b:current_syntax")
16 let s:sgml_cpo_save = &cpo
21 " mark illegal characters
22 syn match sgmlError "[<&]"
26 " provide different highlithing for unicode characters
27 " inside strings and in plain text (character data).
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
39 " strings inside character data or comments
41 syn region sgmlString contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=sgmlEntity,sgmlUnicodeNumberAttr display
42 syn region sgmlString contained start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=sgmlEntity,sgmlUnicodeNumberAttr display
44 " punctuation (within attributes) e.g. <tag sgml:foo.attribute ...>
46 syn match sgmlAttribPunct +[:.]+ contained display
49 " no highlighting for sgmlEqual (sgmlEqual has no highlighting group)
50 syn match sgmlEqual +=+
53 " attribute, everything before the '='
55 " PROVIDES: @sgmlAttribHook
59 " <tag foo.attribute = "value">
63 \ +[^-'"<]\@<=\<[a-zA-Z0-9.:]\+\>\([^'">]\@=\|$\)+
65 \ contains=sgmlAttribPunct,@sgmlAttribHook
69 " UNQUOTED value (not including the '=' -- sgmlEqual)
71 " PROVIDES: @sgmlValueHook
75 " <tag foo.attribute = value>
79 \ +[^"' =/!?<>][^ =/!?<>]*+
81 \ contains=sgmlEntity,sgmlUnicodeNumberAttr,@sgmlValueHook
85 " QUOTED value (not including the '=' -- sgmlEqual)
87 " PROVIDES: @sgmlValueHook
91 " <tag foo.attribute = "value">
93 " <tag foo.attribute = 'value'>
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
102 " value, everything after (and including) the '='
107 " <tag foo.attribute = "value">
109 " <tag foo.attribute = value>
112 syn match sgmlEqualValue
115 \ contains=sgmlEqual,sgmlString,sgmlValue
120 " use matchgroup=sgmlTag to skip over the leading '<'
121 " see also sgmlEmptyTag below.
123 " PROVIDES: @sgmlTagHook
126 \ matchgroup=sgmlTag start=+<[^ /!?"']\@=+
127 \ matchgroup=sgmlTag end=+>+
129 \ contains=sgmlError,sgmlAttrib,sgmlEqualValue,@sgmlTagHook
132 " tag content for empty tags. This is the same as sgmlTag
133 " above, except the `matchgroup=sgmlEndTag for highlighting
134 " the end '/>' differently.
136 " PROVIDES: @sgmlTagHook
138 syn region sgmlEmptyTag
139 \ matchgroup=sgmlTag start=+<[^ /!?"']\@=+
140 \ matchgroup=sgmlEndTag end=+/>+
142 \ contains=sgmlError,sgmlAttrib,sgmlEqualValue,@sgmlTagHook
146 " highlight everything but not the trailing '>' which
147 " was already highlighted by the containing sgmlRegion.
149 " PROVIDES: @sgmlTagHook
150 " (should we provide a separate @sgmlEndTagHook ?)
155 \ contains=@sgmlTagHook
158 " [-- SGML SPECIFIC --]
161 " tag content for abbreviated regions
163 " PROVIDES: @sgmlTagHook
165 syn region sgmlAbbrTag
166 \ matchgroup=sgmlTag start=+<[^ /!?"']\@=+
167 \ matchgroup=sgmlTag end=+/+
169 \ contains=sgmlError,sgmlAttrib,sgmlEqualValue,@sgmlTagHook
173 " just highlight the trailing '/'
174 syn match sgmlAbbrEndTag +/+
178 " abbreviated regions
180 " No highlighing, highlighing is done by contained elements.
182 " PROVIDES: @sgmlRegionHook
186 " <bold/Im Anfang war das Wort/
188 syn match sgmlAbbrRegion
189 \ +<[^/!?>"']\+/\_[^/]\+/+
190 \ contains=sgmlAbbrTag,sgmlAbbrEndTag,sgmlCdata,sgmlComment,sgmlEntity,sgmlUnicodeNumberData,@sgmlRegionHook
192 " [-- END OF SGML SPECIFIC --]
195 " real (non-empty) elements. We cannot do syntax folding
196 " as in xml, because end tags may be optional in sgml depending
198 " No highlighing, highlighing is done by contained elements.
200 " PROVIDES: @sgmlRegionHook
206 " <another.tag></another.tag>
212 " compared to xmlRegion:
214 " - added a single '/'in the start pattern
216 syn region sgmlRegion
217 \ start=+<\z([^ /!?>"']\+\)\(\(\_[^/>]*[^/!?]>\)\|>\)+
219 \ contains=sgmlTag,sgmlEndTag,sgmlCdata,@sgmlRegionCluster,sgmlComment,sgmlEntity,sgmlUnicodeNumberData,@sgmlRegionHook
224 " empty tags. Just a container, no highlighting.
225 " Compare this with sgmlTag.
231 " TODO use sgmlEmptyTag intead of sgmlTag
232 syn match sgmlEmptyRegion
233 \ +<[^ /!?>"']\(\_[^"'<>]\|"\_[^"]*"\|'\_[^']*'\)*/>+
234 \ contains=sgmlEmptyTag
237 " cluster which contains the above two elements
238 syn cluster sgmlRegionCluster contains=sgmlRegion,sgmlEmptyRegion,sgmlAbbrRegion
241 " &entities; compare with dtd
242 syn match sgmlEntity "&[^; \t]*;" contains=sgmlEntityPunct
243 syn match sgmlEntityPunct contained "[&.;]"
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=+--+
256 " PROVIDES: @sgmlCdataHook
259 \ start=+<!\[CDATA\[+
261 \ contains=sgmlCdataStart,sgmlCdataEnd,@sgmlCdataHook
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
271 " Processing instructions
272 " This allows "?>" inside strings -- good idea?
273 syn region sgmlProcessing matchgroup=sgmlProcessingDelim start="<?" end="?>" contains=sgmlAttrib,sgmlEqualValue
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
284 " TODO !!! to be improved !!!
286 syn sync match sgmlSyncDT grouphere sgmlDocType +\_.\(<!DOCTYPE\)\@=+
287 " syn sync match sgmlSyncDT groupthere NONE +]>+
289 syn sync match sgmlSync grouphere sgmlRegion +\_.\(<[^ /!?>"']\+\)\@=+
290 " syn sync match sgmlSync grouphere sgmlRegion "<[^ /!?>"']*>"
291 syn sync match sgmlSync groupthere sgmlRegion +</[^ /!?>"']\+>+
293 syn sync minlines=100
296 " The default highlighting.
297 hi def link sgmlTodo Todo
298 hi def link sgmlTag Function
299 hi def link sgmlEndTag Identifier
301 hi def link sgmlAbbrEndTag Identifier
302 hi def link sgmlEmptyTag Function
303 hi def link sgmlEntity Statement
304 hi def link sgmlEntityPunct Type
306 hi def link sgmlAttribPunct Comment
307 hi def link sgmlAttrib Type
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
316 hi def link sgmlProcessingDelim Comment
317 hi def link sgmlProcessing Type
319 hi def link sgmlCdata String
320 hi def link sgmlCdataCdata Statement
321 hi def link sgmlCdataStart Type
322 hi def link sgmlCdataEnd Type
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
332 let b:current_syntax = "sgml"
334 let &cpo = s:sgml_cpo_save
335 unlet s:sgml_cpo_save