codemirror-rails 2.3 → 2.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README.md +0 -16
  2. data/codemirror-rails.gemspec +1 -1
  3. data/lib/codemirror/rails/version.rb +2 -2
  4. data/vendor/assets/javascripts/codemirror.js +323 -687
  5. data/vendor/assets/javascripts/codemirror/modes/clike.js +3 -40
  6. data/vendor/assets/javascripts/codemirror/modes/clojure.js +14 -14
  7. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +0 -6
  8. data/vendor/assets/javascripts/codemirror/modes/css.js +1 -1
  9. data/vendor/assets/javascripts/codemirror/modes/diff.js +5 -24
  10. data/vendor/assets/javascripts/codemirror/modes/gfm.js +4 -40
  11. data/vendor/assets/javascripts/codemirror/modes/go.js +22 -20
  12. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +1 -1
  13. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +2 -4
  14. data/vendor/assets/javascripts/codemirror/modes/javascript.js +7 -8
  15. data/vendor/assets/javascripts/codemirror/modes/less.js +54 -100
  16. data/vendor/assets/javascripts/codemirror/modes/markdown.js +49 -52
  17. data/vendor/assets/javascripts/codemirror/modes/pascal.js +46 -2
  18. data/vendor/assets/javascripts/codemirror/modes/perl.js +1 -1
  19. data/vendor/assets/javascripts/codemirror/modes/php.js +25 -54
  20. data/vendor/assets/javascripts/codemirror/modes/python.js +16 -14
  21. data/vendor/assets/javascripts/codemirror/modes/rpm-spec.js +1 -1
  22. data/vendor/assets/javascripts/codemirror/modes/rst.js +1 -1
  23. data/vendor/assets/javascripts/codemirror/modes/ruby.js +9 -4
  24. data/vendor/assets/javascripts/codemirror/modes/scheme.js +46 -74
  25. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +16 -16
  26. data/vendor/assets/javascripts/codemirror/modes/stex.js +6 -21
  27. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +45 -55
  28. data/vendor/assets/javascripts/codemirror/modes/xml.js +14 -79
  29. data/vendor/assets/javascripts/codemirror/{utils/overlay.js → overlay.js} +2 -3
  30. data/vendor/assets/javascripts/codemirror/runmode.js +27 -0
  31. data/vendor/assets/stylesheets/codemirror.css +2 -63
  32. data/vendor/assets/stylesheets/codemirror/modes/tiddlywiki.css +21 -14
  33. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +1 -1
  34. data/vendor/assets/stylesheets/codemirror/themes/elegant.css +2 -2
  35. data/vendor/assets/stylesheets/codemirror/themes/neat.css +3 -3
  36. data/vendor/assets/stylesheets/codemirror/themes/night.css +1 -1
  37. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +2 -2
  38. metadata +6 -39
  39. data/vendor/assets/javascripts/codemirror/keymaps/emacs.js +0 -29
  40. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +0 -766
  41. data/vendor/assets/javascripts/codemirror/modes/ecl.js +0 -203
  42. data/vendor/assets/javascripts/codemirror/modes/erlang.js +0 -251
  43. data/vendor/assets/javascripts/codemirror/modes/pig.js +0 -172
  44. data/vendor/assets/javascripts/codemirror/modes/properties.js +0 -63
  45. data/vendor/assets/javascripts/codemirror/modes/shell.js +0 -103
  46. data/vendor/assets/javascripts/codemirror/modes/smarty.js +0 -148
  47. data/vendor/assets/javascripts/codemirror/modes/tiki.js +0 -316
  48. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +0 -26
  49. data/vendor/assets/javascripts/codemirror/modes/xquery.js +0 -448
  50. data/vendor/assets/javascripts/codemirror/utils/closetag.js +0 -146
  51. data/vendor/assets/javascripts/codemirror/utils/dialog.js +0 -63
  52. data/vendor/assets/javascripts/codemirror/utils/foldcode.js +0 -196
  53. data/vendor/assets/javascripts/codemirror/utils/formatting.js +0 -297
  54. data/vendor/assets/javascripts/codemirror/utils/javascript-hint.js +0 -134
  55. data/vendor/assets/javascripts/codemirror/utils/loadmode.js +0 -51
  56. data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +0 -44
  57. data/vendor/assets/javascripts/codemirror/utils/multiplex.js +0 -72
  58. data/vendor/assets/javascripts/codemirror/utils/pig-hint.js +0 -123
  59. data/vendor/assets/javascripts/codemirror/utils/runmode.js +0 -49
  60. data/vendor/assets/javascripts/codemirror/utils/search.js +0 -118
  61. data/vendor/assets/javascripts/codemirror/utils/searchcursor.js +0 -117
  62. data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +0 -72
  63. data/vendor/assets/stylesheets/codemirror/modes/tiki.css +0 -26
  64. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +0 -81
  65. data/vendor/assets/stylesheets/codemirror/themes/blackboard.css +0 -25
  66. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +0 -21
  67. data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +0 -44
  68. data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +0 -27
  69. data/vendor/assets/stylesheets/codemirror/themes/xq-dark.css +0 -46
  70. data/vendor/assets/stylesheets/codemirror/utils/dialog.css +0 -23
  71. data/vendor/assets/stylesheets/codemirror/utils/simple-hint.css +0 -16
