codemirror-rails 3.02 → 3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/LICENSE +1 -1
  4. data/codemirror-rails.gemspec +1 -0
  5. data/doc/CodeMirror-LICENSE +5 -1
  6. data/lib/codemirror/rails/version.rb +2 -2
  7. data/vendor/assets/javascripts/codemirror/{utils → addons/dialog}/dialog.js +4 -0
  8. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +54 -0
  9. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +54 -0
  10. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/closetag.js +9 -8
  11. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/continuecomment.js +12 -4
  12. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -0
  13. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/matchbrackets.js +30 -11
  14. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +31 -0
  15. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +32 -0
  16. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +11 -0
  17. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +64 -0
  18. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +582 -0
  19. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/javascript-hint.js +15 -11
  20. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/pig-hint.js +19 -19
  21. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/python-hint.js +2 -2
  22. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +180 -0
  23. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/xml-hint.js +5 -18
  24. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +127 -0
  25. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +14 -0
  26. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +197 -0
  27. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/loadmode.js +0 -0
  28. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/multiplex.js +2 -2
  29. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/overlay.js +2 -2
  30. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/colorize.js +0 -0
  31. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode-standalone.js +2 -3
  32. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode.js +0 -0
  33. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +89 -0
  34. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +60 -0
  35. data/vendor/assets/javascripts/codemirror/{utils → addons/search}/search.js +5 -5
  36. data/vendor/assets/javascripts/codemirror/{utils → addons/search}/searchcursor.js +37 -30
  37. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +39 -0
  38. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +34 -0
  39. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +721 -188
  40. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +6 -6
  41. data/vendor/assets/javascripts/codemirror/modes/clike.js +14 -14
  42. data/vendor/assets/javascripts/codemirror/modes/clojure.js +23 -7
  43. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +2 -2
  44. data/vendor/assets/javascripts/codemirror/modes/css.js +337 -235
  45. data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -12
  46. data/vendor/assets/javascripts/codemirror/modes/erlang.js +1 -1
  47. data/vendor/assets/javascripts/codemirror/modes/gas.js +326 -0
  48. data/vendor/assets/javascripts/codemirror/modes/gfm.js +1 -0
  49. data/vendor/assets/javascripts/codemirror/modes/haskell.js +26 -26
  50. data/vendor/assets/javascripts/codemirror/modes/haxe.js +17 -17
  51. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +6 -6
  52. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +43 -23
  53. data/vendor/assets/javascripts/codemirror/modes/javascript.js +78 -33
  54. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +2 -2
  55. data/vendor/assets/javascripts/codemirror/modes/less.js +38 -38
  56. data/vendor/assets/javascripts/codemirror/modes/livescript.js +267 -0
  57. data/vendor/assets/javascripts/codemirror/modes/lua.js +7 -7
  58. data/vendor/assets/javascripts/codemirror/modes/markdown.js +108 -57
  59. data/vendor/assets/javascripts/codemirror/modes/mirc.js +177 -0
  60. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +22 -22
  61. data/vendor/assets/javascripts/codemirror/modes/ocaml.js +1 -1
  62. data/vendor/assets/javascripts/codemirror/modes/perl.js +791 -791
  63. data/vendor/assets/javascripts/codemirror/modes/php.js +1 -1
  64. data/vendor/assets/javascripts/codemirror/modes/pig.js +163 -163
  65. data/vendor/assets/javascripts/codemirror/modes/python.js +31 -31
  66. data/vendor/assets/javascripts/codemirror/modes/q.js +124 -0
  67. data/vendor/assets/javascripts/codemirror/modes/rst.js +486 -250
  68. data/vendor/assets/javascripts/codemirror/modes/sass.js +3 -3
  69. data/vendor/assets/javascripts/codemirror/modes/scss_test.js +80 -0
  70. data/vendor/assets/javascripts/codemirror/modes/shell.js +2 -2
  71. data/vendor/assets/javascripts/codemirror/modes/sieve.js +10 -10
  72. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +129 -129
  73. data/vendor/assets/javascripts/codemirror/modes/smarty.js +3 -3
  74. data/vendor/assets/javascripts/codemirror/modes/sparql.js +1 -1
  75. data/vendor/assets/javascripts/codemirror/modes/sql.js +23 -23
  76. data/vendor/assets/javascripts/codemirror/modes/stex.js +192 -121
  77. data/vendor/assets/javascripts/codemirror/modes/tcl.js +131 -0
  78. data/vendor/assets/javascripts/codemirror/modes/test.js +64 -0
  79. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +345 -345
  80. data/vendor/assets/javascripts/codemirror/modes/tiki.js +297 -298
  81. data/vendor/assets/javascripts/codemirror/modes/turtle.js +145 -0
  82. data/vendor/assets/javascripts/codemirror/modes/vb.js +31 -32
  83. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +4 -4
  84. data/vendor/assets/javascripts/codemirror/modes/xml.js +10 -6
  85. data/vendor/assets/javascripts/codemirror/modes/xquery.js +55 -55
  86. data/vendor/assets/javascripts/codemirror/modes/yaml.js +90 -90
  87. data/vendor/assets/javascripts/codemirror/modes/z80.js +82 -110
  88. data/vendor/assets/javascripts/codemirror.js +1914 -1115
  89. data/vendor/assets/stylesheets/codemirror/{utils → addons/dialog}/dialog.css +0 -0
  90. data/vendor/assets/stylesheets/codemirror/addons/hint/show-hint.css +38 -0
  91. data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +96 -0
  92. data/vendor/assets/stylesheets/codemirror/modes/tiki.css +2 -2
  93. data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +0 -1
  94. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +0 -1
  95. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +2 -2
  96. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +5 -5
  97. data/vendor/assets/stylesheets/codemirror/themes/midnight.css +52 -0
  98. data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +43 -0
  99. data/vendor/assets/stylesheets/codemirror.css +16 -10
  100. metadata +60 -52
  101. data/vendor/assets/javascripts/codemirror/modes/mysql.js +0 -203
  102. data/vendor/assets/javascripts/codemirror/modes/plsql.js +0 -216
  103. data/vendor/assets/javascripts/codemirror/utils/collapserange.js +0 -68
  104. data/vendor/assets/javascripts/codemirror/utils/continuelist.js +0 -28
  105. data/vendor/assets/javascripts/codemirror/utils/foldcode.js +0 -183
  106. data/vendor/assets/javascripts/codemirror/utils/formatting.js +0 -114
  107. data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +0 -46
  108. data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +0 -102
  109. data/vendor/assets/stylesheets/codemirror/utils/simple-hint.css +0 -16
