dtd.vim (4990B)
1 " Vim syntax file 2 " Language: DTD (Document Type Definition for XML) 3 " Maintainer: Christian Brabandt <cb@256bit.org> 4 " Repository: https://github.com/chrisbra/vim-xml-ftplugin 5 " Previous Maintainer: Johannes Zellner <johannes@zellner.org> 6 " Author: Daniel Amyot <damyot@site.uottawa.ca> 7 " Last Changed: Sept 24, 2019 8 " Filenames: *.dtd 9 " 10 " REFERENCES: 11 " http://www.w3.org/TR/html40/ 12 " http://www.w3.org/TR/NOTE-html-970421 13 " 14 " TODO: 15 " - improve synchronizing. 16 17 if exists("b:current_syntax") 18 finish 19 endif 20 let s:dtd_cpo_save = &cpo 21 set cpo&vim 22 23 if !exists("dtd_ignore_case") 24 " I prefer having the case takes into consideration. 25 syn case match 26 else 27 syn case ignore 28 endif 29 30 31 " the following line makes the opening <! and 32 " closing > highlighted using 'dtdFunction'. 33 " 34 " PROVIDES: @dtdTagHook 35 " 36 syn region dtdTag matchgroup=dtdFunction 37 \ start=+<!+ end=+>+ matchgroup=NONE 38 \ contains=dtdTag,dtdTagName,dtdError,dtdComment,dtdString,dtdAttrType,dtdAttrDef,dtdEnum,dtdParamEntityInst,dtdParamEntityDecl,dtdCard,@dtdTagHook 39 40 if !exists("dtd_no_tag_errors") 41 " mark everything as an error which starts with a <! 42 " and is not overridden later. If this is annoying, 43 " it can be switched off by setting the variable 44 " dtd_no_tag_errors. 45 syn region dtdError contained start=+<!+lc=2 end=+>+ 46 endif 47 48 " if this is a html like comment highlight also 49 " the opening <! and the closing > as Comment. 50 syn region dtdComment start=+<![ \t]*--+ end=+-->+ contains=dtdTodo,@Spell 51 52 53 " proper DTD comment 54 syn region dtdComment contained start=+--+ end=+--+ contains=dtdTodo,@Spell 55 56 57 " Start tags (keywords). This is contained in dtdFunction. 58 " Note that everything not contained here will be marked 59 " as error. 60 syn match dtdTagName contained +<!\(ATTLIST\|DOCTYPE\|ELEMENT\|ENTITY\|NOTATION\|SHORTREF\|USEMAP\|\[\)+lc=2,hs=s+2 61 62 63 " wildcards and operators 64 syn match dtdCard contained "|" 65 syn match dtdCard contained "," 66 " evenutally overridden by dtdEntity 67 syn match dtdCard contained "&" 68 syn match dtdCard contained "?" 69 syn match dtdCard contained "\*" 70 syn match dtdCard contained "+" 71 72 " ...and finally, special cases. 73 syn match dtdCard "ANY" 74 syn match dtdCard "EMPTY" 75 76 if !exists("dtd_no_param_entities") 77 78 " highlight parameter entity declarations 79 " and instances. Note that the closing `;' 80 " is optional. 81 82 " instances 83 syn region dtdParamEntityInst oneline matchgroup=dtdParamEntityPunct 84 \ start="%[-_a-zA-Z0-9.]\+"he=s+1,rs=s+1 85 \ skip=+[-_a-zA-Z0-9.]+ 86 \ end=";\|\>" 87 \ matchgroup=NONE contains=dtdParamEntityPunct 88 syn match dtdParamEntityPunct contained "\." 89 90 " declarations 91 " syn region dtdParamEntityDecl oneline matchgroup=dtdParamEntityDPunct start=+<!ENTITY % +lc=8 skip=+[-_a-zA-Z0-9.]+ matchgroup=NONE end="\>" contains=dtdParamEntityDPunct 92 syn match dtdParamEntityDecl +<!ENTITY % [-_a-zA-Z0-9.]*+lc=8 contains=dtdParamEntityDPunct 93 syn match dtdParamEntityDPunct contained "%\|\." 94 95 endif 96 97 " &entities; compare with xml 98 syn match dtdEntity "&[^; \t]*;" contains=dtdEntityPunct 99 syn match dtdEntityPunct contained "[&.;]" 100 101 " Strings are between quotes 102 syn region dtdString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=dtdAttrDef,dtdAttrType,dtdParamEntityInst,dtdEntity,dtdCard 103 syn region dtdString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=dtdAttrDef,dtdAttrType,dtdParamEntityInst,dtdEntity,dtdCard 104 105 " Enumeration of elements or data between parenthesis 106 " 107 " PROVIDES: @dtdEnumHook 108 " 109 syn region dtdEnum matchgroup=dtdType start="(" end=")" matchgroup=NONE contains=dtdEnum,dtdParamEntityInst,dtdCard,@dtdEnumHook 110 111 "Attribute types 112 syn keyword dtdAttrType NMTOKEN ENTITIES NMTOKENS ID CDATA 113 syn keyword dtdAttrType IDREF IDREFS 114 " ENTITY has to treated special for not overriding <!ENTITY 115 syn match dtdAttrType +[^!]\<ENTITY+ 116 117 "Attribute Definitions 118 syn match dtdAttrDef "#REQUIRED" 119 syn match dtdAttrDef "#IMPLIED" 120 syn match dtdAttrDef "#FIXED" 121 122 syn case match 123 " define some common keywords to mark TODO 124 " and important sections inside comments. 125 syn keyword dtdTodo contained TODO FIXME XXX 126 127 syn sync lines=250 128 129 " Define the default highlighting. 130 " Only when an item doesn't have highlighting yet 131 132 " The default highlighting. 133 hi def link dtdFunction Function 134 hi def link dtdTag Normal 135 hi def link dtdType Type 136 hi def link dtdAttrType dtdType 137 hi def link dtdAttrDef dtdType 138 hi def link dtdConstant Constant 139 hi def link dtdString dtdConstant 140 hi def link dtdEnum dtdConstant 141 hi def link dtdCard dtdFunction 142 143 hi def link dtdEntity Statement 144 hi def link dtdEntityPunct dtdType 145 hi def link dtdParamEntityInst dtdConstant 146 hi def link dtdParamEntityPunct dtdType 147 hi def link dtdParamEntityDecl dtdType 148 hi def link dtdParamEntityDPunct dtdComment 149 150 hi def link dtdComment Comment 151 hi def link dtdTagName Statement 152 hi def link dtdError Error 153 hi def link dtdTodo Todo 154 155 156 let &cpo = s:dtd_cpo_save 157 unlet s:dtd_cpo_save 158 159 let b:current_syntax = "dtd" 160 161 " vim: ts=8