@@ -1,316 +0,0 @@
1
- CodeMirror.defineMode('tiki', function(config, parserConfig) {
2
- function inBlock(style, terminator, returnTokenizer) {
3
- return function(stream, state) {
4
- while (!stream.eol()) {
5
- if (stream.match(terminator)) {
6
- state.tokenize = inText;
7
- break;
8
- }
9
- stream.next();
10
- }
11
-
12
- if (returnTokenizer) state.tokenize = returnTokenizer;
13
-
14
- return style;
15
- };
16
- }
17
-
18
- function inLine(style, terminator) {
19
- return function(stream, state) {
20
- while(!stream.eol()) {
21
- stream.next()
22
- }
23
- state.tokenize = inText;
24
- return style;
25
- };
26
- }
27
-
28
- function inText(stream, state) {
29
- function chain(parser) {
30
- state.tokenize = parser;
31
- return parser(stream, state);
32
- }
33
-
34
- var sol = stream.sol();
35
- var ch = stream.next();
36
-
37
- //non start of line
38
- switch (ch) { //switch is generally much faster than if, so it is used here
39
- case "{": //plugin
40
- type = stream.eat("/") ? "closeTag" : "openTag";
41
- stream.eatSpace();
42
- tagName = "";
43
- var c;
44
- while ((c = stream.eat(/[^\s\u00a0=\"\'\/?(}]/))) tagName += c;
45
- state.tokenize = inPlugin;
46
- return "tag";
47
- break;
48
- case "_": //bold
49
- if (stream.eat("_")) {
50
- return chain(inBlock("strong", "__", inText));
51
- }
52
- break;
53
- case "'": //italics
54
- if (stream.eat("'")) {
55
- // Italic text
56
- return chain(inBlock("em", "''", inText));
57
- }
58
- break;
59
- case "(":// Wiki Link
60
- if (stream.eat("(")) {
61
- return chain(inBlock("variable-2", "))", inText));
62
- }
63
- break;
64
- case "[":// Weblink
65
- return chain(inBlock("variable-3", "]", inText));
66
- break;
67
- case "|": //table
68
- if (stream.eat("|")) {
69
- return chain(inBlock("comment", "||"));
70
- }
71
- break;
72
- case "-":
73
- if (stream.eat("=")) {//titleBar
74
- return chain(inBlock("header string", "=-", inText));
75
- } else if (stream.eat("-")) {//deleted
76
- return chain(inBlock("error tw-deleted", "--", inText));
77
- }
78
- break;
79
- case "=": //underline
80
- if (stream.match("==")) {
81
- return chain(inBlock("tw-underline", "===", inText));
82
- }
83
- break;
84
- case ":":
85
- if (stream.eat(":")) {
86
- return chain(inBlock("comment", "::"));
87
- }
88
- break;
89
- case "^": //box
90
- return chain(inBlock("tw-box", "^"));
91
- break;
92
- case "~": //np
93
- if (stream.match("np~")) {
94
- return chain(inBlock("meta", "~/np~"));
95
- }
96
- break;
97
- }
98
-
99
- //start of line types
100
- if (sol) {
101
- switch (ch) {
102
- case "!": //header at start of line
103
- if (stream.match('!!!!!')) {
104
- return chain(inLine("header string"));
105
- } else if (stream.match('!!!!')) {
106
- return chain(inLine("header string"));
107
- } else if (stream.match('!!!')) {
108
- return chain(inLine("header string"));
109
- } else if (stream.match('!!')) {
110
- return chain(inLine("header string"));
111
- } else {
112
- return chain(inLine("header string"));
113
- }
114
- break;
115
- case "*": //unordered list line item, or <li /> at start of line
116
- case "#": //ordered list line item, or <li /> at start of line
117
- case "+": //ordered list line item, or <li /> at start of line
118
- return chain(inLine("tw-listitem bracket"));
119
- break;
120
- }
121
- }
122
-
123
- //stream.eatWhile(/[&{]/); was eating up plugins, turned off to act less like html and more like tiki
124
- return null;
125
- }
126
-
127
- var indentUnit = config.indentUnit;
128
-
129
- // Return variables for tokenizers
130
- var pluginName, type;
131
- function inPlugin(stream, state) {
132
- var ch = stream.next();
133
- var peek = stream.peek();
134
-
135
- if (ch == "}") {
136
- state.tokenize = inText;
137
- //type = ch == ")" ? "endPlugin" : "selfclosePlugin"; inPlugin
138
- return "tag";
139
- } else if (ch == "(" || ch == ")") {
140
- return "bracket";
141
- } else if (ch == "=") {
142
- type = "equals";
143
-
144
- if (peek == ">") {
145
- ch = stream.next();
146
- peek = stream.peek();
147
- }
148
-
149
- //here we detect values directly after equal character with no quotes
150
- if (!/[\'\"]/.test(peek)) {
151
- state.tokenize = inAttributeNoQuote();
152
- }
153
- //end detect values
154
-
155
- return "operator";
156
- } else if (/[\'\"]/.test(ch)) {
157
- state.tokenize = inAttribute(ch);
158
- return state.tokenize(stream, state);
159
- } else {
160
- stream.eatWhile(/[^\s\u00a0=\"\'\/?]/);
161
- return "keyword";
162
- }
163
- }
164
-
165
- function inAttribute(quote) {
166
- return function(stream, state) {
167
- while (!stream.eol()) {
168
- if (stream.next() == quote) {
169
- state.tokenize = inPlugin;
170
- break;
171
- }
172
- }
173
- return "string";
174
- };
175
- }
176
-
177
- function inAttributeNoQuote() {
178
- return function(stream, state) {
179
- while (!stream.eol()) {
180
- var ch = stream.next();
181
- var peek = stream.peek();
182
- if (ch == " " || ch == "," || /[ )}]/.test(peek)) {
183
- state.tokenize = inPlugin;
184
- break;
185
- }
186
- }
187
- return "string";
188
- };
189
- }
190
-
191
- var curState, setStyle;
192
- function pass() {
193
- for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
194
- }
195
-
196
- function cont() {
197
- pass.apply(null, arguments);
198
- return true;
199
- }
200
-
201
- function pushContext(pluginName, startOfLine) {
202
- var noIndent = curState.context && curState.context.noIndent;
203
- curState.context = {
204
- prev: curState.context,
205
- pluginName: pluginName,
206
- indent: curState.indented,
207
- startOfLine: startOfLine,
208
- noIndent: noIndent
209
- };
210
- }
211
-
212
- function popContext() {
213
- if (curState.context) curState.context = curState.context.prev;
214
- }
215
-
216
- function element(type) {
217
- if (type == "openPlugin") {curState.pluginName = pluginName; return cont(attributes, endplugin(curState.startOfLine));}
218
- else if (type == "closePlugin") {
219
- var err = false;
220
- if (curState.context) {
221
- err = curState.context.pluginName != pluginName;
222
- popContext();
223
- } else {
224
- err = true;
225
- }
226
- if (err) setStyle = "error";
227
- return cont(endcloseplugin(err));
228
- }
229
- else if (type == "string") {
230
- if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");
231
- if (curState.tokenize == inText) popContext();
232
- return cont();
233
- }
234
- else return cont();
235
- }
236
-
237
- function endplugin(startOfLine) {
238
- return function(type) {
239
- if (
240
- type == "selfclosePlugin" ||
241
- type == "endPlugin"
242
- )
243
- return cont();
244
- if (type == "endPlugin") {pushContext(curState.pluginName, startOfLine); return cont();}
245
- return cont();
246
- };
247
- }
248
-
249
- function endcloseplugin(err) {
250
- return function(type) {
251
- if (err) setStyle = "error";
252
- if (type == "endPlugin") return cont();
253
- return pass();
254
- }
255
- }
256
-
257
- function attributes(type) {
258
- if (type == "keyword") {setStyle = "attribute"; return cont(attributes);}
259
- if (type == "equals") return cont(attvalue, attributes);
260
- return pass();
261
- }
262
- function attvalue(type) {
263
- if (type == "keyword") {setStyle = "string"; return cont();}
264
- if (type == "string") return cont(attvaluemaybe);
265
- return pass();
266
- }
267
- function attvaluemaybe(type) {
268
- if (type == "string") return cont(attvaluemaybe);
269
- else return pass();
270
- }
271
- return {
272
- startState: function() {
273
- return {tokenize: inText, cc: [], indented: 0, startOfLine: true, pluginName: null, context: null};
274
- },
275
- token: function(stream, state) {
276
- if (stream.sol()) {
277
- state.startOfLine = true;
278
- state.indented = stream.indentation();
279
- }
280
- if (stream.eatSpace()) return null;
281
-
282
- setStyle = type = pluginName = null;
283
- var style = state.tokenize(stream, state);
284
- if ((style || type) && style != "comment") {
285
- curState = state;
286
- while (true) {
287
- var comb = state.cc.pop() || element;
288
- if (comb(type || style)) break;
289
- }
290
- }
291
- state.startOfLine = false;
292
- return setStyle || style;
293
- },
294
- indent: function(state, textAfter) {
295
- var context = state.context;
296
- if (context && context.noIndent) return 0;
297
- if (context && /^{\//.test(textAfter))
298
- context = context.prev;
299
- while (context && !context.startOfLine)
300
- context = context.prev;
301
- if (context) return context.indent + indentUnit;
302
- else return 0;
303
- },
304
- compareStates: function(a, b) {
305
- if (a.indented != b.indented || a.pluginName != b.pluginName) return false;
306
- for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) {
307
- if (!ca || !cb) return ca == cb;
308
- if (ca.pluginName != cb.pluginName) return false;
309
- }
310
- },
311
- electricChars: "/"
312
- };
313
- });
314
-
315
- //I figure, why not
316
- CodeMirror.defineMIME("text/tiki", "tiki");
@@ -1,26 +0,0 @@
1
- CodeMirror.defineMode("vbscript", function() {
2
- var regexVBScriptKeyword = /^(?:Call|Case|CDate|Clear|CInt|CLng|Const|CStr|Description|Dim|Do|Each|Else|ElseIf|End|Err|Error|Exit|False|For|Function|If|LCase|Loop|LTrim|Next|Nothing|Now|Number|On|Preserve|Quit|ReDim|Resume|RTrim|Select|Set|Sub|Then|To|Trim|True|UBound|UCase|Until|VbCr|VbCrLf|VbLf|VbTab)$/im;
3
-
4
- return {
5
- token: function(stream) {
6
- if (stream.eatSpace()) return null;
7
- var ch = stream.next();
8
- if (ch == "'") {
9
- stream.skipToEnd();
10
- return "comment";
11
- }
12
- if (ch == '"') {
13
- stream.skipTo('"');
14
- return "string";
15
- }
16
-
17
- if (/\w/.test(ch)) {
18
- stream.eatWhile(/\w/);
19
- if (regexVBScriptKeyword.test(stream.current())) return "keyword";
20
- }
21
- return null;
22
- }
23
- };
24
- });
25
-
26
- CodeMirror.defineMIME("text/vbscript", "vbscript");
@@ -1,448 +0,0 @@
1
- /*
2
- Copyright (C) 2011 by MarkLogic Corporation
3
- Author: Mike Brevoort <mike@brevoort.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
22
- */
23
- CodeMirror.defineMode("xquery", function(config, parserConfig) {
24
-
25
- // The keywords object is set to the result of this self executing
26
- // function. Each keyword is a property of the keywords object whose
27
- // value is {type: atype, style: astyle}
28
- var keywords = function(){
29
- // conveinence functions used to build keywords object
30
- function kw(type) {return {type: type, style: "keyword"};}
31
- var A = kw("keyword a")
32
- , B = kw("keyword b")
33
- , C = kw("keyword c")
34
- , operator = kw("operator")
35
- , atom = {type: "atom", style: "atom"}
36
- , punctuation = {type: "punctuation", style: ""}
37
- , qualifier = {type: "axis_specifier", style: "qualifier"};
38
-
39
- // kwObj is what is return from this function at the end
40
- var kwObj = {
41
- 'if': A, 'switch': A, 'while': A, 'for': A,
42
- 'else': B, 'then': B, 'try': B, 'finally': B, 'catch': B,
43
- 'element': C, 'attribute': C, 'let': C, 'implements': C, 'import': C, 'module': C, 'namespace': C,
44
- 'return': C, 'super': C, 'this': C, 'throws': C, 'where': C, 'private': C,
45
- ',': punctuation,
46
- 'null': atom, 'fn:false()': atom, 'fn:true()': atom
47
- };
48
-
49
- // a list of 'basic' keywords. For each add a property to kwObj with the value of
50
- // {type: basic[i], style: "keyword"} e.g. 'after' --> {type: "after", style: "keyword"}
51
- var basic = ['after','ancestor','ancestor-or-self','and','as','ascending','assert','attribute','before',
52
- 'by','case','cast','child','comment','declare','default','define','descendant','descendant-or-self',
53
- 'descending','document','document-node','element','else','eq','every','except','external','following',
54
- 'following-sibling','follows','for','function','if','import','in','instance','intersect','item',
55
- 'let','module','namespace','node','node','of','only','or','order','parent','precedes','preceding',
56
- 'preceding-sibling','processing-instruction','ref','return','returns','satisfies','schema','schema-element',
57
- 'self','some','sortby','stable','text','then','to','treat','typeswitch','union','variable','version','where',
58
- 'xquery', 'empty-sequence'];
59
- for(var i=0, l=basic.length; i < l; i++) { kwObj[basic[i]] = kw(basic[i])};
60
-
61
- // a list of types. For each add a property to kwObj with the value of
62
- // {type: "atom", style: "atom"}
63
- var types = ['xs:string', 'xs:float', 'xs:decimal', 'xs:double', 'xs:integer', 'xs:boolean', 'xs:date', 'xs:dateTime',
64
- 'xs:time', 'xs:duration', 'xs:dayTimeDuration', 'xs:time', 'xs:yearMonthDuration', 'numeric', 'xs:hexBinary',
65
- 'xs:base64Binary', 'xs:anyURI', 'xs:QName', 'xs:byte','xs:boolean','xs:anyURI','xf:yearMonthDuration'];
66
- for(var i=0, l=types.length; i < l; i++) { kwObj[types[i]] = atom;};
67
-
68
- // each operator will add a property to kwObj with value of {type: "operator", style: "keyword"}
69
- var operators = ['eq', 'ne', 'lt', 'le', 'gt', 'ge', ':=', '=', '>', '>=', '<', '<=', '.', '|', '?', 'and', 'or', 'div', 'idiv', 'mod', '*', '/', '+', '-'];
70
- for(var i=0, l=operators.length; i < l; i++) { kwObj[operators[i]] = operator;};
71
-
72
- // each axis_specifiers will add a property to kwObj with value of {type: "axis_specifier", style: "qualifier"}
73
- var axis_specifiers = ["self::", "attribute::", "child::", "descendant::", "descendant-or-self::", "parent::",
74
- "ancestor::", "ancestor-or-self::", "following::", "preceding::", "following-sibling::", "preceding-sibling::"];
75
- for(var i=0, l=axis_specifiers.length; i < l; i++) { kwObj[axis_specifiers[i]] = qualifier; };
76
-
77
- return kwObj;
78
- }();
79
-
80
- // Used as scratch variables to communicate multiple values without
81
- // consing up tons of objects.
82
- var type, content;
83
-
84
- function ret(tp, style, cont) {
85
- type = tp; content = cont;
86
- return style;
87
- }
88
-
89
- function chain(stream, state, f) {
90
- state.tokenize = f;
91
- return f(stream, state);
92
- }
93
-
94
- // the primary mode tokenizer
95
- function tokenBase(stream, state) {
96
- var ch = stream.next(),
97
- mightBeFunction = false,
98
- isEQName = isEQNameAhead(stream);
99
-
100
- // an XML tag (if not in some sub, chained tokenizer)
101
- if (ch == "<") {
102
- if(stream.match("!--", true))
103
- return chain(stream, state, tokenXMLComment);
104
-
105
- if(stream.match("![CDATA", false)) {
106
- state.tokenize = tokenCDATA;
107
- return ret("tag", "tag");
108
- }
109
-
110
- if(stream.match("?", false)) {
111
- return chain(stream, state, tokenPreProcessing);
112
- }
113
-
114
- var isclose = stream.eat("/");
115
- stream.eatSpace();
116
- var tagName = "", c;
117
- while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
118
-
119
- return chain(stream, state, tokenTag(tagName, isclose));
120
- }
121
- // start code block
122
- else if(ch == "{") {
123
- pushStateStack(state,{ type: "codeblock"});
124
- return ret("", "");
125
- }
126
- // end code block
127
- else if(ch == "}") {
128
- popStateStack(state);
129
- return ret("", "");
130
- }
131
- // if we're in an XML block
132
- else if(isInXmlBlock(state)) {
133
- if(ch == ">")
134
- return ret("tag", "tag");
135
- else if(ch == "/" && stream.eat(">")) {
136
- popStateStack(state);
137
- return ret("tag", "tag");
138
- }
139
- else
140
- return ret("word", "word");
141
- }
142
- // if a number
143
- else if (/\d/.test(ch)) {
144
- stream.match(/^\d*(?:\.\d*)?(?:E[+\-]?\d+)?/);
145
- return ret("number", "atom");
146
- }
147
- // comment start
148
- else if (ch === "(" && stream.eat(":")) {
149
- pushStateStack(state, { type: "comment"});
150
- return chain(stream, state, tokenComment);
151
- }
152
- // quoted string
153
- else if ( !isEQName && (ch === '"' || ch === "'"))
154
- return chain(stream, state, tokenString(ch));
155
- // variable
156
- else if(ch === "$") {
157
- return chain(stream, state, tokenVariable);
158
- }
159
- // assignment
160
- else if(ch ===":" && stream.eat("=")) {
161
- return ret("operator", "keyword");
162
- }
163
- // open paren
164
- else if(ch === "(") {
165
- pushStateStack(state, { type: "paren"});
166
- return ret("", "");
167
- }
168
- // close paren
169
- else if(ch === ")") {
170
- popStateStack(state);
171
- return ret("", "");
172
- }
173
- // open paren
174
- else if(ch === "[") {
175
- pushStateStack(state, { type: "bracket"});
176
- return ret("", "");
177
- }
178
- // close paren
179
- else if(ch === "]") {
180
- popStateStack(state);
181
- return ret("", "");
182
- }
183
- else {
184
- var known = keywords.propertyIsEnumerable(ch) && keywords[ch];
185
-
186
- // if there's a EQName ahead, consume the rest of the string portion, it's likely a function
187
- if(isEQName && ch === '\"') while(stream.next() !== '"'){}
188
- if(isEQName && ch === '\'') while(stream.next() !== '\''){}
189
-
190
- // gobble up a word if the character is not known
191
- if(!known) stream.eatWhile(/[\w\$_-]/);
192
-
193
- // gobble a colon in the case that is a lib func type call fn:doc
194
- var foundColon = stream.eat(":")
195
-
196
- // if there's not a second colon, gobble another word. Otherwise, it's probably an axis specifier
197
- // which should get matched as a keyword
198
- if(!stream.eat(":") && foundColon) {
199
- stream.eatWhile(/[\w\$_-]/);
200
- }
201
- // if the next non whitespace character is an open paren, this is probably a function (if not a keyword of other sort)
202
- if(stream.match(/^[ \t]*\(/, false)) {
203
- mightBeFunction = true;
204
- }
205
- // is the word a keyword?
206
- var word = stream.current();
207
- known = keywords.propertyIsEnumerable(word) && keywords[word];
208
-
209
- // if we think it's a function call but not yet known,
210
- // set style to variable for now for lack of something better
211
- if(mightBeFunction && !known) known = {type: "function_call", style: "variable def"};
212
-
213
- // if the previous word was element, attribute, axis specifier, this word should be the name of that
214
- if(isInXmlConstructor(state)) {
215
- popStateStack(state);
216
- return ret("word", "word", word);
217
- }
218
- // as previously checked, if the word is element,attribute, axis specifier, call it an "xmlconstructor" and
219
- // push the stack so we know to look for it on the next word
220
- if(word == "element" || word == "attribute" || known.type == "axis_specifier") pushStateStack(state, {type: "xmlconstructor"});
221
-
222
- // if the word is known, return the details of that else just call this a generic 'word'
223
- return known ? ret(known.type, known.style, word) :
224
- ret("word", "word", word);
225
- }
226
- }
227
-
228
- // handle comments, including nested
229
- function tokenComment(stream, state) {
230
- var maybeEnd = false, maybeNested = false, nestedCount = 0, ch;
231
- while (ch = stream.next()) {
232
- if (ch == ")" && maybeEnd) {
233
- if(nestedCount > 0)
234
- nestedCount--;
235
- else {
236
- popStateStack(state);
237
- break;
238
- }
239
- }
240
- else if(ch == ":" && maybeNested) {
241
- nestedCount++;
242
- }
243
- maybeEnd = (ch == ":");
244
- maybeNested = (ch == "(");
245
- }
246
-
247
- return ret("comment", "comment");
248
- }
249
-
250
- // tokenizer for string literals
251
- // optionally pass a tokenizer function to set state.tokenize back to when finished
252
- function tokenString(quote, f) {
253
- return function(stream, state) {
254
- var ch;
255
-
256
- if(isInString(state) && stream.current() == quote) {
257
- popStateStack(state);
258
- if(f) state.tokenize = f;
259
- return ret("string", "string");
260
- }
261
-
262
- pushStateStack(state, { type: "string", name: quote, tokenize: tokenString(quote, f) });
263
-
264
- // if we're in a string and in an XML block, allow an embedded code block
265
- if(stream.match("{", false) && isInXmlAttributeBlock(state)) {
266
- state.tokenize = tokenBase;
267
- return ret("string", "string");
268
- }
269
-
270
-
271
- while (ch = stream.next()) {
272
- if (ch == quote) {
273
- popStateStack(state);
274
- if(f) state.tokenize = f;
275
- break;
276
- }
277
- else {
278
- // if we're in a string and in an XML block, allow an embedded code block in an attribute
279
- if(stream.match("{", false) && isInXmlAttributeBlock(state)) {
280
- state.tokenize = tokenBase;
281
- return ret("string", "string");
282
- }
283
-
284
- }
285
- }
286
-
287
- return ret("string", "string");
288
- };
289
- }
290
-
291
- // tokenizer for variables
292
- function tokenVariable(stream, state) {
293
- var isVariableChar = /[\w\$_-]/;
294
-
295
- // a variable may start with a quoted EQName so if the next character is quote, consume to the next quote
296
- if(stream.eat("\"")) {
297
- while(stream.next() !== '\"'){};
298
- stream.eat(":");
299
- } else {
300
- stream.eatWhile(isVariableChar);
301
- if(!stream.match(":=", false)) stream.eat(":");
302
- }
303
- stream.eatWhile(isVariableChar);
304
- state.tokenize = tokenBase;
305
- return ret("variable", "variable");
306
- }
307
-
308
- // tokenizer for XML tags
309
- function tokenTag(name, isclose) {
310
- return function(stream, state) {
311
- stream.eatSpace();
312
- if(isclose && stream.eat(">")) {
313
- popStateStack(state);
314
- state.tokenize = tokenBase;
315
- return ret("tag", "tag");
316
- }
317
- // self closing tag without attributes?
318
- if(!stream.eat("/"))
319
- pushStateStack(state, { type: "tag", name: name, tokenize: tokenBase});
320
- if(!stream.eat(">")) {
321
- state.tokenize = tokenAttribute;
322
- return ret("tag", "tag");
323
- }
324
- else {
325
- state.tokenize = tokenBase;
326
- }
327
- return ret("tag", "tag");
328
- }
329
- }
330
-
331
- // tokenizer for XML attributes
332
- function tokenAttribute(stream, state) {
333
- var ch = stream.next();
334
-
335
- if(ch == "/" && stream.eat(">")) {
336
- if(isInXmlAttributeBlock(state)) popStateStack(state);
337
- if(isInXmlBlock(state)) popStateStack(state);
338
- return ret("tag", "tag");
339
- }
340
- if(ch == ">") {
341
- if(isInXmlAttributeBlock(state)) popStateStack(state);
342
- return ret("tag", "tag");
343
- }
344
- if(ch == "=")
345
- return ret("", "");
346
- // quoted string
347
- if (ch == '"' || ch == "'")
348
- return chain(stream, state, tokenString(ch, tokenAttribute));
349
-
350
- if(!isInXmlAttributeBlock(state))
351
- pushStateStack(state, { type: "attribute", name: name, tokenize: tokenAttribute});
352
-
353
- stream.eat(/[a-zA-Z_:]/);
354
- stream.eatWhile(/[-a-zA-Z0-9_:.]/);
355
- stream.eatSpace();
356
-
357
- // the case where the attribute has not value and the tag was closed
358
- if(stream.match(">", false) || stream.match("/", false)) {
359
- popStateStack(state);
360
- state.tokenize = tokenBase;
361
- }
362
-
363
- return ret("attribute", "attribute");
364
- }
365
-
366
- // handle comments, including nested
367
- function tokenXMLComment(stream, state) {
368
- while (ch = stream.next()) {
369
- if (ch == "-" && stream.match("->", true)) {
370
- state.tokenize = tokenBase;
371
- return ret("comment", "comment");
372
- }
373
- }
374
- }
375
-
376
-
377
- // handle CDATA
378
- function tokenCDATA(stream, state) {
379
- while (ch = stream.next()) {
380
- if (ch == "]" && stream.match("]", true)) {
381
- state.tokenize = tokenBase;
382
- return ret("comment", "comment");
383
- }
384
- }
385
- }
386
-
387
- // handle preprocessing instructions
388
- function tokenPreProcessing(stream, state) {
389
- while (ch = stream.next()) {
390
- if (ch == "?" && stream.match(">", true)) {
391
- state.tokenize = tokenBase;
392
- return ret("comment", "comment meta");
393
- }
394
- }
395
- }
396
-
397
-
398
- // functions to test the current context of the state
399
- function isInXmlBlock(state) { return isIn(state, "tag"); }
400
- function isInXmlAttributeBlock(state) { return isIn(state, "attribute"); }
401
- function isInCodeBlock(state) { return isIn(state, "codeblock"); }
402
- function isInXmlConstructor(state) { return isIn(state, "xmlconstructor"); }
403
- function isInString(state) { return isIn(state, "string"); }
404
-
405
- function isEQNameAhead(stream) {
406
- // assume we've already eaten a quote (")
407
- if(stream.current() === '"')
408
- return stream.match(/^[^\"]+\"\:/, false);
409
- else if(stream.current() === '\'')
410
- return stream.match(/^[^\"]+\'\:/, false);
411
- else
412
- return false;
413
- }
414
-
415
- function isIn(state, type) {
416
- return (state.stack.length && state.stack[state.stack.length - 1].type == type);
417
- }
418
-
419
- function pushStateStack(state, newState) {
420
- state.stack.push(newState);
421
- }
422
-
423
- function popStateStack(state) {
424
- var popped = state.stack.pop();
425
- var reinstateTokenize = state.stack.length && state.stack[state.stack.length-1].tokenize
426
- state.tokenize = reinstateTokenize || tokenBase;
427
- }
428
-
429
- // the interface for the mode API
430
- return {
431
- startState: function(basecolumn) {
432
- return {
433
- tokenize: tokenBase,
434
- cc: [],
435
- stack: []
436
- };
437
- },
438
-
439
- token: function(stream, state) {
440
- if (stream.eatSpace()) return null;
441
- var style = state.tokenize(stream, state);
442
- return style;
443
- }
444
- };
445
-
446
- });
447
-
448
- CodeMirror.defineMIME("application/xquery", "xquery");