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