codemirror-rails 4.12 → 4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/codemirror.js +45 -22
  4. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +6 -4
  5. data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +1 -1
  6. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +12 -4
  7. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +14 -9
  8. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +94 -51
  9. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +2 -1
  10. data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +211 -123
  11. data/vendor/assets/javascripts/codemirror/addons/scroll/annotatescrollbar.js +36 -12
  12. data/vendor/assets/javascripts/codemirror/addons/search/matchesonscrollbar.js +9 -4
  13. data/vendor/assets/javascripts/codemirror/addons/selection/selection-pointer.js +3 -0
  14. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +31 -4
  15. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +46 -7
  16. data/vendor/assets/javascripts/codemirror/modes/clike.js +5 -1
  17. data/vendor/assets/javascripts/codemirror/modes/css.js +104 -55
  18. data/vendor/assets/javascripts/codemirror/modes/cypher.js +1 -1
  19. data/vendor/assets/javascripts/codemirror/modes/forth.js +180 -0
  20. data/vendor/assets/javascripts/codemirror/modes/go.js +1 -0
  21. data/vendor/assets/javascripts/codemirror/modes/idl.js +1 -1
  22. data/vendor/assets/javascripts/codemirror/modes/javascript.js +1 -1
  23. data/vendor/assets/javascripts/codemirror/modes/sql.js +1 -1
  24. data/vendor/assets/javascripts/codemirror/modes/stylus.js +444 -0
  25. data/vendor/assets/javascripts/codemirror/modes/verilog.js +192 -19
  26. data/vendor/assets/stylesheets/codemirror/themes/colorforth.css +33 -0
  27. metadata +4 -1
@@ -60,7 +60,7 @@
60
60
  };
61
61
  var indentUnit = config.indentUnit;
62
62
  var curPunc;
63
- var funcs = wordRegexp(["abs", "acos", "allShortestPaths", "asin", "atan", "atan2", "avg", "ceil", "coalesce", "collect", "cos", "cot", "count", "degrees", "e", "endnode", "exp", "extract", "filter", "floor", "haversin", "head", "id", "labels", "last", "left", "length", "log", "log10", "lower", "ltrim", "max", "min", "node", "nodes", "percentileCont", "percentileDisc", "pi", "radians", "rand", "range", "reduce", "rel", "relationship", "relationships", "replace", "right", "round", "rtrim", "shortestPath", "sign", "sin", "split", "sqrt", "startnode", "stdev", "stdevp", "str", "substring", "sum", "tail", "tan", "timestamp", "toFloat", "toInt", "trim", "type", "upper"]);
63
+ var funcs = wordRegexp(["abs", "acos", "allShortestPaths", "asin", "atan", "atan2", "avg", "ceil", "coalesce", "collect", "cos", "cot", "count", "degrees", "e", "endnode", "exp", "extract", "filter", "floor", "haversin", "head", "id", "keys", "labels", "last", "left", "length", "log", "log10", "lower", "ltrim", "max", "min", "node", "nodes", "percentileCont", "percentileDisc", "pi", "radians", "rand", "range", "reduce", "rel", "relationship", "relationships", "replace", "right", "round", "rtrim", "shortestPath", "sign", "sin", "split", "sqrt", "startnode", "stdev", "stdevp", "str", "substring", "sum", "tail", "tan", "timestamp", "toFloat", "toInt", "trim", "type", "upper"]);
64
64
  var preds = wordRegexp(["all", "and", "any", "has", "in", "none", "not", "or", "single", "xor"]);
65
65
  var keywords = wordRegexp(["as", "asc", "ascending", "assert", "by", "case", "commit", "constraint", "create", "csv", "cypher", "delete", "desc", "descending", "distinct", "drop", "else", "end", "explain", "false", "fieldterminator", "foreach", "from", "headers", "in", "index", "is", "limit", "load", "match", "merge", "null", "on", "optional", "order", "periodic", "profile", "remove", "return", "scan", "set", "skip", "start", "then", "true", "union", "unique", "unwind", "using", "when", "where", "with"]);
66
66
  var operatorChars = /[*+\-<>=&|~%^]/;
