diff options
author | Ananya Sen | 2012-02-27 14:41:21 -0800 |
---|---|---|
committer | Ananya Sen | 2012-02-27 14:41:21 -0800 |
commit | 51ed781953bc44bba3c70938aa57b856394cbc88 (patch) | |
tree | 483bcacdcdcc6802d2d048b576406b111656fa05 /imports/codemirror/mode/mysql | |
parent | 15d00c49b522aa471d1ccfbbd33f5c0e721eb89e (diff) | |
download | ninja-51ed781953bc44bba3c70938aa57b856394cbc88.tar.gz |
updating to codemirror 2.22
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'imports/codemirror/mode/mysql')
-rw-r--r-- | imports/codemirror/mode/mysql/index.html | 41 | ||||
-rw-r--r-- | imports/codemirror/mode/mysql/mysql.js | 188 |
2 files changed, 229 insertions, 0 deletions
diff --git a/imports/codemirror/mode/mysql/index.html b/imports/codemirror/mode/mysql/index.html new file mode 100644 index 00000000..006918c0 --- /dev/null +++ b/imports/codemirror/mode/mysql/index.html | |||
@@ -0,0 +1,41 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: MySQL mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="mysql.js"></script> | ||
8 | <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
9 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
10 | </head> | ||
11 | <body> | ||
12 | <h1>CodeMirror: MySQL mode</h1> | ||
13 | <form><textarea id="code" name="code"> | ||
14 | -- Comment for the code | ||
15 | -- MySQL Mode for CodeMirror2 by MySQLTools http://github.com/partydroid/MySQL-Tools | ||
16 | SELECT UNIQUE `var1` as `variable`, | ||
17 | MAX(`var5`) as `max`, | ||
18 | MIN(`var5`) as `min`, | ||
19 | STDEV(`var5`) as `dev` | ||
20 | FROM `table` | ||
21 | |||
22 | LEFT JOIN `table2` ON `var2` = `variable` | ||
23 | |||
24 | ORDER BY `var3` DESC | ||
25 | GROUP BY `groupvar` | ||
26 | |||
27 | LIMIT 0,30; | ||
28 | |||
29 | </textarea></form> | ||
30 | <script> | ||
31 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
32 | mode: "text/x-mysql", | ||
33 | tabMode: "indent", | ||
34 | matchBrackets: true | ||
35 | }); | ||
36 | </script> | ||
37 | |||
38 | <p><strong>MIME types defined:</strong> <code>text/x-mysql</code>.</p> | ||
39 | |||
40 | </body> | ||
41 | </html> | ||
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; | ||