@@ -1,12 +1,12 @@
1
1
  CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
2
-
2
+
3
3
  //config settings
4
4
  var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
5
5
  scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
6
-
6
+
7
7
  //inner modes
8
8
  var scriptingMode, htmlMixedMode;
9
-
9
+
10
10
  //tokenizer when in html mode
11
11
  function htmlDispatch(stream, state) {
12
12
  if (stream.match(scriptStartRegex, false)) {
@@ -32,7 +32,7 @@ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
32
32
  startState: function() {
33
33
  scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
34
34
  htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
35
- return {
35
+ return {
36
36
  token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
37
37
  htmlState : CodeMirror.startState(htmlMixedMode),
38
38
  scriptState : CodeMirror.startState(scriptingMode)
@@ -49,7 +49,7 @@ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
49
49
  else if (scriptingMode.indent)
50
50
  return scriptingMode.indent(state.scriptState, textAfter);
51
51
  },
52
-
52
+
53
53
  copyState: function(state) {
54
54
  return {
55
55
  token : state.token,
@@ -57,7 +57,7 @@ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
57
57
  scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
58
58
  };
59
59
  },
60
-
60
+
61
61
  electricChars: "/{}:",
62
62
 
63
63
  innerMode: function(state) {
@@ -1,19 +1,40 @@
1
- CodeMirror.defineMode("htmlmixed", function(config) {
1
+ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
2
2
  var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
3
- var jsMode = CodeMirror.getMode(config, "javascript");
4
3
  var cssMode = CodeMirror.getMode(config, "css");
5
4
 
5
+ var scriptTypes = [], scriptTypesConf = parserConfig && parserConfig.scriptTypes;
6
+ scriptTypes.push({matches: /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i,
7
+ mode: CodeMirror.getMode(config, "javascript")});
8
+ if (scriptTypesConf) for (var i = 0; i < scriptTypesConf.length; ++i) {
9
+ var conf = scriptTypesConf[i];
10
+ scriptTypes.push({matches: conf.matches, mode: conf.mode && CodeMirror.getMode(config, conf.mode)});
11
+ }
12
+ scriptTypes.push({matches: /./,
13
+ mode: CodeMirror.getMode(config, "text/plain")});
14
+
6
15
  function html(stream, state) {
16
+ var tagName = state.htmlState.tagName;
7
17
  var style = htmlMode.token(stream, state.htmlState);
8
- if (/(?:^|\s)tag(?:\s|$)/.test(style) && stream.current() == ">" && state.htmlState.context) {
9
- if (/^script$/i.test(state.htmlState.context.tagName)) {
10
- state.token = javascript;
11
- state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
12
- }
13
- else if (/^style$/i.test(state.htmlState.context.tagName)) {
14
- state.token = css;
15
- state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
18
+ if (tagName == "script" && /\btag\b/.test(style) && stream.current() == ">") {
19
+ // Script block: mode to change to depends on type attribute
20
+ var scriptType = stream.string.slice(Math.max(0, stream.pos - 100), stream.pos).match(/\btype\s*=\s*("[^"]+"|'[^']+'|\S+)[^<]*$/i);
21
+ scriptType = scriptType ? scriptType[1] : "";
22
+ if (scriptType && /[\"\']/.test(scriptType.charAt(0))) scriptType = scriptType.slice(1, scriptType.length - 1);
23
+ for (var i = 0; i < scriptTypes.length; ++i) {
24
+ var tp = scriptTypes[i];
25
+ if (typeof tp.matches == "string" ? scriptType == tp.matches : tp.matches.test(scriptType)) {
26
+ if (tp.mode) {
27
+ state.token = script;
28
+ state.localMode = tp.mode;
29
+ state.localState = tp.mode.startState && tp.mode.startState(htmlMode.indent(state.htmlState, ""));
30
+ }
31
+ break;
32
+ }
16
33
  }
34
+ } else if (tagName == "style" && /\btag\b/.test(style) && stream.current() == ">") {
35
+ state.token = css;
36
+ state.localMode = cssMode;
37
+ state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
17
38
  }
18
39
  return style;
19
40
  }
@@ -27,19 +48,19 @@ CodeMirror.defineMode("htmlmixed", function(config) {
27
48
  }
28
49
  return style;
29
50
  }
30
- function javascript(stream, state) {
51
+ function script(stream, state) {
31
52
  if (stream.match(/^<\/\s*script\s*>/i, false)) {
32
53
  state.token = html;
33
- state.localState = null;
54
+ state.localState = state.localMode = null;
34
55
  return html(stream, state);
35
56
  }
36
57
  return maybeBackup(stream, /<\/\s*script\s*>/,
37
- jsMode.token(stream, state.localState));
58
+ state.localMode.token(stream, state.localState));
38
59
  }
39
60
  function css(stream, state) {
40
61
  if (stream.match(/^<\/\s*style\s*>/i, false)) {
41
62
  state.token = html;
42
- state.localState = null;
63
+ state.localState = state.localMode = null;
43
64
  return html(stream, state);
44
65
  }
45
66
  return maybeBackup(stream, /<\/\s*style\s*>/,
@@ -49,13 +70,13 @@ CodeMirror.defineMode("htmlmixed", function(config) {
49
70
  return {
50
71
  startState: function() {
51
72
  var state = htmlMode.startState();
52
- return {token: html, localState: null, mode: "html", htmlState: state};
73
+ return {token: html, localMode: null, localState: null, htmlState: state};
53
74
  },
54
75
 
55
76
  copyState: function(state) {
56
77
  if (state.localState)
57
- var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
58
- return {token: state.token, localState: local, mode: state.mode,
78
+ var local = CodeMirror.copyState(state.localMode, state.localState);
79
+ return {token: state.token, localMode: state.localMode, localState: local,
59
80
  htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
60
81
  },
61
82
 
@@ -64,19 +85,18 @@ CodeMirror.defineMode("htmlmixed", function(config) {
64
85
  },
65
86
 
66
87
  indent: function(state, textAfter) {
67
- if (state.token == html || /^\s*<\//.test(textAfter))
88
+ if (!state.localMode || /^\s*<\//.test(textAfter))
68
89
  return htmlMode.indent(state.htmlState, textAfter);
69
- else if (state.token == javascript)
70
- return jsMode.indent(state.localState, textAfter);
90
+ else if (state.localMode.indent)
91
+ return state.localMode.indent(state.localState, textAfter);
71
92
  else
72
- return cssMode.indent(state.localState, textAfter);
93
+ return CodeMirror.Pass;
73
94
  },
74
95
 
75
96
  electricChars: "/{}:",
76
97
 
77
98
  innerMode: function(state) {
78
- var mode = state.token == html ? htmlMode : state.token == javascript ? jsMode : cssMode;
79
- return {state: state.localState || state.htmlState, mode: mode};
99
+ return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
80
100
  }
81
101
  };
82
102
  }, "xml", "javascript", "css");
@@ -11,15 +11,16 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
11
11
  function kw(type) {return {type: type, style: "keyword"};}
12
12
  var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
13
13
  var operator = kw("operator"), atom = {type: "atom", style: "atom"};
14
-
14
+
15
15
  var jsKeywords = {
16
- "if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
16
+ "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
17
17
  "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
18
18
  "var": kw("var"), "const": kw("var"), "let": kw("var"),
19
19
  "function": kw("function"), "catch": kw("catch"),
20
20
  "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
21
21
  "in": operator, "typeof": operator, "instanceof": operator,
22
- "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
22
+ "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
23
+ "this": kw("this")
23
24
  };
24
25
 
25
26
  // Extend the 'normal' keywords with the TypeScript language extensions
@@ -52,7 +53,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
52
53
  return jsKeywords;
53
54
  }();
54
55
 
55
- var isOperatorChar = /[+\-*&%=<>!?|]/;
56
+ var isOperatorChar = /[+\-*&%=<>!?|~^]/;
56
57
 
57
58
  function chain(stream, state, f) {
58
59
  state.tokenize = f;
@@ -86,7 +87,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
86
87
  else if (ch == "0" && stream.eat(/x/i)) {
87
88
  stream.eatWhile(/[\da-f]/i);
88
89
  return ret("number", "number");
89
- }
90
+ }
90
91
  else if (/\d/.test(ch) || ch == "-" && stream.eat(/\d/)) {
91
92
  stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
92
93
  return ret("number", "number");
@@ -111,8 +112,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
111
112
  }
112
113
  }
113
114
  else if (ch == "#") {
114
- stream.skipToEnd();
115
- return ret("error", "error");
115
+ stream.skipToEnd();
116
+ return ret("error", "error");
116
117
  }
117
118
  else if (isOperatorChar.test(ch)) {
118
119
  stream.eatWhile(isOperatorChar);
@@ -148,7 +149,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
148
149
 
149
150
  // Parser
150
151
 
151
- var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
152
+ var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true};
152
153
 
153
154
  function JSLexical(indented, column, type, align, prev, info) {
154
155
  this.indented = indented;
@@ -169,7 +170,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
169
170
  // Communicate our context to the combinators.
170
171
  // (Less wasteful than consing up a hundred closures on every call.)
171
172
  cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
172
-
173
+
173
174
  if (!state.lexical.hasOwnProperty("align"))
174
175
  state.lexical.align = true;
175
176
 
@@ -242,7 +243,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
242
243
  poplex.lex = true;
243
244
 
244
245
  function expect(wanted) {
245
- return function expecting(type) {
246
+ return function(type) {
246
247
  if (type == wanted) return cont();
247
248
  else if (wanted == ";") return pass();
248
249
  else return cont(arguments.callee);
@@ -255,6 +256,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
255
256
  if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
256
257
  if (type == "{") return cont(pushlex("}"), block, poplex);
257
258
  if (type == ";") return cont();
259
+ if (type == "if") return cont(pushlex("form"), expression, statement, poplex, maybeelse(cx.state.indented));
258
260
  if (type == "function") return cont(functiondef);
259
261
  if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"),
260
262
  poplex, statement, poplex);
@@ -268,46 +270,75 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
268
270
  return pass(pushlex("stat"), expression, expect(";"), poplex);
269
271
  }
270
272
  function expression(type) {
271
- if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
273
+ return expressionInner(type, maybeoperatorComma);
274
+ }
275
+ function expressionNoComma(type) {
276
+ return expressionInner(type, maybeoperatorNoComma);
277
+ }
278
+ function expressionInner(type, maybeop) {
279
+ if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
272
280
  if (type == "function") return cont(functiondef);
273
281
  if (type == "keyword c") return cont(maybeexpression);
274
- if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeoperator);
282
+ if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
275
283
  if (type == "operator") return cont(expression);
276
- if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
277
- if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
284
+ if (type == "[") return cont(pushlex("]"), commasep(expressionNoComma, "]"), poplex, maybeop);
285
+ if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeop);
278
286
  return cont();
279
287
  }
280
288
  function maybeexpression(type) {
281
289
  if (type.match(/[;\}\)\],]/)) return pass();
282
290
  return pass(expression);
283
291
  }
284
-
285
- function maybeoperator(type, value) {
286
- if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
287
- if (type == "operator" && value == "?") return cont(expression, expect(":"), expression);
292
+
293
+ function maybeoperatorComma(type, value) {
294
+ if (type == ",") return cont(expression);
295
+ return maybeoperatorNoComma(type, value, maybeoperatorComma);
296
+ }
297
+ function maybeoperatorNoComma(type, value, me) {
298
+ if (!me) me = maybeoperatorNoComma;
299
+ if (type == "operator") {
300
+ if (/\+\+|--/.test(value)) return cont(me);
301
+ if (value == "?") return cont(expression, expect(":"), expression);
302
+ return cont(expression);
303
+ }
288
304
  if (type == ";") return;
289
- if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
290
- if (type == ".") return cont(property, maybeoperator);
291
- if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
305
+ if (type == "(") return cont(pushlex(")", "call"), commasep(expressionNoComma, ")"), poplex, me);
306
+ if (type == ".") return cont(property, me);
307
+ if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, me);
292
308
  }
293
309
  function maybelabel(type) {
294
310
  if (type == ":") return cont(poplex, statement);
295
- return pass(maybeoperator, expect(";"), poplex);
311
+ return pass(maybeoperatorComma, expect(";"), poplex);
296
312
  }
297
313
  function property(type) {
298
314
  if (type == "variable") {cx.marked = "property"; return cont();}
299
315
  }
300
- function objprop(type) {
301
- if (type == "variable") cx.marked = "property";
302
- if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression);
316
+ function objprop(type, value) {
317
+ if (type == "variable") {
318
+ cx.marked = "property";
319
+ if (value == "get" || value == "set") return cont(getterSetter);
320
+ } else if (type == "number" || type == "string") {
321
+ cx.marked = type + " property";
322
+ }
323
+ if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expressionNoComma);
324
+ }
325
+ function getterSetter(type) {
326
+ if (type == ":") return cont(expression);
327
+ if (type != "variable") return cont(expect(":"), expression);
328
+ cx.marked = "property";
329
+ return cont(functiondef);
303
330
  }
304
331
  function commasep(what, end) {
305
332
  function proceed(type) {
306
- if (type == ",") return cont(what, proceed);
333
+ if (type == ",") {
334
+ var lex = cx.state.lexical;
335
+ if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
336
+ return cont(what, proceed);
337
+ }
307
338
  if (type == end) return cont();
308
339
  return cont(expect(end));
309
340
  }
310
- return function commaSeparated(type) {
341
+ return function(type) {
311
342
  if (type == end) return cont();
312
343
  else return pass(what, proceed);
313
344
  };
@@ -332,23 +363,32 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
332
363
  return pass();
333
364
  }
334
365
  function vardef2(type, value) {
335
- if (value == "=") return cont(expression, vardef2);
366
+ if (value == "=") return cont(expressionNoComma, vardef2);
336
367
  if (type == ",") return cont(vardef1);
337
368
  }
369
+ function maybeelse(indent) {
370
+ return function(type, value) {
371
+ if (type == "keyword b" && value == "else") {
372
+ cx.state.lexical = new JSLexical(indent, 0, "form", null, cx.state.lexical);
373
+ return cont(statement, poplex);
374
+ }
375
+ return pass();
376
+ };
377
+ }
338
378
  function forspec1(type) {
339
379
  if (type == "var") return cont(vardef1, expect(";"), forspec2);
340
380
  if (type == ";") return cont(forspec2);
341
381
  if (type == "variable") return cont(formaybein);
342
- return cont(forspec2);
382
+ return pass(expression, expect(";"), forspec2);
343
383
  }
344
384
  function formaybein(_type, value) {
345
385
  if (value == "in") return cont(expression);
346
- return cont(maybeoperator, forspec2);
386
+ return cont(maybeoperatorComma, forspec2);
347
387
  }
348
388
  function forspec2(type, value) {
349
389
  if (type == ";") return cont(forspec3);
350
390
  if (value == "in") return cont(expression);
351
- return cont(expression, expect(";"), forspec3);
391
+ return pass(expression, expect(";"), forspec3);
352
392
  }
353
393
  function forspec3(type) {
354
394
  if (type != ")") cont(expression);
@@ -383,10 +423,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
383
423
  state.lexical.align = false;
384
424
  state.indented = stream.indentation();
385
425
  }
386
- if (stream.eatSpace()) return null;
426
+ if (state.tokenize != jsTokenComment && stream.eatSpace()) return null;
387
427
  var style = state.tokenize(stream, state);
388
428
  if (type == "comment") return style;
389
- state.lastType = type;
429
+ state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
390
430
  return parseJS(state, style, type, content, stream);
391
431
  },
392
432
 
@@ -396,6 +436,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
396
436
  var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
397
437
  if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
398
438
  var type = lexical.type, closing = firstChar == type;
439
+ if (parserConfig.statementIndent != null) {
440
+ if (type == ")" && lexical.prev && lexical.prev.type == "stat") lexical = lexical.prev;
441
+ if (lexical.type == "stat") return lexical.indented + parserConfig.statementIndent;
442
+ }
443
+
399
444
  if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? 4 : 0);
400
445
  else if (type == "form" && firstChar == "{") return lexical.indented;
401
446
  else if (type == "form") return lexical.indented + indentUnit;
@@ -1,5 +1,5 @@
1
1
  CodeMirror.defineMode("jinja2", function() {
2
- var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false",
2
+ var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false",
3
3
  "loop", "none", "self", "super", "if", "as", "not", "and",
4
4
  "else", "import", "with", "without", "context"];
5
5
  keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b");
@@ -38,5 +38,5 @@ CodeMirror.defineMode("jinja2", function() {
38
38
  token: function (stream, state) {
39
39
  return state.tokenize(stream, state);
40
40
  }
41
- };
41
+ };
42
42
  });
@@ -9,16 +9,16 @@ CodeMirror.defineMode("less", function(config) {
9
9
  function ret(style, tp) {type = tp; return style;}
10
10
  //html tags
11
11
  var tags = "a abbr acronym address applet area article aside audio b base basefont bdi bdo big blockquote body br button canvas caption cite code col colgroup command datalist dd del details dfn dir div dl dt em embed fieldset figcaption figure font footer form frame frameset h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins keygen kbd label legend li link map mark menu meta meter nav noframes noscript object ol optgroup option output p param pre progress q rp rt ruby s samp script section select small source span strike strong style sub summary sup table tbody td textarea tfoot th thead time title tr track tt u ul var video wbr".split(' ');
12
-
12
+
13
13
  function inTagsArray(val){
14
14
  for(var i=0; i<tags.length; i++)if(val === tags[i])return true;
15
15
  }
16
-
16
+
17
17
  var selectors = /(^\:root$|^\:nth\-child$|^\:nth\-last\-child$|^\:nth\-of\-type$|^\:nth\-last\-of\-type$|^\:first\-child$|^\:last\-child$|^\:first\-of\-type$|^\:last\-of\-type$|^\:only\-child$|^\:only\-of\-type$|^\:empty$|^\:link|^\:visited$|^\:active$|^\:hover$|^\:focus$|^\:target$|^\:lang$|^\:enabled^\:disabled$|^\:checked$|^\:first\-line$|^\:first\-letter$|^\:before$|^\:after$|^\:not$|^\:required$|^\:invalid$)/;
18
-
18
+
19
19
  function tokenBase(stream, state) {
20
20
  var ch = stream.next();
21
-
21
+
22
22
  if (ch == "@") {stream.eatWhile(/[\w\-]/); return ret("meta", stream.current());}
23
23
  else if (ch == "/" && stream.eat("*")) {
24
24
  state.tokenize = tokenCComment;
@@ -41,7 +41,7 @@ CodeMirror.defineMode("less", function(config) {
41
41
  }else{
42
42
  if(type == "string" || type == "(")return ret("string", "string");
43
43
  if(state.stack[state.stack.length-1] != undefined)return ret(null, ch);
44
- stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/);
44
+ stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/);
45
45
  if( /\/|\)|#/.test(stream.peek() || (stream.eatSpace() && stream.peek() == ")")) || stream.eol() )return ret("string", "string"); // let url(/images/logo.png) without quotes return as string
46
46
  }
47
47
  }
@@ -58,7 +58,7 @@ CodeMirror.defineMode("less", function(config) {
58
58
  return ret(null, "select-op");
59
59
  }
60
60
  else if (/[;{}:\[\]()~\|]/.test(ch)) {
61
- if(ch == ":"){
61
+ if(ch == ":"){
62
62
  stream.eatWhile(/[a-z\\\-]/);
63
63
  if( selectors.test(stream.current()) ){
64
64
  return ret("tag", "tag");
@@ -69,7 +69,7 @@ CodeMirror.defineMode("less", function(config) {
69
69
  if( selectors.test(stream.current().substring(1)) )return ret("tag", "tag");
70
70
  return ret(null, ch);
71
71
  }else{
72
- return ret(null, ch);
72
+ return ret(null, ch);
73
73
  }
74
74
  }else if(ch == "~"){
75
75
  if(type == "r")return ret("string", "string");
@@ -77,7 +77,7 @@ CodeMirror.defineMode("less", function(config) {
77
77
  return ret(null, ch);
78
78
  }
79
79
  }
80
- else if (ch == ".") {
80
+ else if (ch == ".") {
81
81
  if(type == "(" || type == "string")return ret("string", "string"); // allow url(../image.png)
82
82
  stream.eatWhile(/[\a-zA-Z0-9\-_]/);
83
83
  if(stream.peek() == " ")stream.eatSpace();
@@ -106,7 +106,7 @@ CodeMirror.defineMode("less", function(config) {
106
106
  else return ret("number", "unit");
107
107
  }else{//when not a valid hexvalue in the current stream e.g. #footer
108
108
  stream.eatWhile(/[\w\\\-]/);
109
- return ret("atom", "tag");
109
+ return ret("atom", "tag");
110
110
  }
111
111
  }else{//when not a valid hexvalue length
112
112
  stream.eatWhile(/[\w\\\-]/);
@@ -126,14 +126,14 @@ CodeMirror.defineMode("less", function(config) {
126
126
  return ret("string", "string");
127
127
  }else if(stream.peek() == "<" || stream.peek() == ">"){
128
128
  return ret("tag", "tag");
129
- }else if( /\(/.test(stream.peek()) ){
129
+ }else if( /\(/.test(stream.peek()) ){
130
130
  return ret(null, ch);
131
131
  }else if (stream.peek() == "/" && state.stack[state.stack.length-1] != undefined){ // url(dir/center/image.png)
132
132
  return ret("string", "string");
133
133
  }else if( stream.current().match(/\-\d|\-.\d/) ){ // match e.g.: -5px -0.4 etc... only colorize the minus sign
134
134
  //commment out these 2 comment if you want the minus sign to be parsed as null -500px
135
135
  //stream.backUp(stream.current().length-1);
136
- //return ret(null, ch); //console.log( stream.current() );
136
+ //return ret(null, ch); //console.log( stream.current() );
137
137
  return ret("number", "unit");
138
138
  }else if( inTagsArray(stream.current().toLowerCase()) ){ // match html tags
139
139
  return ret("tag", "tag");
@@ -156,30 +156,30 @@ CodeMirror.defineMode("less", function(config) {
156
156
  stream.next();
157
157
  var t_v = stream.peek() == ":" ? true : false;
158
158
  if(!t_v){
159
- var old_pos = stream.pos;
160
- var sc = stream.current().length;
161
- stream.eatWhile(/[a-z\\\-]/);
162
- var new_pos = stream.pos;
163
- if(stream.current().substring(sc-1).match(selectors) != null){
164
- stream.backUp(new_pos-(old_pos-1));
165
- return ret("tag", "tag");
166
- } else stream.backUp(new_pos-(old_pos-1));
167
- }else{
168
- stream.backUp(1);
169
- }
170
- if(t_v)return ret("tag", "tag"); else return ret("variable", "variable");
171
- }else{
172
- return ret("variable", "variable");
159
+ var old_pos = stream.pos;
160
+ var sc = stream.current().length;
161
+ stream.eatWhile(/[a-z\\\-]/);
162
+ var new_pos = stream.pos;
163
+ if(stream.current().substring(sc-1).match(selectors) != null){
164
+ stream.backUp(new_pos-(old_pos-1));
165
+ return ret("tag", "tag");
166
+ } else stream.backUp(new_pos-(old_pos-1));
167
+ }else{
168
+ stream.backUp(1);
169
+ }
170
+ if(t_v)return ret("tag", "tag"); else return ret("variable", "variable");
171
+ }else{
172
+ return ret("variable", "variable");
173
173
  }
174
- }
174
+ }
175
175
  }
176
-
176
+
177
177
  function tokenSComment(stream, state) { // SComment = Slash comment
178
178
  stream.skipToEnd();
179
179
  state.tokenize = tokenBase;
180
180
  return ret("comment", "comment");
181
181
  }
182
-
182
+
183
183
  function tokenCComment(stream, state) {
184
184
  var maybeEnd = false, ch;
185
185
  while ((ch = stream.next()) != null) {
@@ -191,7 +191,7 @@ CodeMirror.defineMode("less", function(config) {
191
191
  }
192
192
  return ret("comment", "comment");
193
193
  }
194
-
194
+
195
195
  function tokenSGMLComment(stream, state) {
196
196
  var dashes = 0, ch;
197
197
  while ((ch = stream.next()) != null) {
@@ -203,7 +203,7 @@ CodeMirror.defineMode("less", function(config) {
203
203
  }
204
204
  return ret("comment", "comment");
205
205
  }
206
-
206
+
207
207
  function tokenString(quote) {
208
208
  return function(stream, state) {
209
209
  var escaped = false, ch;
@@ -216,18 +216,18 @@ CodeMirror.defineMode("less", function(config) {
216
216
  return ret("string", "string");
217
217
  };
218
218
  }
219
-
219
+
220
220
  return {
221
- startState: function(base) {
221
+ startState: function(base) {
222
222
  return {tokenize: tokenBase,
223
223
  baseIndent: base || 0,
224
224
  stack: []};
225
225
  },
226
-
226
+
227
227
  token: function(stream, state) {
228
228
  if (stream.eatSpace()) return null;
229
229
  var style = state.tokenize(stream, state);
230
-
230
+
231
231
  var context = state.stack[state.stack.length-1];
232
232
  if (type == "hash" && context == "rule") style = "atom";
233
233
  else if (style == "variable") {
@@ -237,7 +237,7 @@ CodeMirror.defineMode("less", function(config) {
237
237
  /[\s,|\s\)|\s]/.test(stream.peek()) ? "tag" : type;
238
238
  }
239
239
  }
240
-
240
+
241
241
  if (context == "rule" && /^[\{\};]$/.test(type))
242
242
  state.stack.pop();
243
243
  if (type == "{") {
@@ -249,18 +249,18 @@ CodeMirror.defineMode("less", function(config) {
249
249
  else if (context == "{" && type != "comment") state.stack.push("rule");
250
250
  return style;
251
251
  },
252
-
252
+
253
253
  indent: function(state, textAfter) {
254
254
  var n = state.stack.length;
255
255
  if (/^\}/.test(textAfter))
256
256
  n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
257
257
  return state.baseIndent + n * indentUnit;
258
258
  },
259
-
259
+
260
260
  electricChars: "}"
261
261
  };
262
262
  });
263
263
 
264
264
  CodeMirror.defineMIME("text/x-less", "less");
265
265
  if (!CodeMirror.mimeModes.hasOwnProperty("text/css"))
266
- CodeMirror.defineMIME("text/css", "less");
266
+ CodeMirror.defineMIME("text/css", "less");