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
@@ -3,95 +3,93 @@
3
3
  * Licence: MIT
4
4
  */
5
5
 
6
- CodeMirror.defineMode("stex", function()
7
- {
6
+ CodeMirror.defineMode("stex", function() {
7
+ "use strict";
8
+
8
9
  function pushCommand(state, command) {
9
- state.cmdState.push(command);
10
+ state.cmdState.push(command);
10
11
  }
11
12
 
12
- function peekCommand(state) {
13
- if (state.cmdState.length>0)
14
- return state.cmdState[state.cmdState.length-1];
15
- else
16
- return null;
13
+ function peekCommand(state) {
14
+ if (state.cmdState.length > 0) {
15
+ return state.cmdState[state.cmdState.length - 1];
16
+ } else {
17
+ return null;
18
+ }
17
19
  }
18
20
 
19
21
  function popCommand(state) {
20
- if (state.cmdState.length>0) {
21
- var plug = state.cmdState.pop();
22
- plug.closeBracket();
23
- }
22
+ var plug = state.cmdState.pop();
23
+ if (plug) {
24
+ plug.closeBracket();
25
+ }
24
26
  }
25
27
 
26
- function applyMostPowerful(state) {
27
- var context = state.cmdState;
28
- for (var i = context.length - 1; i >= 0; i--) {
29
- var plug = context[i];
30
- if (plug.name=="DEFAULT")
31
- continue;
32
- return plug.styleIdentifier();
33
- }
34
- return null;
28
+ // returns the non-default plugin closest to the end of the list
29
+ function getMostPowerful(state) {
30
+ var context = state.cmdState;
31
+ for (var i = context.length - 1; i >= 0; i--) {
32
+ var plug = context[i];
33
+ if (plug.name == "DEFAULT") {
34
+ continue;
35
+ }
36
+ return plug;
37
+ }
38
+ return { styleIdentifier: function() { return null; } };
35
39
  }
36
40
 
37
- function addPluginPattern(pluginName, cmdStyle, brackets, styles) {
38
- return function () {
39
- this.name=pluginName;
40
- this.bracketNo = 0;
41
- this.style=cmdStyle;
42
- this.styles = styles;
43
- this.brackets = brackets;
44
-
45
- this.styleIdentifier = function() {
46
- if (this.bracketNo<=this.styles.length)
47
- return this.styles[this.bracketNo-1];
48
- else
49
- return null;
50
- };
51
- this.openBracket = function() {
52
- this.bracketNo++;
53
- return "bracket";
54
- };
55
- this.closeBracket = function() {};
56
- };
41
+ function addPluginPattern(pluginName, cmdStyle, styles) {
42
+ return function () {
43
+ this.name = pluginName;
44
+ this.bracketNo = 0;
45
+ this.style = cmdStyle;
46
+ this.styles = styles;
47
+ this.argument = null; // \begin and \end have arguments that follow. These are stored in the plugin
48
+
49
+ this.styleIdentifier = function() {
50
+ return this.styles[this.bracketNo - 1] || null;
51
+ };
52
+ this.openBracket = function() {
53
+ this.bracketNo++;
54
+ return "bracket";
55
+ };
56
+ this.closeBracket = function() {};
57
+ };
57
58
  }
58
59
 
59
- var plugins = new Array();
60
-
61
- plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]);
62
- plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]);
63
- plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
64
- plugins["begin"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
65
- plugins["end"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
60
+ var plugins = {};
61
+
62
+ plugins["importmodule"] = addPluginPattern("importmodule", "tag", ["string", "builtin"]);
63
+ plugins["documentclass"] = addPluginPattern("documentclass", "tag", ["", "atom"]);
64
+ plugins["usepackage"] = addPluginPattern("usepackage", "tag", ["atom"]);
65
+ plugins["begin"] = addPluginPattern("begin", "tag", ["atom"]);
66
+ plugins["end"] = addPluginPattern("end", "tag", ["atom"]);
66
67
 
67
68
  plugins["DEFAULT"] = function () {
68
- this.name="DEFAULT";
69
- this.style="tag";
69
+ this.name = "DEFAULT";
70
+ this.style = "tag";
70
71
 
71
- this.styleIdentifier = this.openBracket = this.closeBracket = function() {};
72
+ this.styleIdentifier = this.openBracket = this.closeBracket = function() {};
72
73
  };
73
74
 
74
75
  function setState(state, f) {
75
- state.f = f;
76
+ state.f = f;
76
77
  }
77
78
 
79
+ // called when in a normal (no environment) context
78
80
  function normal(source, state) {
79
- if (source.match(/^\\[a-zA-Z@]+/)) {
80
- var cmdName = source.current();
81
- cmdName = cmdName.substr(1, cmdName.length-1);
82
- var plug;
83
- if (plugins.hasOwnProperty(cmdName)) {
84
- plug = plugins[cmdName];
85
- } else {
86
- plug = plugins["DEFAULT"];
87
- }
88
- plug = new plug();
89
- pushCommand(state, plug);
90
- setState(state, beginParams);
91
- return plug.style;
92
- }
81
+ var plug;
82
+ // Do we look like '\command' ? If so, attempt to apply the plugin 'command'
83
+ if (source.match(/^\\[a-zA-Z@]+/)) {
84
+ var cmdName = source.current().slice(1);
85
+ plug = plugins[cmdName] || plugins["DEFAULT"];
86
+ plug = new plug();
87
+ pushCommand(state, plug);
88
+ setState(state, beginParams);
89
+ return plug.style;
90
+ }
93
91
 
94
- // escape characters
92
+ // escape characters
95
93
  if (source.match(/^\\[$&%#{}_]/)) {
96
94
  return "tag";
97
95
  }
@@ -101,74 +99,147 @@ CodeMirror.defineMode("stex", function()
101
99
  return "tag";
102
100
  }
103
101
 
104
- var ch = source.next();
105
- if (ch == "%") {
102
+ // find if we're starting various math modes
103
+ if (source.match("\\[")) {
104
+ setState(state, function(source, state){ return inMathMode(source, state, "\\]"); });
105
+ return "keyword";
106
+ }
107
+ if (source.match("$$")) {
108
+ setState(state, function(source, state){ return inMathMode(source, state, "$$"); });
109
+ return "keyword";
110
+ }
111
+ if (source.match("$")) {
112
+ setState(state, function(source, state){ return inMathMode(source, state, "$"); });
113
+ return "keyword";
114
+ }
115
+
116
+ var ch = source.next();
117
+ if (ch == "%") {
106
118
  // special case: % at end of its own line; stay in same state
107
119
  if (!source.eol()) {
108
120
  setState(state, inCComment);
109
121
  }
110
- return "comment";
111
- }
112
- else if (ch=='}' || ch==']') {
113
- plug = peekCommand(state);
114
- if (plug) {
115
- plug.closeBracket(ch);
116
- setState(state, beginParams);
117
- } else
118
- return "error";
119
- return "bracket";
120
- } else if (ch=='{' || ch=='[') {
121
- plug = plugins["DEFAULT"];
122
- plug = new plug();
123
- pushCommand(state, plug);
124
- return "bracket";
125
- }
126
- else if (/\d/.test(ch)) {
127
- source.eatWhile(/[\w.%]/);
128
- return "atom";
129
- }
130
- else {
131
- source.eatWhile(/[\w-_]/);
132
- return applyMostPowerful(state);
133
- }
122
+ return "comment";
123
+ }
124
+ else if (ch == '}' || ch == ']') {
125
+ plug = peekCommand(state);
126
+ if (plug) {
127
+ plug.closeBracket(ch);
128
+ setState(state, beginParams);
129
+ } else {
130
+ return "error";
131
+ }
132
+ return "bracket";
133
+ } else if (ch == '{' || ch == '[') {
134
+ plug = plugins["DEFAULT"];
135
+ plug = new plug();
136
+ pushCommand(state, plug);
137
+ return "bracket";
138
+ }
139
+ else if (/\d/.test(ch)) {
140
+ source.eatWhile(/[\w.%]/);
141
+ return "atom";
142
+ }
143
+ else {
144
+ source.eatWhile(/[\w\-_]/);
145
+ plug = getMostPowerful(state);
146
+ if (plug.name == 'begin') {
147
+ plug.argument = source.current();
148
+ }
149
+ return plug.styleIdentifier();
150
+ }
134
151
  }
135
152
 
136
153
  function inCComment(source, state) {
137
- source.skipToEnd();
138
- setState(state, normal);
139
- return "comment";
154
+ source.skipToEnd();
155
+ setState(state, normal);
156
+ return "comment";
157
+ }
158
+
159
+ function inMathMode(source, state, endModeSeq) {
160
+ if (source.eatSpace()) {
161
+ return null;
162
+ }
163
+ if (source.match(endModeSeq)) {
164
+ setState(state, normal);
165
+ return "keyword";
166
+ }
167
+ if (source.match(/^\\[a-zA-Z@]+/)) {
168
+ return "tag";
169
+ }
170
+ if (source.match(/^[a-zA-Z]+/)) {
171
+ return "variable-2";
172
+ }
173
+ // escape characters
174
+ if (source.match(/^\\[$&%#{}_]/)) {
175
+ return "tag";
176
+ }
177
+ // white space control characters
178
+ if (source.match(/^\\[,;!\/]/)) {
179
+ return "tag";
180
+ }
181
+ // special math-mode characters
182
+ if (source.match(/^[\^_&]/)) {
183
+ return "tag";
184
+ }
185
+ // non-special characters
186
+ if (source.match(/^[+\-<>|=,\/@!*:;'"`~#?]/)) {
187
+ return null;
188
+ }
189
+ if (source.match(/^(\d+\.\d*|\d*\.\d+|\d+)/)) {
190
+ return "number";
191
+ }
192
+ var ch = source.next();
193
+ if (ch == "{" || ch == "}" || ch == "[" || ch == "]" || ch == "(" || ch == ")") {
194
+ return "bracket";
195
+ }
196
+
197
+ // eat comments here, because inCComment returns us to normal state!
198
+ if (ch == "%") {
199
+ if (!source.eol()) {
200
+ source.skipToEnd();
201
+ }
202
+ return "comment";
203
+ }
204
+ return "error";
140
205
  }
141
206
 
142
207
  function beginParams(source, state) {
143
- var ch = source.peek();
144
- if (ch == '{' || ch == '[') {
145
- var lastPlug = peekCommand(state);
146
- lastPlug.openBracket(ch);
147
- source.eat(ch);
148
- setState(state, normal);
149
- return "bracket";
150
- }
151
- if (/[ \t\r]/.test(ch)) {
152
- source.eat(ch);
153
- return null;
154
- }
155
- setState(state, normal);
156
- lastPlug = peekCommand(state);
157
- if (lastPlug) {
158
- popCommand(state);
159
- }
208
+ var ch = source.peek(), lastPlug;
209
+ if (ch == '{' || ch == '[') {
210
+ lastPlug = peekCommand(state);
211
+ lastPlug.openBracket(ch);
212
+ source.eat(ch);
213
+ setState(state, normal);
214
+ return "bracket";
215
+ }
216
+ if (/[ \t\r]/.test(ch)) {
217
+ source.eat(ch);
218
+ return null;
219
+ }
220
+ setState(state, normal);
221
+ popCommand(state);
222
+
160
223
  return normal(source, state);
161
224
  }
162
225
 
163
226
  return {
164
- startState: function() { return { f:normal, cmdState:[] }; },
165
- copyState: function(s) { return { f: s.f, cmdState: s.cmdState.slice(0, s.cmdState.length) }; },
166
-
167
- token: function(stream, state) {
168
- var t = state.f(stream, state);
169
- return t;
170
- }
171
- };
227
+ startState: function() {
228
+ return {
229
+ cmdState: [],
230
+ f: normal
231
+ };
232
+ },
233
+ copyState: function(s) {
234
+ return {
235
+ cmdState: s.cmdState.slice(),
236
+ f: s.f
237
+ };
238
+ },
239
+ token: function(stream, state) {
240
+ return state.f(stream, state);
241
+ }
242
+ };
172
243
  });
173
244
 
174
245
  CodeMirror.defineMIME("text/x-stex", "stex");
@@ -0,0 +1,131 @@
1
+ //tcl mode by Ford_Lawnmower :: Based on Velocity mode by Steve O'Hara
2
+ CodeMirror.defineMode("tcl", function() {
3
+ function parseWords(str) {
4
+ var obj = {}, words = str.split(" ");
5
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
6
+ return obj;
7
+ }
8
+ var keywords = parseWords("Tcl safe after append array auto_execok auto_import auto_load " +
9
+ "auto_mkindex auto_mkindex_old auto_qualify auto_reset bgerror " +
10
+ "binary break catch cd close concat continue dde eof encoding error " +
11
+ "eval exec exit expr fblocked fconfigure fcopy file fileevent filename " +
12
+ "filename flush for foreach format gets glob global history http if " +
13
+ "incr info interp join lappend lindex linsert list llength load lrange " +
14
+ "lreplace lsearch lset lsort memory msgcat namespace open package parray " +
15
+ "pid pkg::create pkg_mkIndex proc puts pwd re_syntax read regex regexp " +
16
+ "registry regsub rename resource return scan seek set socket source split " +
17
+ "string subst switch tcl_endOfWord tcl_findLibrary tcl_startOfNextWord " +
18
+ "tcl_wordBreakAfter tcl_startOfPreviousWord tcl_wordBreakBefore tcltest " +
19
+ "tclvars tell time trace unknown unset update uplevel upvar variable " +
20
+ "vwait");
21
+ var functions = parseWords("if elseif else and not or eq ne in ni for foreach while switch");
22
+ var isOperatorChar = /[+\-*&%=<>!?^\/\|]/;
23
+ function chain(stream, state, f) {
24
+ state.tokenize = f;
25
+ return f(stream, state);
26
+ }
27
+ function tokenBase(stream, state) {
28
+ var beforeParams = state.beforeParams;
29
+ state.beforeParams = false;
30
+ var ch = stream.next();
31
+ if ((ch == '"' || ch == "'") && state.inParams)
32
+ return chain(stream, state, tokenString(ch));
33
+ else if (/[\[\]{}\(\),;\.]/.test(ch)) {
34
+ if (ch == "(" && beforeParams) state.inParams = true;
35
+ else if (ch == ")") state.inParams = false;
36
+ return null;
37
+ }
38
+ else if (/\d/.test(ch)) {
39
+ stream.eatWhile(/[\w\.]/);
40
+ return "number";
41
+ }
42
+ else if (ch == "#" && stream.eat("*")) {
43
+ return chain(stream, state, tokenComment);
44
+ }
45
+ else if (ch == "#" && stream.match(/ *\[ *\[/)) {
46
+ return chain(stream, state, tokenUnparsed);
47
+ }
48
+ else if (ch == "#" && stream.eat("#")) {
49
+ stream.skipToEnd();
50
+ return "comment";
51
+ }
52
+ else if (ch == '"') {
53
+ stream.skipTo(/"/);
54
+ return "comment";
55
+ }
56
+ else if (ch == "$") {
57
+ stream.eatWhile(/[$_a-z0-9A-Z\.{:]/);
58
+ stream.eatWhile(/}/);
59
+ state.beforeParams = true;
60
+ return "builtin";
61
+ }
62
+ else if (isOperatorChar.test(ch)) {
63
+ stream.eatWhile(isOperatorChar);
64
+ return "comment";
65
+ }
66
+ else {
67
+ stream.eatWhile(/[\w\$_{}]/);
68
+ var word = stream.current().toLowerCase();
69
+ if (keywords && keywords.propertyIsEnumerable(word))
70
+ return "keyword";
71
+ if (functions && functions.propertyIsEnumerable(word)) {
72
+ state.beforeParams = true;
73
+ return "keyword";
74
+ }
75
+ return null;
76
+ }
77
+ }
78
+ function tokenString(quote) {
79
+ return function(stream, state) {
80
+ var escaped = false, next, end = false;
81
+ while ((next = stream.next()) != null) {
82
+ if (next == quote && !escaped) {
83
+ end = true;
84
+ break;
85
+ }
86
+ escaped = !escaped && next == "\\";
87
+ }
88
+ if (end) state.tokenize = tokenBase;
89
+ return "string";
90
+ };
91
+ }
92
+ function tokenComment(stream, state) {
93
+ var maybeEnd = false, ch;
94
+ while (ch = stream.next()) {
95
+ if (ch == "#" && maybeEnd) {
96
+ state.tokenize = tokenBase;
97
+ break;
98
+ }
99
+ maybeEnd = (ch == "*");
100
+ }
101
+ return "comment";
102
+ }
103
+ function tokenUnparsed(stream, state) {
104
+ var maybeEnd = 0, ch;
105
+ while (ch = stream.next()) {
106
+ if (ch == "#" && maybeEnd == 2) {
107
+ state.tokenize = tokenBase;
108
+ break;
109
+ }
110
+ if (ch == "]")
111
+ maybeEnd++;
112
+ else if (ch != " ")
113
+ maybeEnd = 0;
114
+ }
115
+ return "meta";
116
+ }
117
+ return {
118
+ startState: function() {
119
+ return {
120
+ tokenize: tokenBase,
121
+ beforeParams: false,
122
+ inParams: false
123
+ };
124
+ },
125
+ token: function(stream, state) {
126
+ if (stream.eatSpace()) return null;
127
+ return state.tokenize(stream, state);
128
+ }
129
+ };
130
+ });
131
+ CodeMirror.defineMIME("text/x-tcl", "tcl");
@@ -0,0 +1,64 @@
1
+ // Don't take these too seriously -- the expected results appear to be
2
+ // based on the results of actual runs without any serious manual
3
+ // verification. If a change you made causes them to fail, the test is
4
+ // as likely to wrong as the code.
5
+
6
+ (function() {
7
+ var mode = CodeMirror.getMode({tabSize: 4}, "xquery");
8
+ function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
9
+
10
+ MT("eviltest",
11
+ "[keyword xquery] [keyword version] [variable &quot;1][keyword .][atom 0][keyword -][variable ml&quot;][def&variable ;] [comment (: this is : a \"comment\" :)]",
12
+ " [keyword let] [variable $let] [keyword :=] [variable &lt;x] [variable attr][keyword =][variable &quot;value&quot;&gt;&quot;test&quot;&lt;func&gt][def&variable ;function]() [variable $var] {[keyword function]()} {[variable $var]}[variable &lt;][keyword /][variable func&gt;&lt;][keyword /][variable x&gt;]",
13
+ " [keyword let] [variable $joe][keyword :=][atom 1]",
14
+ " [keyword return] [keyword element] [variable element] {",
15
+ " [keyword attribute] [variable attribute] { [atom 1] },",
16
+ " [keyword element] [variable test] { [variable &#39;a&#39;] }, [keyword attribute] [variable foo] { [variable &quot;bar&quot;] },",
17
+ " [def&variable fn:doc]()[[ [variable foo][keyword /][variable @bar] [keyword eq] [variable $let] ]],",
18
+ " [keyword //][variable x] } [comment (: a more 'evil' test :)]",
19
+ " [comment (: Modified Blakeley example (: with nested comment :) ... :)]",
20
+ " [keyword declare] [keyword private] [keyword function] [def&variable local:declare]() {()}[variable ;]",
21
+ " [keyword declare] [keyword private] [keyword function] [def&variable local:private]() {()}[variable ;]",
22
+ " [keyword declare] [keyword private] [keyword function] [def&variable local:function]() {()}[variable ;]",
23
+ " [keyword declare] [keyword private] [keyword function] [def&variable local:local]() {()}[variable ;]",
24
+ " [keyword let] [variable $let] [keyword :=] [variable &lt;let&gt;let] [variable $let] [keyword :=] [variable &quot;let&quot;&lt;][keyword /let][variable &gt;]",
25
+ " [keyword return] [keyword element] [variable element] {",
26
+ " [keyword attribute] [variable attribute] { [keyword try] { [def&variable xdmp:version]() } [keyword catch]([variable $e]) { [def&variable xdmp:log]([variable $e]) } },",
27
+ " [keyword attribute] [variable fn:doc] { [variable &quot;bar&quot;] [variable castable] [keyword as] [atom xs:string] },",
28
+ " [keyword element] [variable text] { [keyword text] { [variable &quot;text&quot;] } },",
29
+ " [def&variable fn:doc]()[[ [qualifier child::][variable eq][keyword /]([variable @bar] [keyword |] [qualifier attribute::][variable attribute]) [keyword eq] [variable $let] ]],",
30
+ " [keyword //][variable fn:doc]",
31
+ " }");
32
+
33
+ MT("testEmptySequenceKeyword",
34
+ "[string \"foo\"] [keyword instance] [keyword of] [keyword empty-sequence]()");
35
+
36
+ MT("testMultiAttr",
37
+ "[tag <p ][attribute a1]=[string \"foo\"] [attribute a2]=[string \"bar\"][tag >][variable hello] [variable world][tag </p>]");
38
+
39
+ MT("test namespaced variable",
40
+ "[keyword declare] [keyword namespace] [variable e] [keyword =] [string \"http://example.com/ANamespace\"][variable ;declare] [keyword variable] [variable $e:exampleComThisVarIsNotRecognized] [keyword as] [keyword element]([keyword *]) [variable external;]");
41
+
42
+ MT("test EQName variable",
43
+ "[keyword declare] [keyword variable] [variable $\"http://www.example.com/ns/my\":var] [keyword :=] [atom 12][variable ;]",
44
+ "[tag <out>]{[variable $\"http://www.example.com/ns/my\":var]}[tag </out>]");
45
+
46
+ MT("test EQName function",
47
+ "[keyword declare] [keyword function] [def&variable \"http://www.example.com/ns/my\":fn] ([variable $a] [keyword as] [atom xs:integer]) [keyword as] [atom xs:integer] {",
48
+ " [variable $a] [keyword +] [atom 2]",
49
+ "}[variable ;]",
50
+ "[tag <out>]{[def&variable \"http://www.example.com/ns/my\":fn]([atom 12])}[tag </out>]");
51
+
52
+ MT("test EQName function with single quotes",
53
+ "[keyword declare] [keyword function] [def&variable 'http://www.example.com/ns/my':fn] ([variable $a] [keyword as] [atom xs:integer]) [keyword as] [atom xs:integer] {",
54
+ " [variable $a] [keyword +] [atom 2]",
55
+ "}[variable ;]",
56
+ "[tag <out>]{[def&variable 'http://www.example.com/ns/my':fn]([atom 12])}[tag </out>]");
57
+
58
+ MT("testProcessingInstructions",
59
+ "[def&variable data]([comment&meta <?target content?>]) [keyword instance] [keyword of] [atom xs:string]");
60
+
61
+ MT("testQuoteEscapeDouble",
62
+ "[keyword let] [variable $rootfolder] [keyword :=] [string \"c:\\builds\\winnt\\HEAD\\qa\\scripts\\\"]",
63
+ "[keyword let] [variable $keysfolder] [keyword :=] [def&variable concat]([variable $rootfolder], [string \"keys\\\"])");
64
+ })();