sgml.vim 8.7 KB

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