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