PluginProbe
WPIDE – File Manager & Code Editor / 2.2
WPIDE – File Manager & Code Editor v2.2
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
wpide / ace-0.2.0 / src / mode-javascript.js

mode-javascript.js in WPIDE – File Manager & Code Editor 2.2, at ace-0.2.0/src/mode-javascript.js

948 lines 39.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Distributed under the BSD license:
3 *
4 * Copyright (c) 2010, Ajax.org B.V.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of Ajax.org B.V. nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * ***** END LICENSE BLOCK ***** */
30
31 define('ace/mode/javascript', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/javascript_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range', 'ace/worker/worker_client', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
32
33
34 var oop = require("../lib/oop");
35 var TextMode = require("./text").Mode;
36 var Tokenizer = require("../tokenizer").Tokenizer;
37 var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
38 var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39 var Range = require("../range").Range;
40 var WorkerClient = require("../worker/worker_client").WorkerClient;
41 var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
42 var CStyleFoldMode = require("./folding/cstyle").FoldMode;
43
44 var Mode = function() {
45 this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules());
46 this.$outdent = new MatchingBraceOutdent();
47 this.$behaviour = new CstyleBehaviour();
48 this.foldingRules = new CStyleFoldMode();
49 };
50 oop.inherits(Mode, TextMode);
51
52 (function() {
53
54
55 this.toggleCommentLines = function(state, doc, startRow, endRow) {
56 var outdent = true;
57 var re = /^(\s*)\/\//;
58
59 for (var i=startRow; i<= endRow; i++) {
60 if (!re.test(doc.getLine(i))) {
61 outdent = false;
62 break;
63 }
64 }
65
66 if (outdent) {
67 var deleteRange = new Range(0, 0, 0, 0);
68 for (var i=startRow; i<= endRow; i++)
69 {
70 var line = doc.getLine(i);
71 var m = line.match(re);
72 deleteRange.start.row = i;
73 deleteRange.end.row = i;
74 deleteRange.end.column = m[0].length;
75 doc.replace(deleteRange, m[1]);
76 }
77 }
78 else {
79 doc.indentRows(startRow, endRow, "//");
80 }
81 };
82
83 this.getNextLineIndent = function(state, line, tab) {
84 var indent = this.$getIndent(line);
85
86 var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
87 var tokens = tokenizedLine.tokens;
88 var endState = tokenizedLine.state;
89
90 if (tokens.length && tokens[tokens.length-1].type == "comment") {
91 return indent;
92 }
93
94 if (state == "start" || state == "regex_allowed") {
95 var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
96 if (match) {
97 indent += tab;
98 }
99 } else if (state == "doc-start") {
100 if (endState == "start" || state == "regex_allowed") {
101 return "";
102 }
103 var match = line.match(/^\s*(\/?)\*/);
104 if (match) {
105 if (match[1]) {
106 indent += " ";
107 }
108 indent += "* ";
109 }
110 }
111
112 return indent;
113 };
114
115 this.checkOutdent = function(state, line, input) {
116 return this.$outdent.checkOutdent(line, input);
117 };
118
119 this.autoOutdent = function(state, doc, row) {
120 this.$outdent.autoOutdent(doc, row);
121 };
122
123 this.createWorker = function(session) {
124 var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
125 worker.attachToDocument(session.getDocument());
126
127 worker.on("jslint", function(results) {
128 session.setAnnotations(results.data);
129 });
130
131 worker.on("terminate", function() {
132 session.clearAnnotations();
133 });
134
135 return worker;
136 };
137
138 }).call(Mode.prototype);
139
140 exports.Mode = Mode;
141 });
142
143 define('ace/mode/javascript_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
144
145
146 var oop = require("../lib/oop");
147 var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
148 var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
149
150 var JavaScriptHighlightRules = function() {
151 var keywordMapper = this.createKeywordMapper({
152 "variable.language":
153 "Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
154 "Namespace|QName|XML|XMLList|" + // E4X
155 "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
156 "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
157 "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
158 "SyntaxError|TypeError|URIError|" +
159 "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
160 "isNaN|parseFloat|parseInt|" +
161 "JSON|Math|" + // Other
162 "this|arguments|prototype|window|document" , // Pseudo
163 "keyword":
164 "const|yield|import|get|set|" +
165 "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
166 "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
167 "__parent__|__count__|escape|unescape|with|__proto__|" +
168 "class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
169 "storage.type":
170 "const|let|var|function",
171 "constant.language":
172 "null|Infinity|NaN|undefined",
173 "support.function":
174 "alert"
175 }, "identifier");
176 var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield";
177 var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
178
179 var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
180 "u[0-9a-fA-F]{4}|" + // unicode
181 "[0-2][0-7]{0,2}|" + // oct
182 "3[0-6][0-7]?|" + // oct
183 "37[0-7]?|" + // oct
184 "[4-7][0-7]?|" + //oct
185 ".)";
186
187 this.$rules = {
188 "start" : [
189 {
190 token : "comment",
191 regex : /\/\/.*$/
192 },
193 DocCommentHighlightRules.getStartRule("doc-start"),
194 {
195 token : "comment", // multi line comment
196 merge : true,
197 regex : /\/\*/,
198 next : "comment"
199 }, {
200 token : "string",
201 regex : "'(?=.)",
202 next : "qstring"
203 }, {
204 token : "string",
205 regex : '"(?=.)',
206 next : "qqstring"
207 }, {
208 token : "constant.numeric", // hex
209 regex : /0[xX][0-9a-fA-F]+\b/
210 }, {
211 token : "constant.numeric", // float
212 regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
213 }, {
214 token : [
215 "storage.type", "punctuation.operator", "support.function",
216 "punctuation.operator", "entity.name.function", "text","keyword.operator"
217 ],
218 regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
219 next: "function_arguments"
220 }, {
221 token : [
222 "storage.type", "punctuation.operator", "entity.name.function", "text",
223 "keyword.operator", "text", "storage.type", "text", "paren.lparen"
224 ],
225 regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
226 next: "function_arguments"
227 }, {
228 token : [
229 "entity.name.function", "text", "keyword.operator", "text", "storage.type",
230 "text", "paren.lparen"
231 ],
232 regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
233 next: "function_arguments"
234 }, {
235 token : [
236 "storage.type", "punctuation.operator", "entity.name.function", "text",
237 "keyword.operator", "text",
238 "storage.type", "text", "entity.name.function", "text", "paren.lparen"
239 ],
240 regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
241 next: "function_arguments"
242 }, {
243 token : [
244 "storage.type", "text", "entity.name.function", "text", "paren.lparen"
245 ],
246 regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
247 next: "function_arguments"
248 }, {
249 token : [
250 "entity.name.function", "text", "punctuation.operator",
251 "text", "storage.type", "text", "paren.lparen"
252 ],
253 regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
254 next: "function_arguments"
255 }, {
256 token : [
257 "text", "text", "storage.type", "text", "paren.lparen"
258 ],
259 regex : "(:)(\\s*)(function)(\\s*)(\\()",
260 next: "function_arguments"
261 }, {
262 token : "constant.language.boolean",
263 regex : /(?:true|false)\b/
264 }, {
265 token : "keyword",
266 regex : "(?:" + kwBeforeRe + ")\\b",
267 next : "regex_allowed"
268 }, {
269 token : ["punctuation.operator", "support.function"],
270 regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:opzzzz|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
271 }, {
272 token : ["punctuation.operator", "support.function.dom"],
273 regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
274 }, {
275 token : ["punctuation.operator", "support.constant"],
276 regex : /(\.)(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/
277 }, {
278 token : ["storage.type", "punctuation.operator", "support.function.firebug"],
279 regex : /(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/
280 }, {
281 token : keywordMapper,
282 regex : identifierRe
283 }, {
284 token : "keyword.operator",
285 regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/,
286 next : "regex_allowed"
287 }, {
288 token : "punctuation.operator",
289 regex : /\?|\:|\,|\;|\./,
290 next : "regex_allowed"
291 }, {
292 token : "paren.lparen",
293 regex : /[\[({]/,
294 next : "regex_allowed"
295 }, {
296 token : "paren.rparen",
297 regex : /[\])}]/
298 }, {
299 token : "keyword.operator",
300 regex : /\/=?/,
301 next : "regex_allowed"
302 }, {
303 token: "comment",
304 regex: /^#!.*$/
305 }, {
306 token : "text",
307 regex : /\s+/
308 }
309 ],
310 "regex_allowed": [
311 DocCommentHighlightRules.getStartRule("doc-start"),
312 {
313 token : "comment", // multi line comment
314 merge : true,
315 regex : "\\/\\*",
316 next : "comment_regex_allowed"
317 }, {
318 token : "comment",
319 regex : "\\/\\/.*$"
320 }, {
321 token: "string.regexp",
322 regex: "\\/",
323 next: "regex",
324 merge: true
325 }, {
326 token : "text",
327 regex : "\\s+"
328 }, {
329 token: "empty",
330 regex: "",
331 next: "start"
332 }
333 ],
334 "regex": [
335 {
336 token: "regexp.keyword.operator",
337 regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
338 }, {
339 token: "string.regexp",
340 regex: "/\\w*",
341 next: "start",
342 merge: true
343 }, {
344 token : "invalid",
345 regex: /\{\d+,?(?:\d+)?}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
346 }, {
347 token : "constant.language.escape",
348 regex: /\(\?[:=!]|\)|{\d+,?(?:\d+)?}|{,\d+}|[+*]\?|[(|)$^+*?]/
349 }, {
350 token: "string.regexp",
351 regex: /{|[^{\[\/\\(|)$^+*?]+/,
352 merge: true
353 }, {
354 token: "constant.language.escape",
355 regex: /\[\^?/,
356 next: "regex_character_class",
357 merge: true
358 }, {
359 token: "empty",
360 regex: "",
361 next: "start"
362 }
363 ],
364 "regex_character_class": [
365 {
366 token: "regexp.keyword.operator",
367 regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
368 }, {
369 token: "constant.language.escape",
370 regex: "]",
371 next: "regex",
372 merge: true
373 }, {
374 token: "constant.language.escape",
375 regex: "-"
376 }, {
377 token: "string.regexp.charachterclass",
378 regex: /[^\]\-\\]+/,
379 merge: true
380 }, {
381 token: "empty",
382 regex: "",
383 next: "start"
384 }
385 ],
386 "function_arguments": [
387 {
388 token: "variable.parameter",
389 regex: identifierRe
390 }, {
391 token: "punctuation.operator",
392 regex: "[, ]+",
393 merge: true
394 }, {
395 token: "punctuation.operator",
396 regex: "$",
397 merge: true
398 }, {
399 token: "empty",
400 regex: "",
401 next: "start"
402 }
403 ],
404 "comment_regex_allowed" : [
405 {
406 token : "comment", // closing comment
407 regex : ".*?\\*\\/",
408 merge : true,
409 next : "regex_allowed"
410 }, {
411 token : "comment", // comment spanning whole line
412 merge : true,
413 regex : ".+"
414 }
415 ],
416 "comment" : [
417 {
418 token : "comment", // closing comment
419 regex : ".*?\\*\\/",
420 merge : true,
421 next : "start"
422 }, {
423 token : "comment", // comment spanning whole line
424 merge : true,
425 regex : ".+"
426 }
427 ],
428 "qqstring" : [
429 {
430 token : "constant.language.escape",
431 regex : escapedRe
432 }, {
433 token : "string",
434 regex : '[^"\\\\]+',
435 merge : true
436 }, {
437 token : "string",
438 regex : "\\\\$",
439 next : "qqstring",
440 merge : true
441 }, {
442 token : "string",
443 regex : '"|$',
444 next : "start",
445 merge : true
446 }
447 ],
448 "qstring" : [
449 {
450 token : "constant.language.escape",
451 regex : escapedRe
452 }, {
453 token : "string",
454 regex : "[^'\\\\]+",
455 merge : true
456 }, {
457 token : "string",
458 regex : "\\\\$",
459 next : "qstring",
460 merge : true
461 }, {
462 token : "string",
463 regex : "'|$",
464 next : "start",
465 merge : true
466 }
467 ]
468 };
469
470 this.embedRules(DocCommentHighlightRules, "doc-",
471 [ DocCommentHighlightRules.getEndRule("start") ]);
472 };
473
474 oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
475
476 exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
477 });
478
479 define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
480
481
482 var oop = require("../lib/oop");
483 var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
484
485 var DocCommentHighlightRules = function() {
486
487 this.$rules = {
488 "start" : [ {
489 token : "comment.doc.tag",
490 regex : "@[\\w\\d_]+" // TODO: fix email addresses
491 }, {
492 token : "comment.doc",
493 merge : true,
494 regex : "\\s+"
495 }, {
496 token : "comment.doc",
497 merge : true,
498 regex : "TODO"
499 }, {
500 token : "comment.doc",
501 merge : true,
502 regex : "[^@\\*]+"
503 }, {
504 token : "comment.doc",
505 merge : true,
506 regex : "."
507 }]
508 };
509 };
510
511 oop.inherits(DocCommentHighlightRules, TextHighlightRules);
512
513 DocCommentHighlightRules.getStartRule = function(start) {
514 return {
515 token : "comment.doc", // doc comment
516 merge : true,
517 regex : "\\/\\*(?=\\*)",
518 next : start
519 };
520 };
521
522 DocCommentHighlightRules.getEndRule = function (start) {
523 return {
524 token : "comment.doc", // closing comment
525 merge : true,
526 regex : "\\*\\/",
527 next : start
528 };
529 };
530
531
532 exports.DocCommentHighlightRules = DocCommentHighlightRules;
533
534 });
535
536 define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
537
538
539 var Range = require("../range").Range;
540
541 var MatchingBraceOutdent = function() {};
542
543 (function() {
544
545 this.checkOutdent = function(line, input) {
546 if (! /^\s+$/.test(line))
547 return false;
548
549 return /^\s*\}/.test(input);
550 };
551
552 this.autoOutdent = function(doc, row) {
553 var line = doc.getLine(row);
554 var match = line.match(/^(\s*\})/);
555
556 if (!match) return 0;
557
558 var column = match[1].length;
559 var openBracePos = doc.findMatchingBracket({row: row, column: column});
560
561 if (!openBracePos || openBracePos.row == row) return 0;
562
563 var indent = this.$getIndent(doc.getLine(openBracePos.row));
564 doc.replace(new Range(row, 0, row, column-1), indent);
565 };
566
567 this.$getIndent = function(line) {
568 var match = line.match(/^(\s+)/);
569 if (match) {
570 return match[1];
571 }
572
573 return "";
574 };
575
576 }).call(MatchingBraceOutdent.prototype);
577
578 exports.MatchingBraceOutdent = MatchingBraceOutdent;
579 });
580
581 define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
582
583
584 var oop = require("../../lib/oop");
585 var Behaviour = require("../behaviour").Behaviour;
586 var TokenIterator = require("../../token_iterator").TokenIterator;
587 var lang = require("../../lib/lang");
588
589 var SAFE_INSERT_IN_TOKENS =
590 ["text", "paren.rparen", "punctuation.operator"];
591 var SAFE_INSERT_BEFORE_TOKENS =
592 ["text", "paren.rparen", "punctuation.operator", "comment"];
593
594
595 var autoInsertedBrackets = 0;
596 var autoInsertedRow = -1;
597 var autoInsertedLineEnd = "";
598 var maybeInsertedBrackets = 0;
599 var maybeInsertedRow = -1;
600 var maybeInsertedLineStart = "";
601 var maybeInsertedLineEnd = "";
602
603 var CstyleBehaviour = function () {
604
605 CstyleBehaviour.isSaneInsertion = function(editor, session) {
606 var cursor = editor.getCursorPosition();
607 var iterator = new TokenIterator(session, cursor.row, cursor.column);
608 if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
609 var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
610 if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
611 return false;
612 }
613 iterator.stepForward();
614 return iterator.getCurrentTokenRow() !== cursor.row ||
615 this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
616 };
617
618 CstyleBehaviour.$matchTokenType = function(token, types) {
619 return types.indexOf(token.type || token) > -1;
620 };
621
622 CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
623 var cursor = editor.getCursorPosition();
624 var line = session.doc.getLine(cursor.row);
625 if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
626 autoInsertedBrackets = 0;
627 autoInsertedRow = cursor.row;
628 autoInsertedLineEnd = bracket + line.substr(cursor.column);
629 autoInsertedBrackets++;
630 };
631
632 CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
633 var cursor = editor.getCursorPosition();
634 var line = session.doc.getLine(cursor.row);
635 if (!this.isMaybeInsertedClosing(cursor, line))
636 maybeInsertedBrackets = 0;
637 maybeInsertedRow = cursor.row;
638 maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
639 maybeInsertedLineEnd = line.substr(cursor.column);
640 maybeInsertedBrackets++;
641 };
642
643 CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
644 return autoInsertedBrackets > 0 &&
645 cursor.row === autoInsertedRow &&
646 bracket === autoInsertedLineEnd[0] &&
647 line.substr(cursor.column) === autoInsertedLineEnd;
648 };
649
650 CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
651 return maybeInsertedBrackets > 0 &&
652 cursor.row === maybeInsertedRow &&
653 line.substr(cursor.column) === maybeInsertedLineEnd &&
654 line.substr(0, cursor.column) == maybeInsertedLineStart;
655 };
656
657 CstyleBehaviour.popAutoInsertedClosing = function() {
658 autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
659 autoInsertedBrackets--;
660 };
661
662 CstyleBehaviour.clearMaybeInsertedClosing = function() {
663 maybeInsertedBrackets = 0;
664 maybeInsertedRow = -1;
665 };
666
667 this.add("braces", "insertion", function (state, action, editor, session, text) {
668 var cursor = editor.getCursorPosition();
669 var line = session.doc.getLine(cursor.row);
670 if (text == '{') {
671 var selection = editor.getSelectionRange();
672 var selected = session.doc.getTextRange(selection);
673 if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
674 return {
675 text: '{' + selected + '}',
676 selection: false
677 };
678 } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
679 if (/[\]\}\)]/.test(line[cursor.column])) {
680 CstyleBehaviour.recordAutoInsert(editor, session, "}");
681 return {
682 text: '{}',
683 selection: [1, 1]
684 };
685 } else {
686 CstyleBehaviour.recordMaybeInsert(editor, session, "{");
687 return {
688 text: '{',
689 selection: [1, 1]
690 };
691 }
692 }
693 } else if (text == '}') {
694 var rightChar = line.substring(cursor.column, cursor.column + 1);
695 if (rightChar == '}') {
696 var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
697 if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
698 CstyleBehaviour.popAutoInsertedClosing();
699 return {
700 text: '',
701 selection: [1, 1]
702 };
703 }
704 }
705 } else if (text == "\n" || text == "\r\n") {
706 var closing = "";
707 if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
708 closing = lang.stringRepeat("}", maybeInsertedBrackets);
709 CstyleBehaviour.clearMaybeInsertedClosing();
710 }
711 var rightChar = line.substring(cursor.column, cursor.column + 1);
712 if (rightChar == '}' || closing !== "") {
713 var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
714 if (!openBracePos)
715 return null;
716
717 var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
718 var next_indent = this.$getIndent(line);
719
720 return {
721 text: '\n' + indent + '\n' + next_indent + closing,
722 selection: [1, indent.length, 1, indent.length]
723 };
724 }
725 }
726 });
727
728 this.add("braces", "deletion", function (state, action, editor, session, range) {
729 var selected = session.doc.getTextRange(range);
730 if (!range.isMultiLine() && selected == '{') {
731 var line = session.doc.getLine(range.start.row);
732 var rightChar = line.substring(range.end.column, range.end.column + 1);
733 if (rightChar == '}') {
734 range.end.column++;
735 return range;
736 } else {
737 maybeInsertedBrackets--;
738 }
739 }
740 });
741
742 this.add("parens", "insertion", function (state, action, editor, session, text) {
743 if (text == '(') {
744 var selection = editor.getSelectionRange();
745 var selected = session.doc.getTextRange(selection);
746 if (selected !== "" && editor.getWrapBehavioursEnabled()) {
747 return {
748 text: '(' + selected + ')',
749 selection: false
750 };
751 } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
752 CstyleBehaviour.recordAutoInsert(editor, session, ")");
753 return {
754 text: '()',
755 selection: [1, 1]
756 };
757 }
758 } else if (text == ')') {
759 var cursor = editor.getCursorPosition();
760 var line = session.doc.getLine(cursor.row);
761 var rightChar = line.substring(cursor.column, cursor.column + 1);
762 if (rightChar == ')') {
763 var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
764 if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
765 CstyleBehaviour.popAutoInsertedClosing();
766 return {
767 text: '',
768 selection: [1, 1]
769 };
770 }
771 }
772 }
773 });
774
775 this.add("parens", "deletion", function (state, action, editor, session, range) {
776 var selected = session.doc.getTextRange(range);
777 if (!range.isMultiLine() && selected == '(') {
778 var line = session.doc.getLine(range.start.row);
779 var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
780 if (rightChar == ')') {
781 range.end.column++;
782 return range;
783 }
784 }
785 });
786
787 this.add("brackets", "insertion", function (state, action, editor, session, text) {
788 if (text == '[') {
789 var selection = editor.getSelectionRange();
790 var selected = session.doc.getTextRange(selection);
791 if (selected !== "" && editor.getWrapBehavioursEnabled()) {
792 return {
793 text: '[' + selected + ']',
794 selection: false
795 };
796 } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
797 CstyleBehaviour.recordAutoInsert(editor, session, "]");
798 return {
799 text: '[]',
800 selection: [1, 1]
801 };
802 }
803 } else if (text == ']') {
804 var cursor = editor.getCursorPosition();
805 var line = session.doc.getLine(cursor.row);
806 var rightChar = line.substring(cursor.column, cursor.column + 1);
807 if (rightChar == ']') {
808 var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
809 if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
810 CstyleBehaviour.popAutoInsertedClosing();
811 return {
812 text: '',
813 selection: [1, 1]
814 };
815 }
816 }
817 }
818 });
819
820 this.add("brackets", "deletion", function (state, action, editor, session, range) {
821 var selected = session.doc.getTextRange(range);
822 if (!range.isMultiLine() && selected == '[') {
823 var line = session.doc.getLine(range.start.row);
824 var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
825 if (rightChar == ']') {
826 range.end.column++;
827 return range;
828 }
829 }
830 });
831
832 this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
833 if (text == '"' || text == "'") {
834 var quote = text;
835 var selection = editor.getSelectionRange();
836 var selected = session.doc.getTextRange(selection);
837 if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
838 return {
839 text: quote + selected + quote,
840 selection: false
841 };
842 } else {
843 var cursor = editor.getCursorPosition();
844 var line = session.doc.getLine(cursor.row);
845 var leftChar = line.substring(cursor.column-1, cursor.column);
846 if (leftChar == '\\') {
847 return null;
848 }
849 var tokens = session.getTokens(selection.start.row);
850 var col = 0, token;
851 var quotepos = -1; // Track whether we're inside an open quote.
852
853 for (var x = 0; x < tokens.length; x++) {
854 token = tokens[x];
855 if (token.type == "string") {
856 quotepos = -1;
857 } else if (quotepos < 0) {
858 quotepos = token.value.indexOf(quote);
859 }
860 if ((token.value.length + col) > selection.start.column) {
861 break;
862 }
863 col += tokens[x].value.length;
864 }
865 if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
866 if (!CstyleBehaviour.isSaneInsertion(editor, session))
867 return;
868 return {
869 text: quote + quote,
870 selection: [1,1]
871 };
872 } else if (token && token.type === "string") {
873 var rightChar = line.substring(cursor.column, cursor.column + 1);
874 if (rightChar == quote) {
875 return {
876 text: '',
877 selection: [1, 1]
878 };
879 }
880 }
881 }
882 }
883 });
884
885 this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
886 var selected = session.doc.getTextRange(range);
887 if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
888 var line = session.doc.getLine(range.start.row);
889 var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
890 if (rightChar == '"') {
891 range.end.column++;
892 return range;
893 }
894 }
895 });
896
897 };
898
899 oop.inherits(CstyleBehaviour, Behaviour);
900
901 exports.CstyleBehaviour = CstyleBehaviour;
902 });
903
904 define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
905
906
907 var oop = require("../../lib/oop");
908 var Range = require("../../range").Range;
909 var BaseFoldMode = require("./fold_mode").FoldMode;
910
911 var FoldMode = exports.FoldMode = function() {};
912 oop.inherits(FoldMode, BaseFoldMode);
913
914 (function() {
915
916 this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
917 this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
918
919 this.getFoldWidgetRange = function(session, foldStyle, row) {
920 var line = session.getLine(row);
921 var match = line.match(this.foldingStartMarker);
922 if (match) {
923 var i = match.index;
924
925 if (match[1])
926 return this.openingBracketBlock(session, match[1], row, i);
927
928 return session.getCommentFoldRange(row, i + match[0].length, 1);
929 }
930
931 if (foldStyle !== "markbeginend")
932 return;
933
934 var match = line.match(this.foldingStopMarker);
935 if (match) {
936 var i = match.index + match[0].length;
937
938 if (match[1])
939 return this.closingBracketBlock(session, match[1], row, i);
940
941 return session.getCommentFoldRange(row, i, -1);
942 }
943 };
944
945 }).call(FoldMode.prototype);
946
947 });
948