3 " Maintainer: Kenneth J. Pronovici <pronovic@ieee.org>
4 " Last Change: $LastChangedDate: 2007-12-19 10:59:39 -0600 (Wed, 19 Dec 2007) $
6 " URL: ftp://cedar-solutions.com/software/mysql.vim
7 " Note: The definitions below are taken from the mysql user manual as of April 2002, for version 3.23
9 " For version 5.x: Clear all syntax items
10 " For version 6.x: Quit when a syntax file was already loaded
13 elseif exists("b:current_syntax")
20 " General keywords which don't fall into other categories
21 syn keyword mysqlKeyword action add after aggregate all alter as asc auto_increment avg avg_row_length
22 syn keyword mysqlKeyword both by
23 syn keyword mysqlKeyword cascade change character check checksum column columns comment constraint create cross
24 syn keyword mysqlKeyword current_date current_time current_timestamp
25 syn keyword mysqlKeyword data database databases day day_hour day_minute day_second
26 syn keyword mysqlKeyword default delayed delay_key_write delete desc describe distinct distinctrow drop
27 syn keyword mysqlKeyword enclosed escape escaped explain
28 syn keyword mysqlKeyword fields file first flush for foreign from full function
29 syn keyword mysqlKeyword global grant grants group
30 syn keyword mysqlKeyword having heap high_priority hosts hour hour_minute hour_second
31 syn keyword mysqlKeyword identified ignore index infile inner insert insert_id into isam
32 syn keyword mysqlKeyword join
33 syn keyword mysqlKeyword key keys kill last_insert_id leading left limit lines load local lock logs long
34 syn keyword mysqlKeyword low_priority
35 syn keyword mysqlKeyword match max_rows middleint min_rows minute minute_second modify month myisam
36 syn keyword mysqlKeyword natural no
37 syn keyword mysqlKeyword on optimize option optionally order outer outfile
38 syn keyword mysqlKeyword pack_keys partial password primary privileges procedure process processlist
39 syn keyword mysqlKeyword read references reload rename replace restrict returns revoke row rows
40 syn keyword mysqlKeyword second select show shutdown soname sql_big_result sql_big_selects sql_big_tables sql_log_off
41 syn keyword mysqlKeyword sql_log_update sql_low_priority_updates sql_select_limit sql_small_result sql_warnings starting
42 syn keyword mysqlKeyword status straight_join string
43 syn keyword mysqlKeyword table tables temporary terminated to trailing type
44 syn keyword mysqlKeyword unique unlock unsigned update usage use using
45 syn keyword mysqlKeyword values varbinary variables varying
46 syn keyword mysqlKeyword where with write
47 syn keyword mysqlKeyword year_month
48 syn keyword mysqlKeyword zerofill
51 syn keyword mysqlSpecial false null true
53 " Strings (single- and double-quote)
54 syn region mysqlString start=+"+ skip=+\\\\\|\\"+ end=+"+
55 syn region mysqlString start=+'+ skip=+\\\\\|\\'+ end=+'+
57 " Numbers and hexidecimal values
58 syn match mysqlNumber "-\=\<[0-9]*\>"
59 syn match mysqlNumber "-\=\<[0-9]*\.[0-9]*\>"
60 syn match mysqlNumber "-\=\<[0-9]*e[+-]\=[0-9]*\>"
61 syn match mysqlNumber "-\=\<[0-9]*\.[0-9]*e[+-]\=[0-9]*\>"
62 syn match mysqlNumber "\<0x[abcdefABCDEF0-9]*\>"
65 syn match mysqlVariable "@\a*[A-Za-z0-9]*[._]*[A-Za-z0-9]*"
67 " Comments (c-style, mysql-style and modified sql-style)
68 syn region mysqlComment start="/\*" end="\*/"
69 syn match mysqlComment "#.*"
70 syn match mysqlComment "--\_s.*"
71 syn sync ccomment mysqlComment
75 " This gets a bit ugly. There are two different problems we have to
78 " The first problem is that some keywoards like 'float' can be used
79 " both with and without specifiers, i.e. 'float', 'float(1)' and
80 " 'float(@var)' are all valid. We have to account for this and we
81 " also have to make sure that garbage like floatn or float_(1) is not
84 " The second problem is that some of these keywords are included in
85 " function names. For instance, year() is part of the name of the
86 " dayofyear() function, and the dec keyword (no parenthesis) is part of
87 " the name of the decode() function.
89 syn keyword mysqlType tinyint smallint mediumint int integer bigint
90 syn keyword mysqlType date datetime time bit bool
91 syn keyword mysqlType tinytext mediumtext longtext text
92 syn keyword mysqlType tinyblob mediumblob longblob blob
93 syn region mysqlType start="float\W" end="."me=s-1
94 syn region mysqlType start="float$" end="."me=s-1
95 syn region mysqlType start="float(" end=")" contains=mysqlNumber,mysqlVariable
96 syn region mysqlType start="double\W" end="."me=s-1
97 syn region mysqlType start="double$" end="."me=s-1
98 syn region mysqlType start="double(" end=")" contains=mysqlNumber,mysqlVariable
99 syn region mysqlType start="double precision\W" end="."me=s-1
100 syn region mysqlType start="double precision$" end="."me=s-1
101 syn region mysqlType start="double precision(" end=")" contains=mysqlNumber,mysqlVariable
102 syn region mysqlType start="real\W" end="."me=s-1
103 syn region mysqlType start="real$" end="."me=s-1
104 syn region mysqlType start="real(" end=")" contains=mysqlNumber,mysqlVariable
105 syn region mysqlType start="numeric(" end=")" contains=mysqlNumber,mysqlVariable
106 syn region mysqlType start="dec\W" end="."me=s-1
107 syn region mysqlType start="dec$" end="."me=s-1
108 syn region mysqlType start="dec(" end=")" contains=mysqlNumber,mysqlVariable
109 syn region mysqlType start="decimal\W" end="."me=s-1
110 syn region mysqlType start="decimal$" end="."me=s-1
111 syn region mysqlType start="decimal(" end=")" contains=mysqlNumber,mysqlVariable
112 syn region mysqlType start="\Wtimestamp\W" end="."me=s-1
113 syn region mysqlType start="\Wtimestamp$" end="."me=s-1
114 syn region mysqlType start="\Wtimestamp(" end=")" contains=mysqlNumber,mysqlVariable
115 syn region mysqlType start="^timestamp\W" end="."me=s-1
116 syn region mysqlType start="^timestamp$" end="."me=s-1
117 syn region mysqlType start="^timestamp(" end=")" contains=mysqlNumber,mysqlVariable
118 syn region mysqlType start="\Wyear(" end=")" contains=mysqlNumber,mysqlVariable
119 syn region mysqlType start="^year(" end=")" contains=mysqlNumber,mysqlVariable
120 syn region mysqlType start="char(" end=")" contains=mysqlNumber,mysqlVariable
121 syn region mysqlType start="varchar(" end=")" contains=mysqlNumber,mysqlVariable
122 syn region mysqlType start="enum(" end=")" contains=mysqlString,mysqlVariable
123 syn region mysqlType start="\Wset(" end=")" contains=mysqlString,mysqlVariable
124 syn region mysqlType start="^set(" end=")" contains=mysqlString,mysqlVariable
126 " Logical, string and numeric operators
127 syn keyword mysqlOperator between not and or is in like regexp rlike binary exists
128 syn region mysqlOperator start="isnull(" end=")" contains=ALL
129 syn region mysqlOperator start="coalesce(" end=")" contains=ALL
130 syn region mysqlOperator start="interval(" end=")" contains=ALL
132 " Control flow functions
133 syn keyword mysqlFlow case when then else end
134 syn region mysqlFlow start="ifnull(" end=")" contains=ALL
135 syn region mysqlFlow start="nullif(" end=")" contains=ALL
136 syn region mysqlFlow start="if(" end=")" contains=ALL
140 " I'm leery of just defining keywords for functions, since according to the MySQL manual:
142 " Function names do not clash with table or column names. For example, ABS is a
143 " valid column name. The only restriction is that for a function call, no spaces
144 " are allowed between the function name and the `(' that follows it.
146 " This means that if I want to highlight function names properly, I have to use a
147 " region to define them, not just a keyword. This will probably cause the syntax file
148 " to load more slowly, but at least it will be 'correct'.
150 syn region mysqlFunction start="abs(" end=")" contains=ALL
151 syn region mysqlFunction start="acos(" end=")" contains=ALL
152 syn region mysqlFunction start="adddate(" end=")" contains=ALL
153 syn region mysqlFunction start="ascii(" end=")" contains=ALL
154 syn region mysqlFunction start="asin(" end=")" contains=ALL
155 syn region mysqlFunction start="atan(" end=")" contains=ALL
156 syn region mysqlFunction start="atan2(" end=")" contains=ALL
157 syn region mysqlFunction start="benchmark(" end=")" contains=ALL
158 syn region mysqlFunction start="bin(" end=")" contains=ALL
159 syn region mysqlFunction start="bit_and(" end=")" contains=ALL
160 syn region mysqlFunction start="bit_count(" end=")" contains=ALL
161 syn region mysqlFunction start="bit_or(" end=")" contains=ALL
162 syn region mysqlFunction start="ceiling(" end=")" contains=ALL
163 syn region mysqlFunction start="character_length(" end=")" contains=ALL
164 syn region mysqlFunction start="char_length(" end=")" contains=ALL
165 syn region mysqlFunction start="concat(" end=")" contains=ALL
166 syn region mysqlFunction start="concat_ws(" end=")" contains=ALL
167 syn region mysqlFunction start="connection_id(" end=")" contains=ALL
168 syn region mysqlFunction start="conv(" end=")" contains=ALL
169 syn region mysqlFunction start="cos(" end=")" contains=ALL
170 syn region mysqlFunction start="cot(" end=")" contains=ALL
171 syn region mysqlFunction start="count(" end=")" contains=ALL
172 syn region mysqlFunction start="curdate(" end=")" contains=ALL
173 syn region mysqlFunction start="curtime(" end=")" contains=ALL
174 syn region mysqlFunction start="date_add(" end=")" contains=ALL
175 syn region mysqlFunction start="date_format(" end=")" contains=ALL
176 syn region mysqlFunction start="date_sub(" end=")" contains=ALL
177 syn region mysqlFunction start="dayname(" end=")" contains=ALL
178 syn region mysqlFunction start="dayofmonth(" end=")" contains=ALL
179 syn region mysqlFunction start="dayofweek(" end=")" contains=ALL
180 syn region mysqlFunction start="dayofyear(" end=")" contains=ALL
181 syn region mysqlFunction start="decode(" end=")" contains=ALL
182 syn region mysqlFunction start="degrees(" end=")" contains=ALL
183 syn region mysqlFunction start="elt(" end=")" contains=ALL
184 syn region mysqlFunction start="encode(" end=")" contains=ALL
185 syn region mysqlFunction start="encrypt(" end=")" contains=ALL
186 syn region mysqlFunction start="exp(" end=")" contains=ALL
187 syn region mysqlFunction start="export_set(" end=")" contains=ALL
188 syn region mysqlFunction start="extract(" end=")" contains=ALL
189 syn region mysqlFunction start="field(" end=")" contains=ALL
190 syn region mysqlFunction start="find_in_set(" end=")" contains=ALL
191 syn region mysqlFunction start="floor(" end=")" contains=ALL
192 syn region mysqlFunction start="format(" end=")" contains=ALL
193 syn region mysqlFunction start="from_days(" end=")" contains=ALL
194 syn region mysqlFunction start="from_unixtime(" end=")" contains=ALL
195 syn region mysqlFunction start="get_lock(" end=")" contains=ALL
196 syn region mysqlFunction start="greatest(" end=")" contains=ALL
197 syn region mysqlFunction start="group_unique_users(" end=")" contains=ALL
198 syn region mysqlFunction start="hex(" end=")" contains=ALL
199 syn region mysqlFunction start="inet_aton(" end=")" contains=ALL
200 syn region mysqlFunction start="inet_ntoa(" end=")" contains=ALL
201 syn region mysqlFunction start="instr(" end=")" contains=ALL
202 syn region mysqlFunction start="lcase(" end=")" contains=ALL
203 syn region mysqlFunction start="least(" end=")" contains=ALL
204 syn region mysqlFunction start="length(" end=")" contains=ALL
205 syn region mysqlFunction start="load_file(" end=")" contains=ALL
206 syn region mysqlFunction start="locate(" end=")" contains=ALL
207 syn region mysqlFunction start="log(" end=")" contains=ALL
208 syn region mysqlFunction start="log10(" end=")" contains=ALL
209 syn region mysqlFunction start="lower(" end=")" contains=ALL
210 syn region mysqlFunction start="lpad(" end=")" contains=ALL
211 syn region mysqlFunction start="ltrim(" end=")" contains=ALL
212 syn region mysqlFunction start="make_set(" end=")" contains=ALL
213 syn region mysqlFunction start="master_pos_wait(" end=")" contains=ALL
214 syn region mysqlFunction start="max(" end=")" contains=ALL
215 syn region mysqlFunction start="md5(" end=")" contains=ALL
216 syn region mysqlFunction start="mid(" end=")" contains=ALL
217 syn region mysqlFunction start="min(" end=")" contains=ALL
218 syn region mysqlFunction start="mod(" end=")" contains=ALL
219 syn region mysqlFunction start="monthname(" end=")" contains=ALL
220 syn region mysqlFunction start="now(" end=")" contains=ALL
221 syn region mysqlFunction start="oct(" end=")" contains=ALL
222 syn region mysqlFunction start="octet_length(" end=")" contains=ALL
223 syn region mysqlFunction start="ord(" end=")" contains=ALL
224 syn region mysqlFunction start="period_add(" end=")" contains=ALL
225 syn region mysqlFunction start="period_diff(" end=")" contains=ALL
226 syn region mysqlFunction start="pi(" end=")" contains=ALL
227 syn region mysqlFunction start="position(" end=")" contains=ALL
228 syn region mysqlFunction start="pow(" end=")" contains=ALL
229 syn region mysqlFunction start="power(" end=")" contains=ALL
230 syn region mysqlFunction start="quarter(" end=")" contains=ALL
231 syn region mysqlFunction start="radians(" end=")" contains=ALL
232 syn region mysqlFunction start="rand(" end=")" contains=ALL
233 syn region mysqlFunction start="release_lock(" end=")" contains=ALL
234 syn region mysqlFunction start="repeat(" end=")" contains=ALL
235 syn region mysqlFunction start="reverse(" end=")" contains=ALL
236 syn region mysqlFunction start="round(" end=")" contains=ALL
237 syn region mysqlFunction start="rpad(" end=")" contains=ALL
238 syn region mysqlFunction start="rtrim(" end=")" contains=ALL
239 syn region mysqlFunction start="sec_to_time(" end=")" contains=ALL
240 syn region mysqlFunction start="session_user(" end=")" contains=ALL
241 syn region mysqlFunction start="sign(" end=")" contains=ALL
242 syn region mysqlFunction start="sin(" end=")" contains=ALL
243 syn region mysqlFunction start="soundex(" end=")" contains=ALL
244 syn region mysqlFunction start="space(" end=")" contains=ALL
245 syn region mysqlFunction start="sqrt(" end=")" contains=ALL
246 syn region mysqlFunction start="std(" end=")" contains=ALL
247 syn region mysqlFunction start="stddev(" end=")" contains=ALL
248 syn region mysqlFunction start="strcmp(" end=")" contains=ALL
249 syn region mysqlFunction start="subdate(" end=")" contains=ALL
250 syn region mysqlFunction start="substring(" end=")" contains=ALL
251 syn region mysqlFunction start="substring_index(" end=")" contains=ALL
252 syn region mysqlFunction start="subtime(" end=")" contains=ALL
253 syn region mysqlFunction start="sum(" end=")" contains=ALL
254 syn region mysqlFunction start="sysdate(" end=")" contains=ALL
255 syn region mysqlFunction start="system_user(" end=")" contains=ALL
256 syn region mysqlFunction start="tan(" end=")" contains=ALL
257 syn region mysqlFunction start="time_format(" end=")" contains=ALL
258 syn region mysqlFunction start="time_to_sec(" end=")" contains=ALL
259 syn region mysqlFunction start="to_days(" end=")" contains=ALL
260 syn region mysqlFunction start="trim(" end=")" contains=ALL
261 syn region mysqlFunction start="ucase(" end=")" contains=ALL
262 syn region mysqlFunction start="unique_users(" end=")" contains=ALL
263 syn region mysqlFunction start="unix_timestamp(" end=")" contains=ALL
264 syn region mysqlFunction start="upper(" end=")" contains=ALL
265 syn region mysqlFunction start="user(" end=")" contains=ALL
266 syn region mysqlFunction start="version(" end=")" contains=ALL
267 syn region mysqlFunction start="week(" end=")" contains=ALL
268 syn region mysqlFunction start="weekday(" end=")" contains=ALL
269 syn region mysqlFunction start="yearweek(" end=")" contains=ALL
271 " Define the default highlighting.
272 " For version 5.7 and earlier: only when not done already
273 " For version 5.8 and later: only when an item doesn't have highlighting yet
274 if version >= 508 || !exists("did_mysql_syn_inits")
276 let did_mysql_syn_inits = 1
277 command -nargs=+ HiLink hi link <args>
279 command -nargs=+ HiLink hi def link <args>
282 HiLink mysqlKeyword Statement
283 HiLink mysqlSpecial Special
284 HiLink mysqlString String
285 HiLink mysqlNumber Number
286 HiLink mysqlVariable Identifier
287 HiLink mysqlComment Comment
288 HiLink mysqlType Type
289 HiLink mysqlOperator Statement
290 HiLink mysqlFlow Statement
291 HiLink mysqlFunction Function
296 let b:current_syntax = "mysql"