home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / syntax / sgml.vim < prev    next >
Encoding:
Text File  |  2003-05-04  |  8.8 KB  |  339 lines

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