@@ -0,0 +1,180 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ // Author: Aliaksei Chapyzhenka
5
+
6
+ (function(mod) {
7
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
8
+ mod(require("../../lib/codemirror"));
9
+ else if (typeof define == "function" && define.amd) // AMD
10
+ define(["../../lib/codemirror"], mod);
11
+ else // Plain browser env
12
+ mod(CodeMirror);
13
+ })(function(CodeMirror) {
14
+ "use strict";
15
+
16
+ function toWordList(words) {
17
+ var ret = [];
18
+ words.split(' ').forEach(function(e){
19
+ ret.push({name: e});
20
+ });
21
+ return ret;
22
+ }
23
+
24
+ var coreWordList = toWordList(
25
+ 'INVERT AND OR XOR\
26
+ 2* 2/ LSHIFT RSHIFT\
27
+ 0= = 0< < > U< MIN MAX\
28
+ 2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP\
29
+ >R R> R@\
30
+ + - 1+ 1- ABS NEGATE\
31
+ S>D * M* UM*\
32
+ FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD\
33
+ HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2!\
34
+ ALIGN ALIGNED +! ALLOT\
35
+ CHAR [CHAR] [ ] BL\
36
+ FIND EXECUTE IMMEDIATE COUNT LITERAL STATE\
37
+ ; DOES> >BODY\
38
+ EVALUATE\
39
+ SOURCE >IN\
40
+ <# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL\
41
+ FILL MOVE\
42
+ . CR EMIT SPACE SPACES TYPE U. .R U.R\
43
+ ACCEPT\
44
+ TRUE FALSE\
45
+ <> U> 0<> 0>\
46
+ NIP TUCK ROLL PICK\
47
+ 2>R 2R@ 2R>\
48
+ WITHIN UNUSED MARKER\
49
+ I J\
50
+ TO\
51
+ COMPILE, [COMPILE]\
52
+ SAVE-INPUT RESTORE-INPUT\
53
+ PAD ERASE\
54
+ 2LITERAL DNEGATE\
55
+ D- D+ D0< D0= D2* D2/ D< D= DMAX DMIN D>S DABS\
56
+ M+ M*/ D. D.R 2ROT DU<\
57
+ CATCH THROW\
58
+ FREE RESIZE ALLOCATE\
59
+ CS-PICK CS-ROLL\
60
+ GET-CURRENT SET-CURRENT FORTH-WORDLIST GET-ORDER SET-ORDER\
61
+ PREVIOUS SEARCH-WORDLIST WORDLIST FIND ALSO ONLY FORTH DEFINITIONS ORDER\
62
+ -TRAILING /STRING SEARCH COMPARE CMOVE CMOVE> BLANK SLITERAL');
63
+
64
+ var immediateWordList = toWordList('IF ELSE THEN BEGIN WHILE REPEAT UNTIL RECURSE [IF] [ELSE] [THEN] ?DO DO LOOP +LOOP UNLOOP LEAVE EXIT AGAIN CASE OF ENDOF ENDCASE');
65
+
66
+ CodeMirror.defineMode('forth', function() {
67
+ function searchWordList (wordList, word) {
68
+ var i;
69
+ for (i = wordList.length - 1; i >= 0; i--) {
70
+ if (wordList[i].name === word.toUpperCase()) {
71
+ return wordList[i];
72
+ }
73
+ }
74
+ return undefined;
75
+ }
76
+ return {
77
+ startState: function() {
78
+ return {
79
+ state: '',
80
+ base: 10,
81
+ coreWordList: coreWordList,
82
+ immediateWordList: immediateWordList,
83
+ wordList: []
84
+ };
85
+ },
86
+ token: function (stream, stt) {
87
+ var mat;
88
+ if (stream.eatSpace()) {
89
+ return null;
90
+ }
91
+ if (stt.state === '') { // interpretation
92
+ if (stream.match(/^(\]|:NONAME)(\s|$)/i)) {
93
+ stt.state = ' compilation';
94
+ return 'builtin compilation';
95
+ }
96
+ mat = stream.match(/^(\:)\s+(\S+)(\s|$)+/);
97
+ if (mat) {
98
+ stt.wordList.push({name: mat[2].toUpperCase()});
99
+ stt.state = ' compilation';
100
+ return 'def' + stt.state;
101
+ }
102
+ mat = stream.match(/^(VARIABLE|2VARIABLE|CONSTANT|2CONSTANT|CREATE|POSTPONE|VALUE|WORD)\s+(\S+)(\s|$)+/i);
103
+ if (mat) {
104
+ stt.wordList.push({name: mat[2].toUpperCase()});
105
+ return 'def' + stt.state;
106
+ }
107
+ mat = stream.match(/^(\'|\[\'\])\s+(\S+)(\s|$)+/);
108
+ if (mat) {
109
+ return 'builtin' + stt.state;
110
+ }
111
+ } else { // compilation
112
+ // ; [
113
+ if (stream.match(/^(\;|\[)(\s)/)) {
114
+ stt.state = '';
115
+ stream.backUp(1);
116
+ return 'builtin compilation';
117
+ }
118
+ if (stream.match(/^(\;|\[)($)/)) {
119
+ stt.state = '';
120
+ return 'builtin compilation';
121
+ }
122
+ if (stream.match(/^(POSTPONE)\s+\S+(\s|$)+/)) {
123
+ return 'builtin';
124
+ }
125
+ }
126
+
127
+ // dynamic wordlist
128
+ mat = stream.match(/^(\S+)(\s+|$)/);
129
+ if (mat) {
130
+ if (searchWordList(stt.wordList, mat[1]) !== undefined) {
131
+ return 'variable' + stt.state;
132
+ }
133
+
134
+ // comments
135
+ if (mat[1] === '\\') {
136
+ stream.skipToEnd();
137
+ return 'comment' + stt.state;
138
+ }
139
+
140
+ // core words
141
+ if (searchWordList(stt.coreWordList, mat[1]) !== undefined) {
142
+ return 'builtin' + stt.state;
143
+ }
144
+ if (searchWordList(stt.immediateWordList, mat[1]) !== undefined) {
145
+ return 'keyword' + stt.state;
146
+ }
147
+
148
+ if (mat[1] === '(') {
149
+ stream.eatWhile(function (s) { return s !== ')'; });
150
+ stream.eat(')');
151
+ return 'comment' + stt.state;
152
+ }
153
+
154
+ // // strings
155
+ if (mat[1] === '.(') {
156
+ stream.eatWhile(function (s) { return s !== ')'; });
157
+ stream.eat(')');
158
+ return 'string' + stt.state;
159
+ }
160
+ if (mat[1] === 'S"' || mat[1] === '."' || mat[1] === 'C"') {
161
+ stream.eatWhile(function (s) { return s !== '"'; });
162
+ stream.eat('"');
163
+ return 'string' + stt.state;
164
+ }
165
+
166
+ // numbers
167
+ if (mat[1] - 0xfffffffff) {
168
+ return 'number' + stt.state;
169
+ }
170
+ // if (mat[1].match(/^[-+]?[0-9]+\.[0-9]*/)) {
171
+ // return 'number' + stt.state;
172
+ // }
173
+
174
+ return 'atom' + stt.state;
175
+ }
176
+ }
177
+ };
178
+ });
179
+ CodeMirror.defineMIME("text/x-forth", "forth");
180
+ });
@@ -117,6 +117,7 @@ CodeMirror.defineMode("go", function(config) {
117
117
  return state.context = new Context(state.indented, col, type, null, state.context);
118
118
  }
119
119
  function popContext(state) {
120
+ if (!state.context.prev) return;
120
121
  var t = state.context.type;
121
122
  if (t == ")" || t == "]" || t == "}")
122
123
  state.indented = state.context.indented;
@@ -275,7 +275,7 @@
275
275
 
276
276
  // Handle non-detected items
277
277
  stream.next();
278
- return 'error';
278
+ return null;
279
279
  };
280
280
 
281
281
  CodeMirror.defineMode('idl', function() {
@@ -118,7 +118,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
118
118
  } else if (state.lastType == "operator" || state.lastType == "keyword c" ||
119
119
  state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) {
120
120
  readRegexp(stream);
121
- stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
121
+ stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
122
122
  return ret("regexp", "string-2");
123
123
  } else {
124
124
  stream.eatWhile(isOperatorChar);
@@ -190,7 +190,7 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
190
190
 
191
191
  indent: function(state, textAfter) {
192
192
  var cx = state.context;
193
- if (!cx) return 0;
193
+ if (!cx) return CodeMirror.Pass;
194
194
  var closing = textAfter.charAt(0) == cx.type;
195
195
  if (cx.align) return cx.col + (closing ? 0 : 1);
196
196
  else return cx.indent + (closing ? 0 : config.indentUnit);
@@ -0,0 +1,444 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ CodeMirror.defineMode("stylus", function(config) {
15
+
16
+ var operatorsRegexp = /^(\?:?|\+[+=]?|-[\-=]?|\*[\*=]?|\/=?|[=!:\?]?=|<=?|>=?|%=?|&&|\|=?|\~|!|\^|\\)/,
17
+ delimitersRegexp = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/,
18
+ wordOperatorsRegexp = wordRegexp(wordOperators),
19
+ commonKeywordsRegexp = wordRegexp(commonKeywords),
20
+ commonAtomsRegexp = wordRegexp(commonAtoms),
21
+ commonDefRegexp = wordRegexp(commonDef),
22
+ vendorPrefixesRegexp = new RegExp(/^\-(moz|ms|o|webkit)-/),
23
+ cssValuesWithBracketsRegexp = new RegExp("^(" + cssValuesWithBrackets_.join("|") + ")\\([\\w\-\\#\\,\\.\\%\\s\\(\\)]*\\)");
24
+
25
+ var tokenBase = function(stream, state) {
26
+
27
+ if (stream.eatSpace()) return null;
28
+
29
+ var ch = stream.peek();
30
+
31
+ // Single line Comment
32
+ if (stream.match('//')) {
33
+ stream.skipToEnd();
34
+ return "comment";
35
+ }
36
+
37
+ // Multiline Comment
38
+ if (stream.match('/*')) {
39
+ state.tokenizer = multilineComment;
40
+ return state.tokenizer(stream, state);
41
+ }
42
+
43
+ // Strings
44
+ if (ch === '"' || ch === "'") {
45
+ stream.next();
46
+ state.tokenizer = buildStringTokenizer(ch);
47
+ return "string";
48
+ }
49
+
50
+ // Def
51
+ if (ch === "@") {
52
+ stream.next();
53
+ if (stream.match(/extend/)) {
54
+ dedent(state); // remove indentation after selectors
55
+ } else if (stream.match(/media[\w-\s]*[\w-]/)) {
56
+ indent(state);
57
+ } else if(stream.eatWhile(/[\w-]/)) {
58
+ if(stream.current().match(commonDefRegexp)) {
59
+ indent(state);
60
+ }
61
+ }
62
+ return "def";
63
+ }
64
+
65
+ // Number
66
+ if (stream.match(/^-?[0-9\.]/, false)) {
67
+
68
+ // Floats
69
+ if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i) || stream.match(/^-?\d+\.\d*/)) {
70
+
71
+ // Prevent from getting extra . on 1..
72
+ if (stream.peek() == ".") {
73
+ stream.backUp(1);
74
+ }
75
+ // Units
76
+ stream.eatWhile(/[a-z%]/i);
77
+ return "number";
78
+ }
79
+ // Integers
80
+ if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/) || stream.match(/^-?0(?![\dx])/i)) {
81
+ // Units
82
+ stream.eatWhile(/[a-z%]/i);
83
+ return "number";
84
+ }
85
+ }
86
+
87
+ // Hex color and id selector
88
+ if (ch === "#") {
89
+ stream.next();
90
+
91
+ // Hex color
92
+ if (stream.match(/^[0-9a-f]{6}|[0-9a-f]{3}/i)) {
93
+ return "atom";
94
+ }
95
+
96
+ // ID selector
97
+ if (stream.match(/^[\w-]+/i)) {
98
+ indent(state);
99
+ return "builtin";
100
+ }
101
+ }
102
+
103
+ // Vendor prefixes
104
+ if (stream.match(vendorPrefixesRegexp)) {
105
+ return "meta";
106
+ }
107
+
108
+ // Gradients and animation as CSS value
109
+ if (stream.match(cssValuesWithBracketsRegexp)) {
110
+ return "atom";
111
+ }
112
+
113
+ // Mixins / Functions with indentation
114
+ if (stream.sol() && stream.match(/^\.?[a-z][\w-]*\(/i)) {
115
+ stream.backUp(1);
116
+ indent(state);
117
+ return "keyword";
118
+ }
119
+
120
+ // Mixins / Functions
121
+ if (stream.match(/^\.?[a-z][\w-]*\(/i)) {
122
+ stream.backUp(1);
123
+ return "keyword";
124
+ }
125
+
126
+ // +Block mixins
127
+ if (stream.match(/^(\+|\-)[a-z][\w-]+\(/i)) {
128
+ stream.backUp(1);
129
+ indent(state);
130
+ return "keyword";
131
+ }
132
+
133
+ // url tokens
134
+ if (stream.match(/^url/) && stream.peek() === "(") {
135
+ state.tokenizer = urlTokens;
136
+ if(!stream.peek()) {
137
+ state.cursorHalf = 0;
138
+ }
139
+ return "atom";
140
+ }
141
+
142
+ // Class
143
+ if (stream.match(/^\.[a-z][\w-]*/i)) {
144
+ indent(state);
145
+ return "qualifier";
146
+ }
147
+
148
+ // & Parent Reference with BEM naming
149
+ if (stream.match(/^(_|__|-|--)[a-z0-9-]+/)) {
150
+ return "qualifier";
151
+ }
152
+
153
+ // Pseudo elements/classes
154
+ if (ch == ':' && stream.match(/^::?[\w-]+/)) {
155
+ indent(state);
156
+ return "variable-3";
157
+ }
158
+
159
+ // Conditionals
160
+ if (stream.match(wordRegexp(["for", "if", "else", "unless"]))) {
161
+ indent(state);
162
+ return "keyword";
163
+ }
164
+
165
+ // Keywords
166
+ if (stream.match(commonKeywordsRegexp)) {
167
+ return "keyword";
168
+ }
169
+
170
+ // Atoms
171
+ if (stream.match(commonAtomsRegexp)) {
172
+ return "atom";
173
+ }
174
+
175
+ // Variables
176
+ if (stream.match(/^\$?[a-z][\w-]+\s?=(\s|[\w-'"\$])/i)) {
177
+ stream.backUp(2);
178
+ var cssPropertie = stream.current().toLowerCase().match(/[\w-]+/)[0];
179
+ return cssProperties[cssPropertie] === undefined ? "variable-2" : "property";
180
+ } else if (stream.match(/\$[\w-\.]+/i)) {
181
+ return "variable-2";
182
+ } else if (stream.match(/\$?[\w-]+\.[\w-]+/i)) {
183
+ var cssTypeSelector = stream.current().toLowerCase().match(/[\w]+/)[0];
184
+ if(cssTypeSelectors[cssTypeSelector] === undefined) {
185
+ return "variable-2";
186
+ } else stream.backUp(stream.current().length);
187
+ }
188
+
189
+ // !important
190
+ if (ch === "!") {
191
+ stream.next();
192
+ return stream.match(/^[\w]+/) ? "keyword": "operator";
193
+ }
194
+
195
+ // / Root Reference
196
+ if (stream.match(/^\/(:|\.|#|[a-z])/)) {
197
+ stream.backUp(1);
198
+ return "variable-3";
199
+ }
200
+
201
+ // Operators and delimiters
202
+ if (stream.match(operatorsRegexp) || stream.match(wordOperatorsRegexp)) {
203
+ return "operator";
204
+ }
205
+ if (stream.match(delimitersRegexp)) {
206
+ return null;
207
+ }
208
+
209
+ // & Parent Reference
210
+ if (ch === "&") {
211
+ stream.next();
212
+ return "variable-3";
213
+ }
214
+
215
+ // Font family
216
+ if (stream.match(/^[A-Z][a-z0-9-]+/)) {
217
+ return "string";
218
+ }
219
+
220
+ // CSS rule
221
+ // NOTE: Some css selectors and property values have the same name
222
+ // (embed, menu, pre, progress, sub, table),
223
+ // so they will have the same color (.cm-atom).
224
+ if (stream.match(/[\w-]*/i)) {
225
+
226
+ var word = stream.current().toLowerCase();
227
+
228
+ if(cssProperties[word] !== undefined) {
229
+ // CSS property
230
+ if(!stream.eol())
231
+ return "property";
232
+ else
233
+ return "variable-2";
234
+
235
+ } else if(cssValues[word] !== undefined) {
236
+ // CSS value
237
+ return "atom";
238
+
239
+ } else if(cssTypeSelectors[word] !== undefined) {
240
+ // CSS type selectors
241
+ indent(state);
242
+ return "tag";
243
+
244
+ } else if(word) {
245
+ // By default variable-2
246
+ return "variable-2";
247
+ }
248
+ }
249
+
250
+ // Handle non-detected items
251
+ stream.next();
252
+ return null;
253
+
254
+ };
255
+
256
+ var tokenLexer = function(stream, state) {
257
+
258
+ if (stream.sol()) {
259
+ state.indentCount = 0;
260
+ }
261
+
262
+ var style = state.tokenizer(stream, state);
263
+ var current = stream.current();
264
+
265
+ if (stream.eol() && (current === "}" || current === ",")) {
266
+ dedent(state);
267
+ }
268
+
269
+ if (style !== null) {
270
+ var startOfToken = stream.pos - current.length;
271
+ var withCurrentIndent = startOfToken + (config.indentUnit * state.indentCount);
272
+
273
+ var newScopes = [];
274
+
275
+ for (var i = 0; i < state.scopes.length; i++) {
276
+ var scope = state.scopes[i];
277
+
278
+ if (scope.offset <= withCurrentIndent) {
279
+ newScopes.push(scope);
280
+ }
281
+ }
282
+
283
+ state.scopes = newScopes;
284
+ }
285
+
286
+ return style;
287
+ };
288
+
289
+ return {
290
+ startState: function() {
291
+ return {
292
+ tokenizer: tokenBase,
293
+ scopes: [{offset: 0, type: 'styl'}]
294
+ };
295
+ },
296
+
297
+ token: function(stream, state) {
298
+ var style = tokenLexer(stream, state);
299
+ state.lastToken = { style: style, content: stream.current() };
300
+ return style;
301
+ },
302
+
303
+ indent: function(state) {
304
+ return state.scopes[0].offset;
305
+ },
306
+
307
+ lineComment: "//",
308
+ fold: "indent"
309
+
310
+ };
311
+
312
+ function urlTokens(stream, state) {
313
+ var ch = stream.peek();
314
+
315
+ if (ch === ")") {
316
+ stream.next();
317
+ state.tokenizer = tokenBase;
318
+ return "operator";
319
+ } else if (ch === "(") {
320
+ stream.next();
321
+ stream.eatSpace();
322
+
323
+ return "operator";
324
+ } else if (ch === "'" || ch === '"') {
325
+ state.tokenizer = buildStringTokenizer(stream.next());
326
+ return "string";
327
+ } else {
328
+ state.tokenizer = buildStringTokenizer(")", false);
329
+ return "string";
330
+ }
331
+ }
332
+
333
+ function multilineComment(stream, state) {
334
+ if (stream.skipTo("*/")) {
335
+ stream.next();
336
+ stream.next();
337
+ state.tokenizer = tokenBase;
338
+ } else {
339
+ stream.next();
340
+ }
341
+ return "comment";
342
+ }
343
+
344
+ function buildStringTokenizer(quote, greedy) {
345
+
346
+ if(greedy == null) {
347
+ greedy = true;
348
+ }
349
+
350
+ function stringTokenizer(stream, state) {
351
+ var nextChar = stream.next();
352
+ var peekChar = stream.peek();
353
+ var previousChar = stream.string.charAt(stream.pos-2);
354
+
355
+ var endingString = ((nextChar !== "\\" && peekChar === quote) ||
356
+ (nextChar === quote && previousChar !== "\\"));
357
+
358
+ if (endingString) {
359
+ if (nextChar !== quote && greedy) {
360
+ stream.next();
361
+ }
362
+ state.tokenizer = tokenBase;
363
+ return "string";
364
+ } else if (nextChar === "#" && peekChar === "{") {
365
+ state.tokenizer = buildInterpolationTokenizer(stringTokenizer);
366
+ stream.next();
367
+ return "operator";
368
+ } else {
369
+ return "string";
370
+ }
371
+ }
372
+
373
+ return stringTokenizer;
374
+ }
375
+
376
+ function buildInterpolationTokenizer(currentTokenizer) {
377
+ return function(stream, state) {
378
+ if (stream.peek() === "}") {
379
+ stream.next();
380
+ state.tokenizer = currentTokenizer;
381
+ return "operator";
382
+ } else {
383
+ return tokenBase(stream, state);
384
+ }
385
+ };
386
+ }
387
+
388
+ function indent(state) {
389
+ if (state.indentCount == 0) {
390
+ state.indentCount++;
391
+ var lastScopeOffset = state.scopes[0].offset;
392
+ var currentOffset = lastScopeOffset + config.indentUnit;
393
+ state.scopes.unshift({ offset:currentOffset });
394
+ }
395
+ }
396
+
397
+ function dedent(state) {
398
+ if (state.scopes.length == 1) { return true; }
399
+ state.scopes.shift();
400
+ }
401
+
402
+ });
403
+
404
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
405
+ var cssTypeSelectors_ = ["a","abbr","address","area","article","aside","audio", "b", "base","bdi","bdo","bgsound","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"];
406
+ // https://github.com/csscomb/csscomb.js/blob/master/config/zen.json
407
+ var cssProperties_ = ["position","top","right","bottom","left","z-index","display","visibility","flex-direction","flex-order","flex-pack","float","clear","flex-align","overflow","overflow-x","overflow-y","overflow-scrolling","clip","box-sizing","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","min-width","min-height","max-width","max-height","width","height","outline","outline-width","outline-style","outline-color","outline-offset","border","border-spacing","border-collapse","border-width","border-style","border-color","border-top","border-top-width","border-top-style","border-top-color","border-right","border-right-width","border-right-style","border-right-color","border-bottom","border-bottom-width","border-bottom-style","border-bottom-color","border-left","border-left-width","border-left-style","border-left-color","border-radius","border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-image","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","border-top-image","border-right-image","border-bottom-image","border-left-image","border-corner-image","border-top-left-image","border-top-right-image","border-bottom-right-image","border-bottom-left-image","background","filter:progid:DXImageTransform\\.Microsoft\\.AlphaImageLoader","background-color","background-image","background-attachment","background-position","background-position-x","background-position-y","background-clip","background-origin","background-size","background-repeat","box-decoration-break","box-shadow","color","table-layout","caption-side","empty-cells","list-style","list-style-position","list-style-type","list-style-image","quotes","content","counter-increment","counter-reset","writing-mode","vertical-align","text-align","text-align-last","text-decoration","text-emphasis","text-emphasis-position","text-emphasis-style","text-emphasis-color","text-indent","-ms-text-justify","text-justify","text-outline","text-transform","text-wrap","text-overflow","text-overflow-ellipsis","text-overflow-mode","text-size-adjust","text-shadow","white-space","word-spacing","word-wrap","word-break","tab-size","hyphens","letter-spacing","font","font-weight","font-style","font-variant","font-size-adjust","font-stretch","font-size","font-family","src","line-height","opacity","filter:\\\\\\\\'progid:DXImageTransform.Microsoft.Alpha","filter:progid:DXImageTransform.Microsoft.Alpha\\(Opacity","interpolation-mode","filter","resize","cursor","nav-index","nav-up","nav-right","nav-down","nav-left","transition","transition-delay","transition-timing-function","transition-duration","transition-property","transform","transform-origin","animation","animation-name","animation-duration","animation-play-state","animation-timing-function","animation-delay","animation-iteration-count","animation-direction","pointer-events","unicode-bidi","direction","columns","column-span","column-width","column-count","column-fill","column-gap","column-rule","column-rule-width","column-rule-style","column-rule-color","break-before","break-inside","break-after","page-break-before","page-break-inside","page-break-after","orphans","widows","zoom","max-zoom","min-zoom","user-zoom","orientation","text-rendering","speak","animation-fill-mode","backface-visibility","user-drag","user-select","appearance"];
408
+ // https://github.com/codemirror/CodeMirror/blob/master/mode/css/css.js#L501
409
+ var cssValues_ = ["above","absolute","activeborder","activecaption","afar","after-white-space","ahead","alias","all","all-scroll","alternate","always","amharic","amharic-abegede","antialiased","appworkspace","arabic-indic","armenian","asterisks","auto","avoid","avoid-column","avoid-page","avoid-region","background","backwards","baseline","below","bidi-override","binary","bengali","block","block-axis","bold","bolder","border","border-box","both","bottom","break","break-all","break-word","button-bevel","buttonface","buttonhighlight","buttonshadow","buttontext","cambodian","capitalize","caps-lock-indicator","captiontext","caret","cell","center","checkbox","circle","cjk-earthly-branch","cjk-heavenly-stem","cjk-ideographic","clear","clip","close-quote","col-resize","collapse","column","compact","condensed","contain","content","content-box","context-menu","continuous","copy","cover","crop","cross","crosshair","currentcolor","cursive","dashed","decimal","decimal-leading-zero","default","default-button","destination-atop","destination-in","destination-out","destination-over","devanagari","disc","discard","document","dot-dash","dot-dot-dash","dotted","double","down","e-resize","ease","ease-in","ease-in-out","ease-out","element","ellipse","ellipsis","embed","end","ethiopic","ethiopic-abegede","ethiopic-abegede-am-et","ethiopic-abegede-gez","ethiopic-abegede-ti-er","ethiopic-abegede-ti-et","ethiopic-halehame-aa-er","ethiopic-halehame-aa-et","ethiopic-halehame-am-et","ethiopic-halehame-gez","ethiopic-halehame-om-et","ethiopic-halehame-sid-et","ethiopic-halehame-so-et","ethiopic-halehame-ti-er","ethiopic-halehame-ti-et","ethiopic-halehame-tig","ew-resize","expanded","extra-condensed","extra-expanded","fantasy","fast","fill","fixed","flat","footnotes","forwards","from","geometricPrecision","georgian","graytext","groove","gujarati","gurmukhi","hand","hangul","hangul-consonant","hebrew","help","hidden","hide","higher","highlight","highlighttext","hiragana","hiragana-iroha","horizontal","hsl","hsla","icon","ignore","inactiveborder","inactivecaption","inactivecaptiontext","infinite","infobackground","infotext","inherit","initial","inline","inline-axis","inline-block","inline-table","inset","inside","intrinsic","invert","italic","justify","kannada","katakana","katakana-iroha","keep-all","khmer","landscape","lao","large","larger","left","level","lighter","line-through","linear","lines","list-item","listbox","listitem","local","logical","loud","lower","lower-alpha","lower-armenian","lower-greek","lower-hexadecimal","lower-latin","lower-norwegian","lower-roman","lowercase","ltr","malayalam","match","media-controls-background","media-current-time-display","media-fullscreen-button","media-mute-button","media-play-button","media-return-to-realtime-button","media-rewind-button","media-seek-back-button","media-seek-forward-button","media-slider","media-sliderthumb","media-time-remaining-display","media-volume-slider","media-volume-slider-container","media-volume-sliderthumb","medium","menu","menulist","menulist-button","menulist-text","menulist-textfield","menutext","message-box","middle","min-intrinsic","mix","mongolian","monospace","move","multiple","myanmar","n-resize","narrower","ne-resize","nesw-resize","no-close-quote","no-drop","no-open-quote","no-repeat","none","normal","not-allowed","nowrap","ns-resize","nw-resize","nwse-resize","oblique","octal","open-quote","optimizeLegibility","optimizeSpeed","oriya","oromo","outset","outside","outside-shape","overlay","overline","padding","padding-box","painted","page","paused","persian","plus-darker","plus-lighter","pointer","polygon","portrait","pre","pre-line","pre-wrap","preserve-3d","progress","push-button","radio","read-only","read-write","read-write-plaintext-only","rectangle","region","relative","repeat","repeat-x","repeat-y","reset","reverse","rgb","rgba","ridge","right","round","row-resize","rtl","run-in","running","s-resize","sans-serif","scroll","scrollbar","se-resize","searchfield","searchfield-cancel-button","searchfield-decoration","searchfield-results-button","searchfield-results-decoration","semi-condensed","semi-expanded","separate","serif","show","sidama","single","skip-white-space","slide","slider-horizontal","slider-vertical","sliderthumb-horizontal","sliderthumb-vertical","slow","small-caps","small-caption","smaller","solid","somali","source-atop","source-in","source-out","source-over","space","square","square-button","start","static","status-bar","stretch","stroke","sub","subpixel-antialiased","super","sw-resize","table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row","table-row-group","telugu","text","text-bottom","text-top","textfield","thai","thick","thin","threeddarkshadow","threedface","threedhighlight","threedlightshadow","threedshadow","tibetan","tigre","tigrinya-er","tigrinya-er-abegede","tigrinya-et","tigrinya-et-abegede","to","top","transparent","ultra-condensed","ultra-expanded","underline","up","upper-alpha","upper-armenian","upper-greek","upper-hexadecimal","upper-latin","upper-norwegian","upper-roman","uppercase","urdu","url","vertical","vertical-text","visible","visibleFill","visiblePainted","visibleStroke","visual","w-resize","wait","wave","wider","window","windowframe","windowtext","x-large","x-small","xor","xx-large","xx-small","bicubic","optimizespeed","grayscale"];
410
+ var cssColorValues_ = ["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","grey","green","greenyellow","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];
411
+ var cssValuesWithBrackets_ = ["gradient","linear-gradient","radial-gradient","repeating-linear-gradient","repeating-radial-gradient","cubic-bezier","translateX","translateY","translate3d","rotate3d","scale","scale3d","perspective","skewX"];
412
+
413
+ var wordOperators = ["in", "and", "or", "not", "is a", "is", "isnt", "defined", "if unless"],
414
+ commonKeywords = ["for", "if", "else", "unless", "return"],
415
+ commonAtoms = ["null", "true", "false", "href", "title", "type", "not-allowed", "readonly", "disabled"],
416
+ commonDef = ["@font-face", "@keyframes", "@media", "@viewport", "@page", "@host", "@supports", "@block", "@css"],
417
+ cssTypeSelectors = keySet(cssTypeSelectors_),
418
+ cssProperties = keySet(cssProperties_),
419
+ cssValues = keySet(cssValues_.concat(cssColorValues_)),
420
+ hintWords = wordOperators.concat(commonKeywords,
421
+ commonAtoms,
422
+ commonDef,
423
+ cssTypeSelectors_,
424
+ cssProperties_,
425
+ cssValues_,
426
+ cssValuesWithBrackets_,
427
+ cssColorValues_);
428
+
429
+ function wordRegexp(words) {
430
+ return new RegExp("^((" + words.join(")|(") + "))\\b");
431
+ };
432
+
433
+ function keySet(array) {
434
+ var keys = {};
435
+ for (var i = 0; i < array.length; ++i) {
436
+ keys[array[i]] = true;
437
+ }
438
+ return keys;
439
+ };
440
+
441
+ CodeMirror.registerHelper("hintWords", "stylus", hintWords);
442
+ CodeMirror.defineMIME("text/x-styl", "stylus");
443
+
444
+ });