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 / xml.vim < prev    next >
Encoding:
Text File  |  2003-05-24  |  7.0 KB  |  289 lines

  1. " Vim syntax file
  2. " Language:    XML
  3. " Maintainer:    Johannes Zellner <johannes@zellner.org>
  4. "        Author and previous maintainer:
  5. "        Paul Siegmann <pauls@euronet.nl>
  6. " Last Change:    Sat, 24 May 2003 13:12:45 CEST
  7. " Filenames:    *.xml
  8. " URL:        http://www.zellner.org/vim/syntax/xml.vim
  9. " $Id: xml.vim,v 1.41 2003/05/24 11:14:23 joze Exp $
  10.  
  11. " CREDITS:
  12. "   The original version was derived by Paul Siegmann from
  13. "   Claudio Fleiner's html.vim.
  14. "
  15. " REFERENCES:
  16. "   [1] http://www.w3.org/TR/2000/REC-xml-20001006
  17. "   [2] http://www.w3.org/XML/1998/06/xmlspec-report-19980910.htm
  18. "
  19. "   as <hirauchi@kiwi.ne.jp> pointed out according to reference [1]
  20. "
  21. "   2.3 Common Syntactic Constructs
  22. "   [4]    NameChar    ::=    Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
  23. "   [5]    Name        ::=    (Letter | '_' | ':') (NameChar)*
  24. "
  25. " NOTE:
  26. "   1) empty tag delimiters "/>" inside attribute values (strings)
  27. "      confuse syntax highlighting.
  28. "   2) for large files, folding can be pretty slow, especially when
  29. "      loading a file the first time and viewoptions contains 'folds'
  30. "      so that folds of previous sessions are applied.
  31. "      Don't use 'foldmethod=syntax' in this case.
  32.  
  33.  
  34. " Quit when a syntax file was already loaded
  35. if exists("b:current_syntax")
  36.     finish
  37. endif
  38.  
  39. let s:xml_cpo_save = &cpo
  40. set cpo&vim
  41.  
  42. syn case match
  43.  
  44. " mark illegal characters
  45. syn match xmlError "[<&]"
  46.  
  47. " strings (inside tags) aka VALUES
  48. "
  49. " EXAMPLE:
  50. "
  51. " <tag foo.attribute = "value">
  52. "               ^^^^^^^
  53. syn region  xmlString contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=xmlEntity display
  54. syn region  xmlString contained start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=xmlEntity display
  55.  
  56.  
  57. " punctuation (within attributes) e.g. <tag xml:foo.attribute ...>
  58. "                           ^   ^
  59. " syn match   xmlAttribPunct +[-:._]+ contained display
  60. syn match   xmlAttribPunct +[:.]+ contained display
  61.  
  62. " no highlighting for xmlEqual (xmlEqual has no highlighting group)
  63. syn match   xmlEqual +=+ display
  64.  
  65.  
  66. " attribute, everything before the '='
  67. "
  68. " PROVIDES: @xmlAttribHook
  69. "
  70. " EXAMPLE:
  71. "
  72. " <tag foo.attribute = "value">
  73. "      ^^^^^^^^^^^^^
  74. "
  75. syn match   xmlAttrib
  76.     \ +[-'"<]\@<!\<[a-zA-Z:_][-.0-9a-zA-Z0-9:_]*\>\(['">]\@!\|$\)+
  77.     \ contained
  78.     \ contains=xmlAttribPunct,@xmlAttribHook
  79.     \ display
  80.  
  81.  
  82. " namespace spec
  83. "
  84. " PROVIDES: @xmlNamespaceHook
  85. "
  86. " EXAMPLE:
  87. "
  88. " <xsl:for-each select = "lola">
  89. "  ^^^
  90. "
  91. if exists("g:xml_namespace_transparent")
  92. syn match   xmlNamespace
  93.     \ +\(<\|</\)\@<=[^ /!?<>"':]\+[:]\@=+
  94.     \ contained
  95.     \ contains=@xmlNamespaceHook
  96.     \ transparent
  97.     \ display
  98. else
  99. syn match   xmlNamespace
  100.     \ +\(<\|</\)\@<=[^ /!?<>"':]\+[:]\@=+
  101.     \ contained
  102.     \ contains=@xmlNamespaceHook
  103.     \ display
  104. endif
  105.  
  106.  
  107. " tag name
  108. "
  109. " PROVIDES: @xmlTagHook
  110. "
  111. " EXAMPLE:
  112. "
  113. " <tag foo.attribute = "value">
  114. "  ^^^
  115. "
  116. syn match   xmlTagName
  117.     \ +[<]\@<=[^ /!?<>"']\++
  118.     \ contained
  119.     \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook
  120.     \ display
  121.  
  122.  
  123. " start tag
  124. " use matchgroup=xmlTag to skip over the leading '<'
  125. "
  126. " PROVIDES: @xmlStartTagHook
  127. "
  128. " EXAMPLE:
  129. "
  130. " <tag id="whoops">
  131. " s^^^^^^^^^^^^^^^e
  132. "
  133. syn region   xmlTag
  134.     \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+
  135.     \ matchgroup=xmlTag end=+>+
  136.     \ contained
  137.     \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook
  138.  
  139.  
  140. " highlight the end tag
  141. "
  142. " PROVIDES: @xmlTagHook
  143. " (should we provide a separate @xmlEndTagHook ?)
  144. "
  145. " EXAMPLE:
  146. "
  147. " </tag>
  148. " ^^^^^^
  149. "
  150. syn match   xmlEndTag
  151.     \ +</[^ /!?<>"']\+>+
  152.     \ contained
  153.     \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook
  154.  
  155.  
  156. " tag elements with syntax-folding.
  157. " NOTE: NO HIGHLIGHING -- highlighing is done by contained elements
  158. "
  159. " PROVIDES: @xmlRegionHook
  160. "
  161. " EXAMPLE:
  162. "
  163. " <tag id="whoops">
  164. "   <!-- comment -->
  165. "   <another.tag></another.tag>
  166. "   <empty.tag/>
  167. "   some data
  168. " </tag>
  169. "
  170. syn region   xmlRegion
  171.     \ start=+<\z([^ /!?<>"']\+\)+
  172.     \ skip=+<!--\_.\{-}-->+
  173.     \ end=+</\z1\_\s\{-}>+
  174.     \ matchgroup=xmlEndTag end=+/>+
  175.     \ fold
  176.     \ contains=xmlTag,xmlEndTag,xmlCdata,xmlRegion,xmlComment,xmlEntity,xmlProcessing,@xmlRegionHook
  177.     \ keepend
  178.     \ extend
  179.  
  180.  
  181. " &entities; compare with dtd
  182. syn match   xmlEntity              "&[^; \t]*;" contains=xmlEntityPunct
  183. syn match   xmlEntityPunct  contained "[&.;]"
  184.  
  185.  
  186. " The real comments (this implements the comments as defined by xml,
  187. " but not all xml pages actually conform to it. Errors are flagged.
  188. syn region  xmlComment
  189.     \ start=+<!+
  190.     \ end=+>+
  191.     \ contains=xmlCommentPart,xmlCommentError
  192.     \ extend
  193.     \ fold
  194.  
  195. syn keyword xmlTodo        contained TODO FIXME XXX display
  196. syn match   xmlCommentError contained "[^><!]"
  197. syn region  xmlCommentPart
  198.     \ start=+--+
  199.     \ end=+--+
  200.     \ contained
  201.     \ contains=xmlTodo,@xmlCommentHook
  202.  
  203.  
  204. " CData sections
  205. "
  206. " PROVIDES: @xmlCdataHook
  207. "
  208. syn region    xmlCdata
  209.     \ start=+<!\[CDATA\[+
  210.     \ end=+]]>+
  211.     \ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook
  212.     \ keepend
  213.     \ extend
  214.  
  215. " using the following line instead leads to corrupt folding at CDATA regions
  216. " syn match    xmlCdata      +<!\[CDATA\[\_.\{-}]]>+  contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook
  217. syn match    xmlCdataStart +<!\[CDATA\[+  contained contains=xmlCdataCdata
  218. syn keyword  xmlCdataCdata CDATA      contained
  219. syn match    xmlCdataEnd   +]]>+      contained
  220.  
  221.  
  222. " Processing instructions
  223. " This allows "?>" inside strings -- good idea?
  224. syn region  xmlProcessing matchgroup=xmlProcessingDelim start="<?" end="?>" contains=xmlAttrib,xmlEqual,xmlString
  225.  
  226.  
  227. " DTD -- we use dtd.vim here
  228. syn region  xmlDocType matchgroup=xmlDocTypeDecl
  229.     \ start="<!DOCTYPE"he=s+2,rs=s+2 end=">"
  230.     \ fold
  231.     \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString
  232. syn keyword xmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM
  233. syn region  xmlInlineDTD contained matchgroup=xmlDocTypeDecl start="\[" end="]" contains=@xmlDTD
  234. syn include @xmlDTD <sfile>:p:h/dtd.vim
  235. unlet b:current_syntax
  236.  
  237.  
  238. " synchronizing
  239. " TODO !!! to be improved !!!
  240.  
  241. syn sync match xmlSyncDT grouphere  xmlDocType +\_.\(<!DOCTYPE\)\@=+
  242. " syn sync match xmlSyncDT groupthere  NONE       +]>+
  243.  
  244. syn sync match xmlSync grouphere   xmlRegion  +\_.\(<[^ /!?<>"']\+\)\@=+
  245. " syn sync match xmlSync grouphere  xmlRegion "<[^ /!?<>"']*>"
  246. syn sync match xmlSync groupthere  xmlRegion  +</[^ /!?<>"']\+>+
  247.  
  248. syn sync minlines=100
  249.  
  250.  
  251. " The default highlighting.
  252. hi def link xmlTodo        Todo
  253. hi def link xmlTag        Function
  254. hi def link xmlTagName        Function
  255. hi def link xmlEndTag        Identifier
  256. if !exists("g:xml_namespace_transparent")
  257.     hi def link xmlNamespace    Tag
  258. endif
  259. hi def link xmlEntity        Statement
  260. hi def link xmlEntityPunct    Type
  261.  
  262. hi def link xmlAttribPunct    Comment
  263. hi def link xmlAttrib        Type
  264.  
  265. hi def link xmlString        String
  266. hi def link xmlComment        Comment
  267. hi def link xmlCommentPart    Comment
  268. hi def link xmlCommentError    Error
  269. hi def link xmlError        Error
  270.  
  271. hi def link xmlProcessingDelim    Comment
  272. hi def link xmlProcessing    Type
  273.  
  274. hi def link xmlCdata        String
  275. hi def link xmlCdataCdata    Statement
  276. hi def link xmlCdataStart    Type
  277. hi def link xmlCdataEnd        Type
  278.  
  279. hi def link xmlDocTypeDecl    Function
  280. hi def link xmlDocTypeKeyword    Statement
  281. hi def link xmlInlineDTD    Function
  282.  
  283. let b:current_syntax = "xml"
  284.  
  285. let &cpo = s:xml_cpo_save
  286. unlet s:xml_cpo_save
  287.  
  288. " vim: ts=8
  289.