codemirror-rails 4.3 → 4.4

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.
@@ -369,6 +369,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
369
369
 
370
370
 
371
371
  ),
372
+ multiLineStrings: true,
372
373
  blockKeywords: words("catch class do else finally for forSome if match switch try while"),
373
374
  atoms: words("true false null"),
374
375
  hooks: {
@@ -461,13 +461,13 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
461
461
  "glyph-orientation-vertical", "text-anchor", "writing-mode"
462
462
  ], propertyKeywords = keySet(propertyKeywords_);
463
463
 
464
- var nonStandardPropertyKeywords = [
464
+ var nonStandardPropertyKeywords_ = [
465
465
  "scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
466
466
  "scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
467
467
  "scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
468
468
  "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
469
469
  "searchfield-results-decoration", "zoom"
470
- ], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords);
470
+ ], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
471
471
 
472
472
  var colorKeywords_ = [
473
473
  "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
@@ -589,7 +589,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
589
589
  ], fontProperties = keySet(fontProperties_);
590
590
 
591
591
  var allWords = mediaTypes_.concat(mediaFeatures_).concat(propertyKeywords_)
592
- .concat(nonStandardPropertyKeywords).concat(colorKeywords_).concat(valueKeywords_);
592
+ .concat(nonStandardPropertyKeywords_).concat(colorKeywords_).concat(valueKeywords_);
593
593
  CodeMirror.registerHelper("hintWords", "css", allWords);
594
594
 
