blob: 001dbbddd3461e6f28c380501705fb4ae1e1ba08 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" 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 Moolenaar8e52a592012-05-18 21:49:28 +020016if exists("b:current_syntax")
17 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +000018endif
Bram Moolenaar8e52a592012-05-18 21:49:28 +020019let s:dtd_cpo_save = &cpo
20set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000021
22if !exists("dtd_ignore_case")
23 " I prefer having the case takes into consideration.
24 syn case match
25else
26 syn case ignore
27endif
28
29
30" the following line makes the opening <! and
31" closing > highlighted using 'dtdFunction'.
32"
33" PROVIDES: @dtdTagHook
34"
35syn region dtdTag matchgroup=dtdFunction
36 \ start=+<!+ end=+>+ matchgroup=NONE
37 \ contains=dtdTag,dtdTagName,dtdError,dtdComment,dtdString,dtdAttrType,dtdAttrDef,dtdEnum,dtdParamEntityInst,dtdParamEntityDecl,dtdCard,@dtdTagHook
38
39if !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=+>+
45endif
46
47" if this is a html like comment hightlight also
48" the opening <! and the closing > as Comment.
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000049syn region dtdComment start=+<![ \t]*--+ end=+-->+ contains=dtdTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000050
51
52" proper DTD comment
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000053syn region dtdComment contained start=+--+ end=+--+ contains=dtdTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
55
56" Start tags (keywords). This is contained in dtdFunction.
57" Note that everything not contained here will be marked
58" as error.
59syn match dtdTagName contained +<!\(ATTLIST\|DOCTYPE\|ELEMENT\|ENTITY\|NOTATION\|SHORTREF\|USEMAP\|\[\)+lc=2,hs=s+2
60
61
62" wildcards and operators
63syn match dtdCard contained "|"
64syn match dtdCard contained ","
65" evenutally overridden by dtdEntity
66syn match dtdCard contained "&"
67syn match dtdCard contained "?"
68syn match dtdCard contained "\*"
69syn match dtdCard contained "+"
70
71" ...and finally, special cases.
72syn match dtdCard "ANY"
73syn match dtdCard "EMPTY"
74
75if !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
94endif
95
96" &entities; compare with xml
97syn match dtdEntity "&[^; \t]*;" contains=dtdEntityPunct
98syn match dtdEntityPunct contained "[&.;]"
99
100" Strings are between quotes
101syn region dtdString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=dtdAttrDef,dtdAttrType,dtdEnum,dtdParamEntityInst,dtdEntity,dtdCard
102syn 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"
108syn region dtdEnum matchgroup=dtdType start="(" end=")" matchgroup=NONE contains=dtdEnum,dtdParamEntityInst,dtdCard,@dtdEnumHook
109
110"Attribute types
111syn keyword dtdAttrType NMTOKEN ENTITIES NMTOKENS ID CDATA
112syn keyword dtdAttrType IDREF IDREFS
113" ENTITY has to treated special for not overriding <!ENTITY
114syn match dtdAttrType +[^!]\<ENTITY+
115
116"Attribute Definitions
117syn match dtdAttrDef "#REQUIRED"
118syn match dtdAttrDef "#IMPLIED"
119syn match dtdAttrDef "#FIXED"
120
121syn case match
122" define some common keywords to mark TODO
123" and important sections inside comments.
124syn keyword dtdTodo contained TODO FIXME XXX
125
126syn sync lines=250
127
128" Define the default highlighting.
129" For version 5.7 and earlier: only when not done already
130" For version 5.8 and later: only when an item doesn't have highlighting yet
131if version >= 508 || !exists("did_dtd_syn_inits")
132 if version < 508
133 let did_dtd_syn_inits = 1
134 command -nargs=+ HiLink hi link <args>
135 else
136 command -nargs=+ HiLink hi def link <args>
137 endif
138
139 " The default highlighting.
140 HiLink dtdFunction Function
141 HiLink dtdTag Normal
142 HiLink dtdType Type
143 HiLink dtdAttrType dtdType
144 HiLink dtdAttrDef dtdType
145 HiLink dtdConstant Constant
146 HiLink dtdString dtdConstant
147 HiLink dtdEnum dtdConstant
148 HiLink dtdCard dtdFunction
149
150 HiLink dtdEntity Statement
151 HiLink dtdEntityPunct dtdType
152 HiLink dtdParamEntityInst dtdConstant
153 HiLink dtdParamEntityPunct dtdType
154 HiLink dtdParamEntityDecl dtdType
155 HiLink dtdParamEntityDPunct dtdComment
156
157 HiLink dtdComment Comment
158 HiLink dtdTagName Statement
159 HiLink dtdError Error
160 HiLink dtdTodo Todo
161
162 delcommand HiLink
163endif
164
Bram Moolenaar8e52a592012-05-18 21:49:28 +0200165let &cpo = s:dtd_cpo_save
166unlet s:dtd_cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167
168let b:current_syntax = "dtd"
169
170" vim: ts=8