codemirror-rails 0.3.2 → 2.2

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.
@@ -136,7 +136,9 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
136
136
 
137
137
  indent: function(state, textAfter) {
138
138
  if (state.tokenize != tokenBase && state.tokenize != null) return 0;
139
- var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
139
+ var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
140
+ if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
141
+ var closing = firstChar == ctx.type;
140
142
  if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
141
143
  else if (ctx.align) return ctx.column + (closing ? 0 : 1);
142
144
  else return ctx.indented + (closing ? 0 : indentUnit);
@@ -50,7 +50,7 @@ CodeMirror.defineMode("groovy", function(config, parserConfig) {
50
50
  return "operator";
51
51
  }
52
52
  stream.eatWhile(/[\w\$_]/);
53
- if (ch == "@") return "meta";
53
+ if (ch == "@") { stream.eatWhile(/[\w\$_\.]/); return "meta"; }
54
54
  if (state.lastToken == ".") return "property";
55
55
  if (stream.eat(":")) { curPunc = "proplabel"; return "property"; }
56
56
  var cur = stream.current();
@@ -0,0 +1,68 @@
1
+ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
2
+
3
+ //config settings
4
+ var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
5
+ scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
6
+
7
+ //inner modes
8
+ var scriptingMode, htmlMixedMode;
9
+
10
+ //tokenizer when in html mode
11
+ function htmlDispatch(stream, state) {
12
+ if (stream.match(scriptStartRegex, false)) {
13
+ state.token=scriptingDispatch;
14
+ return scriptingMode.token(stream, state.scriptState);
15
+ }
16
+ else
17
+ return htmlMixedMode.token(stream, state.htmlState);
18
+ }
19
+
20
+ //tokenizer when in scripting mode
21
+ function scriptingDispatch(stream, state) {
22
+ if (stream.match(scriptEndRegex, false)) {
23
+ state.token=htmlDispatch;
24
+ return htmlMixedMode.token(stream, state.htmlState);
25
+ }
26
+ else
27
+ return scriptingMode.token(stream, state.scriptState);
28
+ }
29
+
30
+
31
+ return {
32
+ startState: function() {
33
+ scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
34
+ htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
35
+ return {
36
+ token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
37
+ htmlState : htmlMixedMode.startState(),
38
+ scriptState : scriptingMode.startState()
39
+ }
40
+ },
41
+
42
+ token: function(stream, state) {
43
+ return state.token(stream, state);
44
+ },
45
+
46
+ indent: function(state, textAfter) {
47
+ if (state.token == htmlDispatch)
48
+ return htmlMixedMode.indent(state.htmlState, textAfter);
49
+ else
50
+ return scriptingMode.indent(state.scriptState, textAfter);
51
+ },
52
+
53
+ copyState: function(state) {
54
+ return {
55
+ token : state.token,
56
+ htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
57
+ scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
58
+ }
59
+ },
60
+
61
+
62
+ electricChars: "/{}:"
63
+ }
64
+ });
65
+
66
+ CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
67
+ CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
68
+ CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
@@ -87,7 +87,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
87
87
  else {
88
88
  stream.eatWhile(/[\w\$_]/);
89
89
  var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
90
- return known ? ret(known.type, known.style, word) :
90
+ return (known && state.kwAllowed) ? ret(known.type, known.style, word) :
91
91
  ret("variable", "variable", word);
92
92
  }
93
93
  }
@@ -316,6 +316,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
316
316
  return {
317
317
  tokenize: jsTokenBase,
318
318
  reAllowed: true,
319
+ kwAllowed: true,
319
320
  cc: [],
320
321
  lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
321
322
  localVars: null,
@@ -334,6 +335,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
334
335
  var style = state.tokenize(stream, state);
335
336
  if (type == "comment") return style;
336
337
  state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/);
338
+ state.kwAllowed = type != '.';
337
339
  return parseJS(state, style, type, content, stream);
338
340
  },
339
341
 