595
595
  function tokenCComment(stream, state) {
@@ -298,6 +298,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
298
298
  var result = function() {
299
299
  var state = cx.state, indent = state.indented;
300
300
  if (state.lexical.type == "stat") indent = state.lexical.indented;
301
+ else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
302
+ indent = outer.indented;
301
303
  state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
302
304
  };
303
305
  result.lex = true;
@@ -0,0 +1,280 @@
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("kotlin", function (config, parserConfig) {
15
+ function words(str) {
16
+ var obj = {}, words = str.split(" ");
17
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
18
+ return obj;
19
+ }
20
+
21
+ var multiLineStrings = parserConfig.multiLineStrings;
22
+
23
+ var keywords = words(
24
+ "package continue return object while break class data trait throw super" +
25
+ " when type this else This try val var fun for is in if do as true false null get set");
26
+ var softKeywords = words("import" +
27
+ " where by get set abstract enum open annotation override private public internal" +
28
+ " protected catch out vararg inline finally final ref");
29
+ var blockKeywords = words("catch class do else finally for if where try while enum");
30
+ var atoms = words("null true false this");
31
+
32
+ var curPunc;
33
+
34
+ function tokenBase(stream, state) {
35
+ var ch = stream.next();
36
+ if (ch == '"' || ch == "'") {
37
+ return startString(ch, stream, state);
38
+ }
39
+ // Wildcard import w/o trailing semicolon (import smth.*)
40
+ if (ch == "." && stream.eat("*")) {
41
+ return "word";
42
+ }
43
+ if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
44
+ curPunc = ch;
45
+ return null;
46
+ }
47
+ if (/\d/.test(ch)) {
48
+ if (stream.eat(/eE/)) {
49
+ stream.eat(/\+\-/);
50
+ stream.eatWhile(/\d/);
51
+ }
52
+ return "number";
53
+ }
54
+ if (ch == "/") {
55
+ if (stream.eat("*")) {
56
+ state.tokenize.push(tokenComment);
57
+ return tokenComment(stream, state);
58
+ }
59
+ if (stream.eat("/")) {
60
+ stream.skipToEnd();
61
+ return "comment";
62
+ }
63
+ if (expectExpression(state.lastToken)) {
64
+ return startString(ch, stream, state);
65
+ }
66
+ }
67
+ // Commented
68
+ if (ch == "-" && stream.eat(">")) {
69
+ curPunc = "->";
70
+ return null;
71
+ }
72
+ if (/[\-+*&%=<>!?|\/~]/.test(ch)) {
73
+ stream.eatWhile(/[\-+*&%=<>|~]/);
74
+ return "operator";
75
+ }
76
+ stream.eatWhile(/[\w\$_]/);
77
+
78
+ var cur = stream.current();
79
+ if (atoms.propertyIsEnumerable(cur)) {
80
+ return "atom";
81
+ }
82
+ if (softKeywords.propertyIsEnumerable(cur)) {
83
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
84
+ return "softKeyword";
85
+ }
86
+
87
+ if (keywords.propertyIsEnumerable(cur)) {
88
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
89
+ return "keyword";
90
+ }
91
+ return "word";
92
+ }
93
+
94
+ tokenBase.isBase = true;
95
+
96
+ function startString(quote, stream, state) {
97
+ var tripleQuoted = false;
98
+ if (quote != "/" && stream.eat(quote)) {
99
+ if (stream.eat(quote)) tripleQuoted = true;
100
+ else return "string";
101
+ }
102
+ function t(stream, state) {
103
+ var escaped = false, next, end = !tripleQuoted;
104
+
105
+ while ((next = stream.next()) != null) {
106
+ if (next == quote && !escaped) {
107
+ if (!tripleQuoted) {
108
+ break;
109
+ }
110
+ if (stream.match(quote + quote)) {
111
+ end = true;
112
+ break;
113
+ }
114
+ }
115
+
116
+ if (quote == '"' && next == "$" && !escaped && stream.eat("{")) {
117
+ state.tokenize.push(tokenBaseUntilBrace());
118
+ return "string";
119
+ }
120
+
121
+ if (next == "$" && !escaped && !stream.eat(" ")) {
122
+ state.tokenize.push(tokenBaseUntilSpace());
123
+ return "string";
124
+ }
125
+ escaped = !escaped && next == "\\";
126
+ }
127
+ if (multiLineStrings)
128
+ state.tokenize.push(t);
129
+ if (end) state.tokenize.pop();
130
+ return "string";
131
+ }
132
+
133
+ state.tokenize.push(t);
134
+ return t(stream, state);
135
+ }
136
+
137
+ function tokenBaseUntilBrace() {
138
+ var depth = 1;
139
+
140
+ function t(stream, state) {
141
+ if (stream.peek() == "}") {
142
+ depth--;
143
+ if (depth == 0) {
144
+ state.tokenize.pop();
145
+ return state.tokenize[state.tokenize.length - 1](stream, state);
146
+ }
147
+ } else if (stream.peek() == "{") {
148
+ depth++;
149
+ }
150
+ return tokenBase(stream, state);
151
+ }
152
+
153
+ t.isBase = true;
154
+ return t;
155
+ }
156
+
157
+ function tokenBaseUntilSpace() {
158
+ function t(stream, state) {
159
+ if (stream.eat(/[\w]/)) {
160
+ var isWord = stream.eatWhile(/[\w]/);
161
+ if (isWord) {
162
+ state.tokenize.pop();
163
+ return "word";
164
+ }
165
+ }
166
+ state.tokenize.pop();
167
+ return "string";
168
+ }
169
+
170
+ t.isBase = true;
171
+ return t;
172
+ }
173
+
174
+ function tokenComment(stream, state) {
175
+ var maybeEnd = false, ch;
176
+ while (ch = stream.next()) {
177
+ if (ch == "/" && maybeEnd) {
178
+ state.tokenize.pop();
179
+ break;
180
+ }
181
+ maybeEnd = (ch == "*");
182
+ }
183
+ return "comment";
184
+ }
185
+
186
+ function expectExpression(last) {
187
+ return !last || last == "operator" || last == "->" || /[\.\[\{\(,;:]/.test(last) ||
188
+ last == "newstatement" || last == "keyword" || last == "proplabel";
189
+ }
190
+
191
+ function Context(indented, column, type, align, prev) {
192
+ this.indented = indented;
193
+ this.column = column;
194
+ this.type = type;
195
+ this.align = align;
196
+ this.prev = prev;
197
+ }
198
+
199
+ function pushContext(state, col, type) {
200
+ return state.context = new Context(state.indented, col, type, null, state.context);
201
+ }
202
+
203
+ function popContext(state) {
204
+ var t = state.context.type;
205
+ if (t == ")" || t == "]" || t == "}")
206
+ state.indented = state.context.indented;
207
+ return state.context = state.context.prev;
208
+ }
209
+
210
+ // Interface
211
+
212
+ return {
213
+ startState: function (basecolumn) {
214
+ return {
215
+ tokenize: [tokenBase],
216
+ context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
217
+ indented: 0,
218
+ startOfLine: true,
219
+ lastToken: null
220
+ };
221
+ },
222
+
223
+ token: function (stream, state) {
224
+ var ctx = state.context;
225
+ if (stream.sol()) {
226
+ if (ctx.align == null) ctx.align = false;
227
+ state.indented = stream.indentation();
228
+ state.startOfLine = true;
229
+ // Automatic semicolon insertion
230
+ if (ctx.type == "statement" && !expectExpression(state.lastToken)) {
231
+ popContext(state);
232
+ ctx = state.context;
233
+ }
234
+ }
235
+ if (stream.eatSpace()) return null;
236
+ curPunc = null;
237
+ var style = state.tokenize[state.tokenize.length - 1](stream, state);
238
+ if (style == "comment") return style;
239
+ if (ctx.align == null) ctx.align = true;
240
+ if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
241
+ // Handle indentation for {x -> \n ... }
242
+ else if (curPunc == "->" && ctx.type == "statement" && ctx.prev.type == "}") {
243
+ popContext(state);
244
+ state.context.align = false;
245
+ }
246
+ else if (curPunc == "{") pushContext(state, stream.column(), "}");
247
+ else if (curPunc == "[") pushContext(state, stream.column(), "]");
248
+ else if (curPunc == "(") pushContext(state, stream.column(), ")");
249
+ else if (curPunc == "}") {
250
+ while (ctx.type == "statement") ctx = popContext(state);
251
+ if (ctx.type == "}") ctx = popContext(state);
252
+ while (ctx.type == "statement") ctx = popContext(state);
253
+ }
254
+ else if (curPunc == ctx.type) popContext(state);
255
+ else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
256
+ pushContext(state, stream.column(), "statement");
257
+ state.startOfLine = false;
258
+ state.lastToken = curPunc || style;
259
+ return style;
260
+ },
261
+
262
+ indent: function (state, textAfter) {
263
+ if (!state.tokenize[state.tokenize.length - 1].isBase) return 0;
264
+ var firstChar = textAfter && textAfter.charAt(0), ctx = state.context;
265
+ if (ctx.type == "statement" && !expectExpression(state.lastToken)) ctx = ctx.prev;
266
+ var closing = firstChar == ctx.type;
267
+ if (ctx.type == "statement") {
268
+ return ctx.indented + (firstChar == "{" ? 0 : config.indentUnit);
269
+ }
270
+ else if (ctx.align) return ctx.column + (closing ? 0 : 1);
271
+ else return ctx.indented + (closing ? 0 : config.indentUnit);
272
+ },
273
+
274
+ electricChars: "{}"
275
+ };
276
+ });
277
+
278
+ CodeMirror.defineMIME("text/x-kotlin", "kotlin");
279
+
280
+ });
@@ -176,7 +176,7 @@ CodeMirror.defineMode("puppet", function () {
176
176
  // Match characters that we are going to assume
177
177
  // are trying to be regex
178
178
  if (ch == '/') {
179
- stream.match(/.*\//);
179
+ stream.match(/.*?\//);
180
180
  return 'variable-3';
181
181
  }
182
182
  // Match all the numbers
@@ -46,16 +46,30 @@ CodeMirror.defineMode("ruby", function(config) {
46
46
  var ch = stream.next(), m;
47
47
  if (ch == "`" || ch == "'" || ch == '"') {
48
48
  return chain(readQuoted(ch, "string", ch == '"' || ch == "`"), stream, state);
49
- } else if (ch == "/" && !stream.eol() && stream.peek() != " ") {
50
- if (stream.eat("=")) return "operator";
51
- return chain(readQuoted(ch, "string-2", true), stream, state);
49
+ } else if (ch == "/") {
50
+ var currentIndex = stream.current().length;
51
+ if (stream.skipTo("/")) {
52
+ var search_till = stream.current().length;
53
+ stream.backUp(stream.current().length - currentIndex);
54
+ var balance = 0; // balance brackets
55
+ while (stream.current().length < search_till) {
56
+ var chchr = stream.next();
57
+ if (chchr == "(") balance += 1;
58
+ else if (chchr == ")") balance -= 1;
59
+ if (balance < 0) break;
60
+ }
61
+ stream.backUp(stream.current().length - currentIndex);
62
+ if (balance == 0)
63
+ return chain(readQuoted(ch, "string-2", true), stream, state);
64
+ }
65
+ return "operator";
52
66
  } else if (ch == "%") {
53
67
  var style = "string", embed = true;
54
68
  if (stream.eat("s")) style = "atom";
55
69
  else if (stream.eat(/[WQ]/)) style = "string";
56
70
  else if (stream.eat(/[r]/)) style = "string-2";
57
71
  else if (stream.eat(/[wxq]/)) { style = "string"; embed = false; }
58
- var delim = stream.eat(/[^\w\s]/);
72
+ var delim = stream.eat(/[^\w\s=]/);
59
73
  if (!delim) return "operator";
60
74
  if (matching.propertyIsEnumerable(delim)) delim = matching[delim];
61
75
  return chain(readQuoted(delim, style, embed, true), stream, state);
@@ -9,6 +9,9 @@
9
9
  * @date 05.07.2013
10
10
  */
11
11
 
12
+ // Warning: Don't base other modes on this one. This here is a
13
+ // terrible way to write a mixed mode.
14
+
12
15
  (function(mod) {
13
16
  if (typeof exports == "object" && typeof module == "object") // CommonJS
14
17
  mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), require("../smarty/smarty"));
@@ -20,11 +23,10 @@
20
23
  "use strict";
21
24
 
22
25
  CodeMirror.defineMode("smartymixed", function(config) {
23
- var settings, regs, helpers, parsers,
24
- htmlMixedMode = CodeMirror.getMode(config, "htmlmixed"),
25
- smartyMode = CodeMirror.getMode(config, "smarty"),
26
+ var htmlMixedMode = CodeMirror.getMode(config, "htmlmixed");
27
+ var smartyMode = CodeMirror.getMode(config, "smarty");
26
28
 
27
- settings = {
29
+ var settings = {
28
30
  rightDelimiter: '}',
29
31
  leftDelimiter: '{'
30
32
  };
@@ -36,15 +38,18 @@ CodeMirror.defineMode("smartymixed", function(config) {
36
38
  settings.rightDelimiter = config.rightDelimiter;
37
39
  }
38
40
 
39
- regs = {
40
- smartyComment: new RegExp("^" + settings.leftDelimiter + "\\*"),
41
- literalOpen: new RegExp(settings.leftDelimiter + "literal" + settings.rightDelimiter),
42
- literalClose: new RegExp(settings.leftDelimiter + "\/literal" + settings.rightDelimiter),
43
- hasLeftDelimeter: new RegExp(".*" + settings.leftDelimiter),
44
- htmlHasLeftDelimeter: new RegExp("[^<>]*" + settings.leftDelimiter)
41
+ function reEsc(str) { return str.replace(/[^\s\w]/g, "\\$&"); }
42
+
43
+ var reLeft = reEsc(settings.leftDelimiter), reRight = reEsc(settings.rightDelimiter);
44
+ var regs = {
45
+ smartyComment: new RegExp("^" + reRight + "\\*"),
46
+ literalOpen: new RegExp(reLeft + "literal" + reRight),
47
+ literalClose: new RegExp(reLeft + "\/literal" + reRight),
48
+ hasLeftDelimeter: new RegExp(".*" + reLeft),
49
+ htmlHasLeftDelimeter: new RegExp("[^<>]*" + reLeft)
45
50
  };
46
51
 
47
- helpers = {
52
+ var helpers = {
48
53
  chain: function(stream, state, parser) {
49
54
  state.tokenize = parser;
50
55
  return parser(stream, state);
@@ -70,7 +75,7 @@ CodeMirror.defineMode("smartymixed", function(config) {
70
75
  }
71
76
  };
72
77
 
73
- parsers = {
78
+ var parsers = {
74
79
  html: function(stream, state) {
75
80
  if (!state.inLiteral && stream.match(regs.htmlHasLeftDelimeter, false) && state.htmlMixedState.htmlState.tagName === null) {
76
81
  state.tokenize = parsers.smarty;
@@ -291,7 +291,7 @@ CodeMirror.defineMode("vbscript", function(conf, parserConf) {
291
291
  style = state.tokenize(stream, state);
292
292
 
293
293
  current = stream.current();
294
- if (style.substr(0, 8) === 'variable' || style==='builtin' || style==='keyword'){//|| knownWords.indexOf(current.substring(1)) > -1) {
294
+ if (style && (style.substr(0, 8) === 'variable' || style==='builtin' || style==='keyword')){//|| knownWords.indexOf(current.substring(1)) > -1) {
295
295
  if (style === 'builtin' || style === 'keyword') style='variable';
296
296
  if (knownWords.indexOf(current.substr(1)) > -1) style='variable-2';
297
297
 
@@ -80,7 +80,7 @@ CodeMirror.defineMode("yaml", function() {
80
80
  }
81
81
 
82
82
  /* pairs (associative arrays) -> key */
83
- if (!state.pair && stream.match(/^\s*\S+(?=\s*:($|\s))/i)) {
83
+ if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) {
84
84
  state.pair = true;
85
85
  state.keyCol = stream.indentation();
86
86
  return "atom";