this repo has no description
1" Vim syntax file
2" Language: SQL with SQLite and other additions.
3" Maintainer: Jessica K McIntosh AT gmail DOT com
4" Last Changed: Thu Jan 23 06:00 PM 2014 EST
5
6" More complete SQL matching with error reporting.
7" Only matches types inside 'CREATE TABLE ();'.
8" Highlights functions. Unknown functions are an error.
9" Based on the SQL syntax files that come with Vim.
10
11if exists('b:current_syntax')
12 finish
13endif
14
15syn case ignore
16
17" All non-contained SQL syntax.
18syn cluster sqlALL contains=TOP
19
20" Various error conditions.
21"syn match sqlError "\<\w\+(" " Not a known function.
22syn match sqlError ")" " Lonely closing paren.
23syn match sqlError ",\(\_\s*[;)]\)\@=" " Comma before a paren or semicolon.
24syn match sqlError " $" " Space at the end of a line.
25" Comma before certain words.
26syn match sqlError ",\_\s*\(\<\(asc\|desc\|exists\|for\|from\)\>\)\@="
27syn match sqlError ",\_\s*\(\<\(group by\|into\|limit\|order\)\>\)\@="
28syn match sqlError ",\_\s*\(\<\(table\|using\|where\)\>\)\@="
29
30" Special words.
31syn keyword sqlSpecial false null true
32
33" Keywords
34syn keyword sqlKeyword access add after aggregate as asc authorization
35syn keyword sqlKeyword begin by cache cascade check cluster collate
36syn keyword sqlKeyword collation column compress conflict connect connection
37syn keyword sqlKeyword constraint current cursor database debug decimal
38syn keyword sqlKeyword default desc each else elsif escape exception
39syn keyword sqlKeyword exclusive explain external file for foreign from function
40syn keyword sqlKeyword group having identified if immediate increment index
41syn keyword sqlKeyword initial inner into is join key left level loop
42syn keyword sqlKeyword maxextents mode modify nocompress nowait object of
43syn keyword sqlKeyword off offline on online option order outer over
44syn keyword sqlKeyword partition pctfree
45syn keyword sqlKeyword primary privileges procedure public references
46syn keyword sqlKeyword referencing release resource return role row rowid
47syn keyword sqlKeyword rowlabel rownum rows schema session share size
48syn keyword sqlKeyword start successful synonym then to transaction trigger
49syn keyword sqlKeyword uid user using validate values view virtual whenever
50syn keyword sqlKeyword where with
51syn match sqlKeyword "\<prompt\>"
52syn match sqlKeyword "\<glob\>"
53" Do special things with CREATE TABLE ( below.
54syn match sqlKeyword "\<table\>"
55
56" SQLite Pragmas - Treat them as keywords.
57syn keyword sqlKeyword auto_vacuum automatic_index cache_size
58syn keyword sqlKeyword case_sensitive_like checkpoint_fullfsync
59syn keyword sqlKeyword collation_list compile_options count_changes
60syn keyword sqlKeyword database_list default_cache_size
61syn keyword sqlKeyword empty_result_callbacks encoding foreign_key_list
62syn keyword sqlKeyword foreign_keys freelist_count full_column_names
63syn keyword sqlKeyword fullfsync ignore_check_constraints
64syn keyword sqlKeyword incremental_vacuum index_info index_list
65syn keyword sqlKeyword integrity_check journal_mode journal_size_limit
66syn keyword sqlKeyword legacy_file_format locking_mode max_page_count
67syn keyword sqlKeyword page_count page_size parser_trace quick_check
68syn keyword sqlKeyword read_uncommitted recursive_triggers
69syn keyword sqlKeyword reverse_unordered_selects schema_version
70syn keyword sqlKeyword secure_delete short_column_names synchronous
71syn keyword sqlKeyword table_info temp_store temp_store_directory
72syn keyword sqlKeyword user_version vdbe_listing vdbe_trace
73syn keyword sqlKeyword wal_autocheckpoint wal_checkpoint writable_schema
74
75" Operators
76syn keyword sqlOperator all and any between case distinct elif else end
77syn keyword sqlOperator exit exists if in intersect is like match matches
78syn keyword sqlOperator minus not or out prior regexp some then union
79syn keyword sqlOperator unique when
80syn match sqlOperator "||\|:="
81
82" Conditionals
83syn match sqlConditional "=\|<\|>\|+\|-"
84
85" Unknown functions.
86syn match sqlUnknownFunc "\<\w\+(\@="
87
88" Functions - Only valid with a '(' after them.
89syn match sqlFunction "\<\(abs\|acos\|asin\|atan2\?\|avg\|cardinality\)(\@="
90syn match sqlFunction "\<\(cast\|changes\|char_length\|character_length\)(\@="
91syn match sqlFunction "\<\(coalesce\|concat\|cos\|count\|\(date\)\?\(time\)\?\)(\@="
92syn match sqlFunction "\<\(exp\|filetoblob\|filetoclob\|floor\|glob\|group_concat\)(\@="
93syn match sqlFunction "\<\(hex\|ifnull\|initcap\|isnull\|julianday\|last_insert_rowid\)(\@="
94syn match sqlFunction "\<\(length\|log10\|logn\|lower\|lpad\|ltrin\|max\|min\)(\@="
95syn match sqlFunction "\<\(mod\|nullif\|octet_length\|pow\|quote\|random\)(\@="
96syn match sqlFunction "\<\(range\|replace\|root\|round\|rpad\|sin\|soundex\)(\@="
97syn match sqlFunction "\<\(sqrtstdev\|strftime\|substr\|substring\|sum\|sysdate\|tan\)(\@="
98syn match sqlFunction "\<\(to_char\|to_date\|to_number\|total\|trim\|trunc\|typeof\)(\@="
99syn match sqlFunction "\<\(upper\|variance\)(\@="
100
101" Oracle DBMS functions.
102syn match sqlFunction "\<dbms_\w\+\.\w\+(\@="
103
104" Oracle Exception Functions.
105syn match sqlFunction "\<raise_application_error(\@="
106
107" SQLite Functions
108syn match sqlFunction "\<\(last_insert_rowid\|load_extension\|randomblob\)(\@="
109syn match sqlFunction "\<\(sqlite_compileoption_get\|sqlite_compileoption_used\)(\@="
110syn match sqlFunction "\<\(sqlite_source_id\|sqlite_version\|sqlite_version\)(\@="
111syn match sqlFunction "\<\(zeroblob\|ltrim\|rtrim\)(\@="
112
113" SQLite Command Line Client Functions
114syn match sqlFunction "^\.\w\+"
115
116" Statements
117syn keyword sqlStatement alter analyze audit begin comment commit delete
118syn keyword sqlStatement drop execute explain grant insert lock noaudit
119syn keyword sqlStatement rename revoke rollback savepoint select
120syn keyword sqlStatement truncate update vacuum
121syn match sqlStatement "\<\(replace\|create\)\>"
122
123" SQLite Statements
124syn keyword sqlStatement attach detach indexed pragma reindex
125
126" Types - Only matched inside 'CREATE TABLE ();'.
127syn keyword sqlType contained bigint bit blob bool boolean byte char
128syn keyword sqlType contained clob date datetime dec decimal enum
129syn keyword sqlType contained float int int8 integer interval long
130syn keyword sqlType contained longblob longtext lvarchar mediumblob
131syn keyword sqlType contained mediumint mediumtext mlslabel money
132syn keyword sqlType contained multiset nchar number numeric nvarchar
133syn keyword sqlType contained raw real rowid serial serial8 set
134syn keyword sqlType contained smallfloat smallint text time
135syn keyword sqlType contained timestamp tinyblob tinyint tinytext
136syn keyword sqlType contained varchar varchar2 varray year
137syn match sqlType contained "\<\(character\|double\|varying\)\>"
138syn match sqlType contained "\<character\s\+varying\>"
139syn match sqlType contained "\<double\s\+precision\>"
140
141" Oracle Variables
142syn match sqlVariable "&\a\w\+"
143syn match sqlVariable ":\w\+"
144syn match sqlVariable "SQL%\w\+"
145
146" Strings
147syn region sqlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=sqlVariable
148syn region sqlString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=sqlVariable
149syn region sqlString start=+`+ skip=+\\\\\|\\`+ end=+`+ contains=sqlVariable
150
151" Numbers
152syn match sqlNumber "-\=\<[0-9]*\>"
153syn match sqlNumber "-\=\<[0-9]*\.[0-9]*\>"
154syn match sqlNumber "-\=\<[0-9][0-9]*e[+-]\=[0-9]*\>"
155syn match sqlNumber "-\=\<[0-9]*\.[0-9]*e[+-]\=[0-9]*\>"
156syn match sqlNumber "\<0x[abcdef0-9]*\>"
157
158" Todo
159syn keyword sqlTodo contained DEBUG FIXME NOTE TODO XXX
160
161" Comments
162syn region sqlComment start="/\*" end="\*/" contains=sqlTodo
163syn match sqlComment "--.*$" contains=sqlTodo
164syn match sqlComment "rem.*$" contains=sqlTodo
165
166" Mark correct paren use. Different colors for different purposes.
167syn region sqlParens transparent matchgroup=sqlParen start="(" end=")"
168syn match sqlParenEmpty "()"
169syn region sqlParens transparent matchgroup=sqlParenFunc start="\(\<\w\+\>\)\@<=(" end=")"
170
171" Highlight types correctly inside create table and procedure statements.
172" All other SQL is properly highlighted as well.
173syn region sqlTypeParens contained matchgroup=sqlType start="(" end=")" contains=@sqlALL
174syn match sqlTypeMatch contained "\(\(^\|[,(]\)\s*\S\+\s\+\)\@<=\w\+\(\s*([^)]\+)\)\?" contains=sqlType,sqlTypeParens
175syn match sqlTypeMatch contained "\(\(^\|[,(]\)\s*\S\+\s\+\)\@<=character\s\+varying\s*([^)]\+)" contains=sqlType,sqlTypeParens
176syn region sqlTypeRegion matchgroup=sqlParen start="\(create\s\+table\s\+[^(]\+\s\+\)\@<=(" end=")" contains=@sqlALL,sqlTypeMatch
177syn region sqlTypeRegion matchgroup=sqlParen start="\(create\s\+\(or\s\+replace\s\+\)\?procedure\s\+[^(]\+\s*\)\@<=(" end=")" contains=@sqlALL,sqlTypeMatch
178
179" SQL Embedded in a statement.
180syn region sqlquoteRegion matchgroup=sqlParen start="\(execute\s\+immediate\s*\)\@<=('" end="')" contains=@sqlALL
181
182" Special Oracle Statements
183syn match sqlStatement "^\s*\(prompt\|spool\)\>" nextgroup=sqlAnyString
184syn match sqlStatement "^\s*accept\s\+" nextgroup=sqlAnyVariable
185syn match sqlStatement "declare\s\+" nextgroup=sqlDeclare
186syn region sqlDeclare contained matchgroup=sqlVariable start="\a\w\+" end="$" contains=@sqlALL,sqlType
187syn match sqlOperator "^@" nextgroup=sqlAnyString
188syn match sqlAnyVariable contained "\a\w\+"
189syn match sqlAnyString contained ".*" contains=sqlVariable
190
191syn region sqlSetRegion matchgroup=sqlStatement start="^\s*set\>" matchgroup=NONE end="$" contains=sqlSetOptions,sqlSetValues
192syn keyword sqlSetOptions contained autorecovery colsep copytypecheck describe escchar flagger
193syn keyword sqlSetOptions contained instance logsource long null recsep recsepchar
194syn keyword sqlSetOptions contained
195syn match sqlSetOptions contained "\<\(app\w*\|array\w*\|auto\w*\|autop\w*\)\>"
196syn match sqlSetOptions contained "\<\(autot\w*\|blo\w*\|cmds\w*\|con\w*\|copyc\w*\)\>"
197syn match sqlSetOptions contained "\<\(def\w*\|echo\|editf\w*\|emb\w*\|errorl\w*\|esc\w*\)\>"
198syn match sqlSetOptions contained "\<\(feed\w*\|flu\w*\|hea\w*\|heads\w*\|lin\w*\)\>"
199syn match sqlSetOptions contained "\<\(lobof\w*\|longc\w*\|mark\w*\|newp\w*\|numf\w*\)\>"
200syn match sqlSetOptions contained "\<\(pages\w*\|pau\w*\|serverout\w*\|shift\w*\|show\w*\)\>"
201syn match sqlSetOptions contained "\<\(sqlbl\w*\|sqlc\w*\|sqlco\w*\|sqln\w*\|sqlpluscompat\w*\)\>"
202syn match sqlSetOptions contained "\<\(sqlpre\w*\|sqlp\w*\|sqlt\w*\|suf\w*\|tab\)\>"
203syn match sqlSetOptions contained "\<\(term\w*\|timi\w*\|und\w*\|ver\w*\|wra\w\?\)\>"
204syn match sqlSetOptions contained "\<\(xquery\s\+\(baseuri\|ordering\|node\|context\)\)\>"
205syn keyword sqlSetValues contained all body byreference byvalue default
206syn keyword sqlSetValues contained entry fill head html identifier indent
207syn keyword sqlSetValues contained linenum local none off on size table truncate
208syn match sqlSetValues contained "\<\(ea\w*\|wr\w*\|imm\w*\|trace\w*\|expl\w*\|stat\w*\)\>"
209syn match sqlSetValues contained "\<\(intermed\w*\|pre\w*\|unl\w*\|for\w*\|wra\w*\|wor\w\?\)\>"
210syn match sqlSetValues contained "\<\(vis\w*\|inv\w*\)\>"
211syn match sqlSetValues contained "\<\(\(un\)\?ordered\)\>"
212
213let sh_minlines = 200
214let sh_maxlines = 2 * sh_minlines
215exec 'syn sync minlines=' . sh_minlines . ' maxlines=' . sh_maxlines
216
217highlight def link sqlComment Comment
218highlight def link sqlError Error
219highlight def link sqlFunction Function
220highlight def link sqlUnknownFunc Exception
221highlight def link sqlKeyword Special
222highlight def link sqlConditional Conditional
223highlight def link sqlNumber Number
224highlight def link sqlOperator Operator
225highlight def link sqlParen Comment
226highlight def link sqlParenEmpty Operator
227highlight def link sqlParenFunc Function
228highlight def link sqlSpecial Keyword
229highlight def link sqlStatement Statement
230highlight def link sqlString String
231highlight def link sqlTodo Todo
232highlight def link sqlType Type
233highlight def link sqlVariable Identifier
234
235highlight def link sqlAnyString sqlString
236highlight def link sqlAnyVariable sqlVariable
237highlight def link sqlSetOptions Operator
238highlight def link sqlSetValues Special
239
240let b:current_syntax = 'sql'