diff options
author | Pushkar Joshi | 2012-03-06 17:04:40 -0800 |
---|---|---|
committer | Pushkar Joshi | 2012-03-06 17:04:40 -0800 |
commit | 7a43958033906b2273de88bc2a26cda7a905d202 (patch) | |
tree | f71817e712c4b07a48257a4f0b206cf9033421df /imports/codemirror/mode/mysql/mysql.js | |
parent | 264e3d8e6d3624083d2fab9fe2560234553bb2ad (diff) | |
parent | 2e3943a8f751ec572066f168b58464c24b9f29e5 (diff) | |
download | ninja-7a43958033906b2273de88bc2a26cda7a905d202.tar.gz |
Merge branch 'master' into brushtool
Diffstat (limited to 'imports/codemirror/mode/mysql/mysql.js')
-rw-r--r-- | imports/codemirror/mode/mysql/mysql.js | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/imports/codemirror/mode/mysql/mysql.js b/imports/codemirror/mode/mysql/mysql.js new file mode 100644 index 00000000..dca5b0f6 --- /dev/null +++ b/imports/codemirror/mode/mysql/mysql.js | |||
@@ -0,0 +1,188 @@ | |||
1 | /* | ||
2 | * MySQL Mode for CodeMirror 2 by MySQL-Tools | ||
3 | * @author James Thorne (partydroid) | ||
4 | * @link http://github.com/partydroid/MySQL-Tools | ||
5 | * @link http://mysqltools.org | ||
6 | * @version 02/Jan/2012 | ||
7 | */ | ||
8 | CodeMirror.defineMode("mysql", function(config) { | ||
9 | var indentUnit = config.indentUnit; | ||
10 | var curPunc; | ||
11 | |||
12 | function wordRegexp(words) { | ||
13 | return new RegExp("^(?:" + words.join("|") + ")$", "i"); | ||
14 | } | ||
15 | var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri", | ||
16 | "isblank", "isliteral", "union", "a"]); | ||
17 | var keywords = wordRegexp([ | ||
18 | ('ACCESSIBLE'),('ALTER'),('AS'),('BEFORE'),('BINARY'),('BY'),('CASE'),('CHARACTER'),('COLUMN'),('CONTINUE'),('CROSS'),('CURRENT_TIMESTAMP'),('DATABASE'),('DAY_MICROSECOND'),('DEC'),('DEFAULT'), | ||
19 | ('DESC'),('DISTINCT'),('DOUBLE'),('EACH'),('ENCLOSED'),('EXIT'),('FETCH'),('FLOAT8'),('FOREIGN'),('GRANT'),('HIGH_PRIORITY'),('HOUR_SECOND'),('IN'),('INNER'),('INSERT'),('INT2'),('INT8'), | ||
20 | ('INTO'),('JOIN'),('KILL'),('LEFT'),('LINEAR'),('LOCALTIME'),('LONG'),('LOOP'),('MATCH'),('MEDIUMTEXT'),('MINUTE_SECOND'),('NATURAL'),('NULL'),('OPTIMIZE'),('OR'),('OUTER'),('PRIMARY'), | ||
21 | ('RANGE'),('READ_WRITE'),('REGEXP'),('REPEAT'),('RESTRICT'),('RIGHT'),('SCHEMAS'),('SENSITIVE'),('SHOW'),('SPECIFIC'),('SQLSTATE'),('SQL_CALC_FOUND_ROWS'),('STARTING'),('TERMINATED'), | ||
22 | ('TINYINT'),('TRAILING'),('UNDO'),('UNLOCK'),('USAGE'),('UTC_DATE'),('VALUES'),('VARCHARACTER'),('WHERE'),('WRITE'),('ZEROFILL'),('ALL'),('AND'),('ASENSITIVE'),('BIGINT'),('BOTH'),('CASCADE'), | ||
23 | ('CHAR'),('COLLATE'),('CONSTRAINT'),('CREATE'),('CURRENT_TIME'),('CURSOR'),('DAY_HOUR'),('DAY_SECOND'),('DECLARE'),('DELETE'),('DETERMINISTIC'),('DIV'),('DUAL'),('ELSEIF'),('EXISTS'),('FALSE'), | ||
24 | ('FLOAT4'),('FORCE'),('FULLTEXT'),('HAVING'),('HOUR_MINUTE'),('IGNORE'),('INFILE'),('INSENSITIVE'),('INT1'),('INT4'),('INTERVAL'),('ITERATE'),('KEYS'),('LEAVE'),('LIMIT'),('LOAD'),('LOCK'), | ||
25 | ('LONGTEXT'),('MASTER_SSL_VERIFY_SERVER_CERT'),('MEDIUMINT'),('MINUTE_MICROSECOND'),('MODIFIES'),('NO_WRITE_TO_BINLOG'),('ON'),('OPTIONALLY'),('OUT'),('PRECISION'),('PURGE'),('READS'), | ||
26 | ('REFERENCES'),('RENAME'),('REQUIRE'),('REVOKE'),('SCHEMA'),('SELECT'),('SET'),('SPATIAL'),('SQLEXCEPTION'),('SQL_BIG_RESULT'),('SSL'),('TABLE'),('TINYBLOB'),('TO'),('TRUE'),('UNIQUE'), | ||
27 | ('UPDATE'),('USING'),('UTC_TIMESTAMP'),('VARCHAR'),('WHEN'),('WITH'),('YEAR_MONTH'),('ADD'),('ANALYZE'),('ASC'),('BETWEEN'),('BLOB'),('CALL'),('CHANGE'),('CHECK'),('CONDITION'),('CONVERT'), | ||
28 | ('CURRENT_DATE'),('CURRENT_USER'),('DATABASES'),('DAY_MINUTE'),('DECIMAL'),('DELAYED'),('DESCRIBE'),('DISTINCTROW'),('DROP'),('ELSE'),('ESCAPED'),('EXPLAIN'),('FLOAT'),('FOR'),('FROM'), | ||
29 | ('GROUP'),('HOUR_MICROSECOND'),('IF'),('INDEX'),('INOUT'),('INT'),('INT3'),('INTEGER'),('IS'),('KEY'),('LEADING'),('LIKE'),('LINES'),('LOCALTIMESTAMP'),('LONGBLOB'),('LOW_PRIORITY'), | ||
30 | ('MEDIUMBLOB'),('MIDDLEINT'),('MOD'),('NOT'),('NUMERIC'),('OPTION'),('ORDER'),('OUTFILE'),('PROCEDURE'),('READ'),('REAL'),('RELEASE'),('REPLACE'),('RETURN'),('RLIKE'),('SECOND_MICROSECOND'), | ||
31 | ('SEPARATOR'),('SMALLINT'),('SQL'),('SQLWARNING'),('SQL_SMALL_RESULT'),('STRAIGHT_JOIN'),('THEN'),('TINYTEXT'),('TRIGGER'),('UNION'),('UNSIGNED'),('USE'),('UTC_TIME'),('VARBINARY'),('VARYING'), | ||
32 | ('WHILE'),('XOR'),('FULL'),('COLUMNS'),('MIN'),('MAX'),('STDEV'),('COUNT') | ||
33 | ]); | ||
34 | var operatorChars = /[*+\-<>=&|]/; | ||
35 | |||
36 | function tokenBase(stream, state) { | ||
37 | var ch = stream.next(); | ||
38 | curPunc = null; | ||
39 | if (ch == "$" || ch == "?") { | ||
40 | stream.match(/^[\w\d]*/); | ||
41 | return "variable-2"; | ||
42 | } | ||
43 | else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) { | ||
44 | stream.match(/^[^\s\u00a0>]*>?/); | ||
45 | return "atom"; | ||
46 | } | ||
47 | else if (ch == "\"" || ch == "'") { | ||
48 | state.tokenize = tokenLiteral(ch); | ||
49 | return state.tokenize(stream, state); | ||
50 | } | ||
51 | else if (ch == "`") { | ||
52 | state.tokenize = tokenOpLiteral(ch); | ||
53 | return state.tokenize(stream, state); | ||
54 | } | ||
55 | else if (/[{}\(\),\.;\[\]]/.test(ch)) { | ||
56 | curPunc = ch; | ||
57 | return null; | ||
58 | } | ||
59 | else if (ch == "-") { | ||
60 | ch2 = stream.next(); | ||
61 | if(ch2=="-") | ||
62 | { | ||
63 | stream.skipToEnd(); | ||
64 | return "comment"; | ||
65 | } | ||
66 | |||
67 | } | ||
68 | else if (operatorChars.test(ch)) { | ||
69 | stream.eatWhile(operatorChars); | ||
70 | return null; | ||
71 | } | ||
72 | else if (ch == ":") { | ||
73 | stream.eatWhile(/[\w\d\._\-]/); | ||
74 | return "atom"; | ||
75 | } | ||
76 | else { | ||
77 | stream.eatWhile(/[_\w\d]/); | ||
78 | if (stream.eat(":")) { | ||
79 | stream.eatWhile(/[\w\d_\-]/); | ||
80 | return "atom"; | ||
81 | } | ||
82 | var word = stream.current(), type; | ||
83 | if (ops.test(word)) | ||
84 | return null; | ||
85 | else if (keywords.test(word)) | ||
86 | return "keyword"; | ||
87 | else | ||
88 | return "variable"; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | function tokenLiteral(quote) { | ||
93 | return function(stream, state) { | ||
94 | var escaped = false, ch; | ||
95 | while ((ch = stream.next()) != null) { | ||
96 | if (ch == quote && !escaped) { | ||
97 | state.tokenize = tokenBase; | ||
98 | break; | ||
99 | } | ||
100 | escaped = !escaped && ch == "\\"; | ||
101 | } | ||
102 | return "string"; | ||
103 | }; | ||
104 | } | ||
105 | |||
106 | function tokenOpLiteral(quote) { | ||
107 | return function(stream, state) { | ||
108 | var escaped = false, ch; | ||
109 | while ((ch = stream.next()) != null) { | ||
110 | if (ch == quote && !escaped) { | ||
111 | state.tokenize = tokenBase; | ||
112 | break; | ||
113 | } | ||
114 | escaped = !escaped && ch == "\\"; | ||
115 | } | ||
116 | return "variable-2"; | ||
117 | }; | ||
118 | } | ||
119 | |||
120 | |||
121 | function pushContext(state, type, col) { | ||
122 | state.context = {prev: state.context, indent: state.indent, col: col, type: type}; | ||
123 | } | ||
124 | function popContext(state) { | ||
125 | state.indent = state.context.indent; | ||
126 | state.context = state.context.prev; | ||
127 | } | ||
128 | |||
129 | return { | ||
130 | startState: function(base) { | ||
131 | return {tokenize: tokenBase, | ||
132 | context: null, | ||
133 | indent: 0, | ||
134 | col: 0}; | ||
135 | }, | ||
136 | |||
137 | token: function(stream, state) { | ||
138 | if (stream.sol()) { | ||
139 | if (state.context && state.context.align == null) state.context.align = false; | ||
140 | state.indent = stream.indentation(); | ||
141 | } | ||
142 | if (stream.eatSpace()) return null; | ||
143 | var style = state.tokenize(stream, state); | ||
144 | |||
145 | if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") { | ||
146 | state.context.align = true; | ||
147 | } | ||
148 | |||
149 | if (curPunc == "(") pushContext(state, ")", stream.column()); | ||
150 | else if (curPunc == "[") pushContext(state, "]", stream.column()); | ||
151 | else if (curPunc == "{") pushContext(state, "}", stream.column()); | ||
152 | else if (/[\]\}\)]/.test(curPunc)) { | ||
153 | while (state.context && state.context.type == "pattern") popContext(state); | ||
154 | if (state.context && curPunc == state.context.type) popContext(state); | ||
155 | } | ||
156 | else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state); | ||
157 | else if (/atom|string|variable/.test(style) && state.context) { | ||
158 | if (/[\}\]]/.test(state.context.type)) | ||
159 | pushContext(state, "pattern", stream.column()); | ||
160 | else if (state.context.type == "pattern" && !state.context.align) { | ||
161 | state.context.align = true; | ||
162 | state.context.col = stream.column(); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | return style; | ||
167 | }, | ||
168 | |||
169 | indent: function(state, textAfter) { | ||
170 | var firstChar = textAfter && textAfter.charAt(0); | ||
171 | var context = state.context; | ||
172 | if (/[\]\}]/.test(firstChar)) | ||
173 | while (context && context.type == "pattern") context = context.prev; | ||
174 | |||
175 | var closing = context && firstChar == context.type; | ||
176 | if (!context) | ||
177 | return 0; | ||
178 | else if (context.type == "pattern") | ||
179 | return context.col; | ||
180 | else if (context.align) | ||
181 | return context.col + (closing ? 0 : 1); | ||
182 | else | ||
183 | return context.indent + (closing ? 0 : indentUnit); | ||
184 | } | ||
185 | }; | ||
186 | }); | ||
187 | |||
188 | CodeMirror.defineMIME("text/x-mysql", "mysql"); | ||