home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim60.zip / vim60rt2.zip / vim / vim60 / syntax / sgml.vim < prev    next >
Encoding:
Text File  |  2001-09-26  |  7.8 KB  |  274 lines

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