@@ -3,12 +3,12 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
3
3
  var htmlMode = CodeMirror.getMode(cmCfg, { name: 'xml', htmlMode: true });
4
4
 
5
5
  var header = 'header'
6
- , code = 'code'
6
+ , code = 'comment'
7
7
  , quote = 'quote'
8
- , list = 'list'
8
+ , list = 'string'
9
9
  , hr = 'hr'
10
- , linktext = 'linktext'
11
- , linkhref = 'linkhref'
10
+ , linktext = 'link'
11
+ , linkhref = 'string'
12
12
  , em = 'em'
13
13
  , strong = 'strong'
14
14
  , emstrong = 'emstrong';
@@ -42,9 +42,9 @@
42
42
  };
43
43
 
44
44
  CodeMirror.defineMode("php", function(config, parserConfig) {
45
- var htmlMode = CodeMirror.getMode(config, "text/html");
46
- var jsMode = CodeMirror.getMode(config, "text/javascript");
47
- var cssMode = CodeMirror.getMode(config, "text/css");
45
+ var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
46
+ var jsMode = CodeMirror.getMode(config, "javascript");
47
+ var cssMode = CodeMirror.getMode(config, "css");
48
48
  var phpMode = CodeMirror.getMode(config, phpConfig);
49
49
 
50
50
  function dispatch(stream, state) { // TODO open PHP inside text/css
@@ -183,6 +183,10 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
183
183
  type = type || 'py';
184
184
  var indentUnit = 0;
185
185
  if (type === 'py') {
186
+ if (state.scopes[0].type !== 'py') {
187
+ state.scopes[0].offset = stream.indentation();
188
+ return;
189
+ }
186
190
  for (var i = 0; i < state.scopes.length; ++i) {
187
191
  if (state.scopes[i].type === 'py') {
188
192
  indentUnit = state.scopes[i].offset + conf.indentUnit;
@@ -198,7 +202,8 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
198
202
  });
199
203
  }
200
204
 
201
- function dedent(stream, state) {
205
+ function dedent(stream, state, type) {
206
+ type = type || 'py';
202
207
  if (state.scopes.length == 1) return;
203
208
  if (state.scopes[0].type === 'py') {
204
209
  var _indent = stream.indentation();
@@ -217,8 +222,16 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
217
222
  }
218
223
  return false
219
224
  } else {
220
- state.scopes.shift();
221
- return false;
225
+ if (type === 'py') {
226
+ state.scopes[0].offset = stream.indentation();
227
+ return false;
228
+ } else {
229
+ if (state.scopes[0].type != type) {
230
+ return true;
231
+ }
232
+ state.scopes.shift();
233
+ return false;
234
+ }
222
235
  }
223
236
  }
224
237
 
@@ -270,7 +283,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
270
283
  }
271
284
  delimiter_index = '])}'.indexOf(current);
272
285
  if (delimiter_index !== -1) {
273
- if (dedent(stream, state)) {
286
+ if (dedent(stream, state, current)) {
274
287
  return ERRORCLASS;
275
288
  }
276
289
  }
@@ -73,7 +73,7 @@ CodeMirror.defineMode('rst', function(config, options) {
73
73
 
74
74
  if (i >= 3 && stream.match(/^\s*$/)) {
75
75
  setNormal(state, null);
76
- return 'section';
76
+ return 'header';
77
77
  } else {
78
78
  stream.backUp(i + 1);
79
79
  }
@@ -83,8 +83,7 @@ CodeMirror.defineMode('rst', function(config, options) {
83
83
  if (!stream.eol()) {
84
84
  setState(state, directive);
85
85
  }
86
-
87
- return 'directive-marker';
86
+ return 'meta';
88
87
  }
89
88
 
90
89
  if (stream.match(reVerbatimMarker)) {
@@ -98,14 +97,13 @@ CodeMirror.defineMode('rst', function(config, options) {
98
97
  local: mode.startState()
99
98
  });
100
99
  }
101
-
102
- return 'verbatim-marker';
100
+ return 'meta';
103
101
  }
104
102
 
105
103
  if (sol && stream.match(reExamples, false)) {
106
104
  if (!pythonMode) {
107
105
  setState(state, verbatim);
108
- return 'verbatim-marker';
106
+ return 'meta';
109
107
  } else {
110
108
  var mode = pythonMode;
111
109
 
@@ -118,12 +116,6 @@ CodeMirror.defineMode('rst', function(config, options) {
118
116
  }
119
117
  }
120
118
 
121
- if (sol && (stream.match(reEnumeratedList) ||
122
- stream.match(reBulletedList))) {
123
- setNormal(state, stream);
124
- return 'list';
125
- }
126
-
127
119
  function testBackward(re) {
128
120
  return sol || !state.ctx.back || re.test(state.ctx.back);
129
121
  }
@@ -153,9 +145,9 @@ CodeMirror.defineMode('rst', function(config, options) {
153
145
  var token;
154
146
 
155
147
  if (ch === ':') {
156
- token = 'role';
148
+ token = 'builtin';
157
149
  } else {
158
- token = 'replacement';
150
+ token = 'atom';
159
151
  }
160
152
 
161
153
  setState(state, inline, {
@@ -183,9 +175,9 @@ CodeMirror.defineMode('rst', function(config, options) {
183
175
  var token;
184
176
 
185
177
  if (orig === '*') {
186
- token = wide ? 'strong' : 'emphasis';
178
+ token = wide ? 'strong' : 'em';
187
179
  } else {
188
- token = wide ? 'inline' : 'interpreted';
180
+ token = wide ? 'string' : 'string-2';
189
181
  }
190
182
 
191
183
  setState(state, inline, {
@@ -247,13 +239,13 @@ CodeMirror.defineMode('rst', function(config, options) {
247
239
  var token = null;
248
240
 
249
241
  if (stream.match(reDirective)) {
250
- token = 'directive';
242
+ token = 'attribute';
251
243
  } else if (stream.match(reHyperlink)) {
252
- token = 'hyperlink';
244
+ token = 'link';
253
245
  } else if (stream.match(reFootnote)) {
254
- token = 'footnote';
246
+ token = 'quote';
255
247
  } else if (stream.match(reCitation)) {
256
- token = 'citation';
248
+ token = 'quote';
257
249
  } else {
258
250
  stream.eatSpace();
259
251
 
@@ -267,6 +259,7 @@ CodeMirror.defineMode('rst', function(config, options) {
267
259
  }
268
260
  }
269
261
 
262
+ // FIXME this is unreachable
270
263
  setState(state, body, {start: true});
271
264
  return token;
272
265
  }
@@ -290,7 +283,7 @@ CodeMirror.defineMode('rst', function(config, options) {
290
283
 
291
284
  function verbatim(stream, state) {
292
285
  if (!verbatimMode) {
293
- return block(stream, state, 'verbatim');
286
+ return block(stream, state, 'meta');
294
287
  } else {
295
288
  if (stream.sol()) {
296
289
  if (!stream.eatSpace()) {
@@ -1,132 +1,139 @@
1
- CodeMirror.defineMode("smalltalk", function(config, parserConfig) {
2
- var keywords = {"true": 1, "false": 1, nil: 1, self: 1, "super": 1, thisContext: 1};
3
- var indentUnit = config.indentUnit;
4
-
5
- function chain(stream, state, f) {
6
- state.tokenize = f;
7
- return f(stream, state);
8
- }
9
-
10
- var type;
11
- function ret(tp, style) {
12
- type = tp;
13
- return style;
14
- }
15
-
16
- function tokenBase(stream, state) {
17
- var ch = stream.next();
18
- if (ch == '"')
19
- return chain(stream, state, tokenComment(ch));
20
- else if (ch == "'")
21
- return chain(stream, state, tokenString(ch));
22
- else if (ch == "#") {
23
- stream.eatWhile(/[\w\$_]/);
24
- return ret("string", "string");
25
- }
26
- else if (ch == '$') {
27
- if (stream.next() == "<") {
28
- stream.eatWhile(/\d/);
29
- stream.eat(/\>/);
30
- }
31
- return ret("string", "string");
32
- }
33
- else if (ch == "^" || (ch == ":" && stream.eat("="))) {
34
- return ret("operator", "operator");
35
- }
36
- else if (/\d/.test(ch)) {
37
- stream.eatWhile(/[\w\.]/)
38
- return ret("number", "number");
39
- }
40
- else if (/[\[\]()]/.test(ch)) {
41
- return ret(ch, null);
42
- }
43
- else {
44
- stream.eatWhile(/[\w\$_]/);
45
- if (keywords && keywords.propertyIsEnumerable(stream.current())) return ret("keyword", "keyword");
46
- return ret("word", "variable");
47
- }
48
- }
49
-
50
- function tokenString(quote) {
51
- return function(stream, state) {
52
- var escaped = false, next, end = false;
53
- while ((next = stream.next()) != null) {
54
- if (next == quote && !escaped) {end = true; break;}
55
- escaped = !escaped && next == "\\";
56
- }
57
- if (end || !(escaped))
58
- state.tokenize = tokenBase;
59
- return ret("string", "string");
60
- };
61
- }
62
-
63
- function tokenComment(quote) {
64
- return function(stream, state) {
65
- var next, end = false;
66
- while ((next = stream.next()) != null) {
67
- if (next == quote) {end = true; break;}
68
- }
69
- if (end)
70
- state.tokenize = tokenBase;
71
- return ret("comment", "comment");
72
- };
73
- }
74
-
75
- function Context(indented, column, type, align, prev) {
76
- this.indented = indented;
77
- this.column = column;
78
- this.type = type;
79
- this.align = align;
80
- this.prev = prev;
81
- }
82
-
83
- function pushContext(state, col, type) {
84
- return state.context = new Context(state.indented, col, type, null, state.context);
85
- }
86
- function popContext(state) {
87
- return state.context = state.context.prev;
88
- }
89
-
90
- // Interface
91
-
92
- return {
93
- startState: function(basecolumn) {
94
- return {
95
- tokenize: tokenBase,
96
- context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
97
- indented: 0,
98
- startOfLine: true
99
- };
100
- },
101
-
102
- token: function(stream, state) {
103
- var ctx = state.context;
104
- if (stream.sol()) {
105
- if (ctx.align == null) ctx.align = false;
106
- state.indented = stream.indentation();
107
- state.startOfLine = true;
108
- }
109
- if (stream.eatSpace()) return null;
110
- var style = state.tokenize(stream, state);
111
- if (type == "comment") return style;
112
- if (ctx.align == null) ctx.align = true;
113
-
114
- if (type == "[") pushContext(state, stream.column(), "]");
115
- else if (type == "(") pushContext(state, stream.column(), ")");
116
- else if (type == ctx.type) popContext(state);
117
- state.startOfLine = false;
118
- return style;
119
- },
120
-
121
- indent: function(state, textAfter) {
122
- if (state.tokenize != tokenBase) return 0;
123
- var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
124
- if (ctx.align) return ctx.column + (closing ? 0 : 1);
125
- else return ctx.indented + (closing ? 0 : indentUnit);
126
- },
127
-
128
- electricChars: "]"
129
- };
1
+ CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
2
+
3
+ var specialChars = /[+\-/\\*~<>=@%|&?!.:;^]/;
4
+ var keywords = /true|false|nil|self|super|thisContext/;
5
+
6
+ var Context = function(tokenizer, parent) {
7
+ this.next = tokenizer;
8
+ this.parent = parent;
9
+ };
10
+
11
+ var Token = function(name, context, eos) {
12
+ this.name = name;
13
+ this.context = context;
14
+ this.eos = eos;
15
+ };
16
+
17
+ var State = function() {
18
+ this.context = new Context(next, null);
19
+ this.expectVariable = true;
20
+ this.indentation = 0;
21
+ this.userIndentationDelta = 0;
22
+ };
23
+
24
+ State.prototype.userIndent = function(indentation) {
25
+ this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;
26
+ };
27
+
28
+ var next = function(stream, context, state) {
29
+ var token = new Token(null, context, false);
30
+ var char = stream.next();
31
+
32
+ if (char === '"') {
33
+ token = nextComment(stream, new Context(nextComment, context));
34
+
35
+ } else if (char === '\'') {
36
+ token = nextString(stream, new Context(nextString, context));
37
+
38
+ } else if (char === '#') {
39
+ stream.eatWhile(/[^ .]/);
40
+ token.name = 'string-2';
41
+
42
+ } else if (char === '$') {
43
+ stream.eatWhile(/[^ ]/);
44
+ token.name = 'string-2';
45
+
46
+ } else if (char === '|' && state.expectVariable) {
47
+ token.context = new Context(nextTemporaries, context);
48
+
49
+ } else if (/[\[\]{}()]/.test(char)) {
50
+ token.name = 'bracket';
51
+ token.eos = /[\[{(]/.test(char);
52
+
53
+ if (char === '[') {
54
+ state.indentation++;
55
+ } else if (char === ']') {
56
+ state.indentation = Math.max(0, state.indentation - 1);
57
+ }
58
+
59
+ } else if (specialChars.test(char)) {
60
+ stream.eatWhile(specialChars);
61
+ token.name = 'operator';
62
+ token.eos = char !== ';'; // ; cascaded message expression
63
+
64
+ } else if (/\d/.test(char)) {
65
+ stream.eatWhile(/[\w\d]/);
66
+ token.name = 'number'
67
+
68
+ } else if (/[\w_]/.test(char)) {
69
+ stream.eatWhile(/[\w\d_]/);
70
+ token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;
71
+
72
+ } else {
73
+ token.eos = state.expectVariable;
74
+ }
75
+
76
+ return token;
77
+ };
78
+
79
+ var nextComment = function(stream, context) {
80
+ stream.eatWhile(/[^"]/);
81
+ return new Token('comment', stream.eat('"') ? context.parent : context, true);
82
+ };
83
+
84
+ var nextString = function(stream, context) {
85
+ stream.eatWhile(/[^']/);
86
+ return new Token('string', stream.eat('\'') ? context.parent : context, false);
87
+ };
88
+
89
+ var nextTemporaries = function(stream, context, state) {
90
+ var token = new Token(null, context, false);
91
+ var char = stream.next();
92
+
93
+ if (char === '|') {
94
+ token.context = context.parent;
95
+ token.eos = true;
96
+
97
+ } else {
98
+ stream.eatWhile(/[^|]/);
99
+ token.name = 'variable';
100
+ }
101
+
102
+ return token;
103
+ }
104
+
105
+ return {
106
+ startState: function() {
107
+ return new State;
108
+ },
109
+
110
+ token: function(stream, state) {
111
+ state.userIndent(stream.indentation());
112
+
113
+ if (stream.eatSpace()) {
114
+ return null;
115
+ }
116
+
117
+ var token = state.context.next(stream, state.context, state);
118
+ state.context = token.context;
119
+ state.expectVariable = token.eos;
120
+
121
+ state.lastToken = token;
122
+ return token.name;
123
+ },
124
+
125
+ blankLine: function(state) {
126
+ state.userIndent(0);
127
+ },
128
+
129
+ indent: function(state, textAfter) {
130
+ var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
131
+ return (state.indentation + i) * config.indentUnit;
132
+ },
133
+
134
+ electricChars: ']'
135
+ };
136
+
130
137
  });
131
138
 
132
- CodeMirror.defineMIME("text/x-stsrc", {name: "smalltalk"});
139
+ CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});