Mercurial > kallithea
annotate rhodecode/public/js/mode/sql/sql.js @ 4029:c9bcfe2d2ade
codecleaner
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 21 Jun 2013 01:11:16 +0200 |
parents | a60a0e9092c6 |
children |
rev | line source |
---|---|
4026
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 CodeMirror.defineMode("sql", function(config, parserConfig) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 "use strict"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 var client = parserConfig.client || {}, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 atoms = parserConfig.atoms || {"false": true, "true": true, "null": true}, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 builtin = parserConfig.builtin || {}, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 keywords = parserConfig.keywords || {}, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 operatorChars = parserConfig.operatorChars || /^[*+\-%<>!=&|~^]/, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 support = parserConfig.support || {}, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 hooks = parserConfig.hooks || {}, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 dateSQL = parserConfig.dateSQL || {"date" : true, "time" : true, "timestamp" : true}; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 function tokenBase(stream, state) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 var ch = stream.next(); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 // call hooks from the mime type |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 if (hooks[ch]) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 var result = hooks[ch](stream, state); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 if (result !== false) return result; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 if (support.hexNumber == true && |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 ((ch == "0" && stream.match(/^[xX][0-9a-fA-F]+/)) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 || (ch == "x" || ch == "X") && stream.match(/^'[0-9a-fA-F]+'/))) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 // hex |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 // ref: http://dev.mysql.com/doc/refman/5.5/en/hexadecimal-literals.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 return "number"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 } else if (support.binaryNumber == true && |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 (((ch == "b" || ch == "B") && stream.match(/^'[01]+'/)) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 || (ch == "0" && stream.match(/^b[01]+/)))) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 // bitstring |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 // ref: http://dev.mysql.com/doc/refman/5.5/en/bit-field-literals.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 return "number"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 } else if (ch.charCodeAt(0) > 47 && ch.charCodeAt(0) < 58) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 // numbers |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 // ref: http://dev.mysql.com/doc/refman/5.5/en/number-literals.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 stream.match(/^[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 support.decimallessFloat == true && stream.eat('.'); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 return "number"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 } else if (ch == "?" && (stream.eatSpace() || stream.eol() || stream.eat(";"))) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 // placeholders |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 return "variable-3"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 } else if (ch == "'" || (ch == '"' && support.doubleQuote)) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 // strings |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 // ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 state.tokenize = tokenLiteral(ch); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 return state.tokenize(stream, state); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 } else if ((((support.nCharCast == true && (ch == "n" || ch == "N")) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 || (support.charsetCast == true && ch == "_" && stream.match(/[a-z][a-z0-9]*/i))) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 && (stream.peek() == "'" || stream.peek() == '"'))) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 // charset casting: _utf8'str', N'str', n'str' |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 // ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 return "keyword"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 } else if (/^[\(\),\;\[\]]/.test(ch)) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 // no highlightning |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 return null; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 } else if (support.commentSlashSlash && ch == "/" && stream.eat("/")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 // 1-line comment |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 stream.skipToEnd(); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 return "comment"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 } else if ((support.commentHash && ch == "#") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 || (ch == "-" && stream.eat("-") && (!support.commentSpaceRequired || stream.eat(" ")))) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 // 1-line comments |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 // ref: https://kb.askmonty.org/en/comment-syntax/ |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 stream.skipToEnd(); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 return "comment"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 } else if (ch == "/" && stream.eat("*")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 // multi-line comments |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 // ref: https://kb.askmonty.org/en/comment-syntax/ |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 state.tokenize = tokenComment; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 return state.tokenize(stream, state); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 } else if (ch == ".") { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 // .1 for 0.1 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 if (support.zerolessFloat == true && stream.match(/^(?:\d+(?:e[+-]?\d+)?)/i)) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 return "number"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 // .table_name (ODBC) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 // // ref: http://dev.mysql.com/doc/refman/5.6/en/identifier-qualifiers.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 if (support.ODBCdotTable == true && stream.match(/^[a-zA-Z_]+/)) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 return "variable-2"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 } else if (operatorChars.test(ch)) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 // operators |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 stream.eatWhile(operatorChars); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 return null; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 } else if (ch == '{' && |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 (stream.match(/^( )*(d|D|t|T|ts|TS)( )*'[^']*'( )*}/) || stream.match(/^( )*(d|D|t|T|ts|TS)( )*"[^"]*"( )*}/))) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 // dates (weird ODBC syntax) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 // ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 return "number"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 } else { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 stream.eatWhile(/^[_\w\d]/); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 var word = stream.current().toLowerCase(); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 // dates (standard SQL syntax) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 // ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 if (dateSQL.hasOwnProperty(word) && (stream.match(/^( )+'[^']*'/) || stream.match(/^( )+"[^"]*"/))) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 return "number"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 if (atoms.hasOwnProperty(word)) return "atom"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 if (builtin.hasOwnProperty(word)) return "builtin"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 if (keywords.hasOwnProperty(word)) return "keyword"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 if (client.hasOwnProperty(word)) return "string-2"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 return null; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 // 'string', with char specified in quote escaped by '\' |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 function tokenLiteral(quote) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 return function(stream, state) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 var escaped = false, ch; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 while ((ch = stream.next()) != null) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 if (ch == quote && !escaped) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 state.tokenize = tokenBase; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 break; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 escaped = !escaped && ch == "\\"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 return "string"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 function tokenComment(stream, state) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 while (true) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 if (stream.skipTo("*")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 stream.next(); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 if (stream.eat("/")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 state.tokenize = tokenBase; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 break; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 } else { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 stream.skipToEnd(); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 break; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 return "comment"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 function pushContext(stream, state, type) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 state.context = { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 prev: state.context, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 indent: stream.indentation(), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 col: stream.column(), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 type: type |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 function popContext(state) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 state.indent = state.context.indent; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 state.context = state.context.prev; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 return { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 startState: function() { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 return {tokenize: tokenBase, context: null}; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 }, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 token: function(stream, state) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 if (stream.sol()) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
157 if (state.context && state.context.align == null) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 state.context.align = false; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
159 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 if (stream.eatSpace()) return null; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 var style = state.tokenize(stream, state); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 if (style == "comment") return style; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 if (state.context && state.context.align == null) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 state.context.align = true; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 var tok = stream.current(); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 if (tok == "(") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 pushContext(stream, state, ")"); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 else if (tok == "[") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 pushContext(stream, state, "]"); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 else if (state.context && state.context.type == tok) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 popContext(state); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 return style; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
176 }, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 indent: function(state, textAfter) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 var cx = state.context; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 if (!cx) return CodeMirror.Pass; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
181 if (cx.align) return cx.col + (textAfter.charAt(0) == cx.type ? 0 : 1); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 else return cx.indent + config.indentUnit; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
185 }); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
186 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 (function() { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 "use strict"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
190 // `identifier` |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 function hookIdentifier(stream) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 // MySQL/MariaDB identifiers |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 // ref: http://dev.mysql.com/doc/refman/5.6/en/identifier-qualifiers.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 var ch; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 while ((ch = stream.next()) != null) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 if (ch == "`" && !stream.eat("`")) return "variable-2"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 return null; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 // variable token |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 function hookVar(stream) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
203 // variables |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 // @@prefix.varName @varName |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 // varName can be quoted with ` or ' or " |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 // ref: http://dev.mysql.com/doc/refman/5.5/en/user-variables.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
207 if (stream.eat("@")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
208 stream.match(/^session\./); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 stream.match(/^local\./); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 stream.match(/^global\./); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
211 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
213 if (stream.eat("'")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 stream.match(/^.*'/); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
215 return "variable-2"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 } else if (stream.eat('"')) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 stream.match(/^.*"/); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 return "variable-2"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
219 } else if (stream.eat("`")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
220 stream.match(/^.*`/); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
221 return "variable-2"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
222 } else if (stream.match(/^[0-9a-zA-Z$\.\_]+/)) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
223 return "variable-2"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
224 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
225 return null; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
226 }; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
227 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
228 // short client keyword token |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
229 function hookClient(stream) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
230 // \N means NULL |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
231 // ref: http://dev.mysql.com/doc/refman/5.5/en/null-values.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
232 if (stream.eat("N")) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
233 return "atom"; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
234 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
235 // \g, etc |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
236 // ref: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
237 return stream.match(/^[a-zA-Z.#!?]/) ? "variable-2" : null; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
238 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
239 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
240 // these keywords are used by all SQL dialects (however, a mode can still overwrite it) |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
241 var sqlKeywords = "alter and as asc between by count create delete desc distinct drop from having in insert into is join like not on or order select set table union update values where "; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
242 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
243 // turn a space-separated list into an array |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
244 function set(str) { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
245 var obj = {}, words = str.split(" "); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
246 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
247 return obj; |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
248 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
249 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
250 // A generic SQL Mode. It's not a standard, it just try to support what is generally supported |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
251 CodeMirror.defineMIME("text/x-sql", { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
252 name: "sql", |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
253 keywords: set(sqlKeywords + "begin"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
254 builtin: set("bool boolean bit blob enum long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision real date datetime year unsigned signed decimal numeric"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
255 atoms: set("false true null unknown"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
256 operatorChars: /^[*+\-%<>!=]/, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
257 dateSQL: set("date time timestamp"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
258 support: set("ODBCdotTable doubleQuote binaryNumber hexNumber") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
259 }); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
260 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
261 CodeMirror.defineMIME("text/x-mysql", { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
262 name: "sql", |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
263 client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
264 keywords: set(sqlKeywords + "accessible action add after algorithm all analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general global grant grants group groupby_concat handler hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show signal slave slow smallint snapshot soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
265 builtin: set("bool boolean bit blob decimal double enum float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
266 atoms: set("false true null unknown"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
267 operatorChars: /^[*+\-%<>!=&|^]/, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
268 dateSQL: set("date time timestamp"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
269 support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber doubleQuote nCharCast charsetCast commentHash commentSpaceRequired"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
270 hooks: { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
271 "@": hookVar, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
272 "`": hookIdentifier, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
273 "\\": hookClient |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
274 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
275 }); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
276 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
277 CodeMirror.defineMIME("text/x-mariadb", { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
278 name: "sql", |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
279 client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
280 keywords: set(sqlKeywords + "accessible action add after algorithm all always analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general generated global grant grants group groupby_concat handler hard hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password persistent phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show signal slave slow smallint snapshot soft soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views virtual warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
281 builtin: set("bool boolean bit blob decimal double enum float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 atoms: set("false true null unknown"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
283 operatorChars: /^[*+\-%<>!=&|^]/, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
284 dateSQL: set("date time timestamp"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber doubleQuote nCharCast charsetCast commentHash commentSpaceRequired"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
286 hooks: { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
287 "@": hookVar, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
288 "`": hookIdentifier, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
289 "\\": hookClient |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
290 } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
291 }); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
292 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
293 // the query language used by Apache Cassandra is called CQL, but this mime type |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
294 // is called Cassandra to avoid confusion with Contextual Query Language |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
295 CodeMirror.defineMIME("text/x-cassandra", { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
296 name: "sql", |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
297 client: { }, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
298 keywords: set("use select from using consistency where limit first reversed first and in insert into values using consistency ttl update set delete truncate begin batch apply create keyspace with columnfamily primary key index on drop alter type add any one quorum all local_quorum each_quorum"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 builtin: set("ascii bigint blob boolean counter decimal double float int text timestamp uuid varchar varint"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
300 atoms: set("false true"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
301 operatorChars: /^[<>=]/, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
302 dateSQL: { }, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
303 support: set("commentSlashSlash decimallessFloat"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
304 hooks: { } |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
305 }); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
306 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
307 // this is based on Peter Raganitsch's 'plsql' mode |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
308 CodeMirror.defineMIME("text/x-plsql", { |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
309 name: "sql", |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
310 client: set("appinfo arraysize autocommit autoprint autorecovery autotrace blockterminator break btitle cmdsep colsep compatibility compute concat copycommit copytypecheck define describe echo editfile embedded escape exec execute feedback flagger flush heading headsep instance linesize lno loboffset logsource long longchunksize markup native newpage numformat numwidth pagesize pause pno recsep recsepchar release repfooter repheader serveroutput shiftinout show showmode size spool sqlblanklines sqlcase sqlcode sqlcontinue sqlnumber sqlpluscompatibility sqlprefix sqlprompt sqlterminator suffix tab term termout time timing trimout trimspool ttitle underline verify version wrap"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
311 keywords: set("abort accept access add all alter and any array arraylen as asc assert assign at attributes audit authorization avg base_table begin between binary_integer body boolean by case cast char char_base check close cluster clusters colauth column comment commit compress connect connected constant constraint crash create current currval cursor data_base database date dba deallocate debugoff debugon decimal declare default definition delay delete desc digits dispose distinct do drop else elsif enable end entry escape exception exception_init exchange exclusive exists exit external fast fetch file for force form from function generic goto grant group having identified if immediate in increment index indexes indicator initial initrans insert interface intersect into is key level library like limited local lock log logging long loop master maxextents maxtrans member minextents minus mislabel mode modify multiset new next no noaudit nocompress nologging noparallel not nowait number_base object of off offline on online only open option or order out package parallel partition pctfree pctincrease pctused pls_integer positive positiven pragma primary prior private privileges procedure public raise range raw read rebuild record ref references refresh release rename replace resource restrict return returning reverse revoke rollback row rowid rowlabel rownum rows run savepoint schema segment select separate session set share snapshot some space split sql start statement storage subtype successful synonym tabauth table tables tablespace task terminate then to trigger truncate type union unique unlimited unrecoverable unusable update use using validate value values variable view views when whenever where while with work"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
312 functions: set("abs acos add_months ascii asin atan atan2 average bfilename ceil chartorowid chr concat convert cos cosh count decode deref dual dump dup_val_on_index empty error exp false floor found glb greatest hextoraw initcap instr instrb isopen last_day least lenght lenghtb ln lower lpad ltrim lub make_ref max min mod months_between new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower nls_sort nls_upper nlssort no_data_found notfound null nvl others power rawtohex reftohex round rowcount rowidtochar rpad rtrim sign sin sinh soundex sqlcode sqlerrm sqrt stddev substr substrb sum sysdate tan tanh to_char to_date to_label to_multi_byte to_number to_single_byte translate true trunc uid upper user userenv variance vsize"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
313 builtin: set("bfile blob character clob dec float int integer mlslabel natural naturaln nchar nclob number numeric nvarchar2 real rowtype signtype smallint string varchar varchar2"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
314 operatorChars: /^[*+\-%<>!=~]/, |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
315 dateSQL: set("date time timestamp"), |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
316 support: set("doubleQuote nCharCast zerolessFloat binaryNumber hexNumber") |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
317 }); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
318 }()); |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
319 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
320 /* |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
321 How Properties of Mime Types are used by SQL Mode |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
322 ================================================= |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
323 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
324 keywords: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
325 A list of keywords you want to be highlighted. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
326 functions: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
327 A list of function names you want to be highlighted. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
328 builtin: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
329 A list of builtin types you want to be highlighted (if you want types to be of class "builtin" instead of "keyword"). |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
330 operatorChars: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
331 All characters that must be handled as operators. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
332 client: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
333 Commands parsed and executed by the client (not the server). |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
334 support: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
335 A list of supported syntaxes which are not common, but are supported by more than 1 DBMS. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
336 * ODBCdotTable: .tableName |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
337 * zerolessFloat: .1 |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
338 * doubleQuote |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
339 * nCharCast: N'string' |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
340 * charsetCast: _utf8'string' |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
341 * commentHash: use # char for comments |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
342 * commentSlashSlash: use // for comments |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
343 * commentSpaceRequired: require a space after -- for comments |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
344 atoms: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
345 Keywords that must be highlighted as atoms,. Some DBMS's support more atoms than others: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
346 UNKNOWN, INFINITY, UNDERFLOW, NaN... |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
347 dateSQL: |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
348 Used for date/time SQL standard syntax, because not all DBMS's support same temporal types. |
a60a0e9092c6
added codemirror edit mode with autodetection
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
349 */ |