/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/js/ace/mode-javascript.js

  • Committer: galaxyAbstractor
  • Date: 2013-04-10 15:49:32 UTC
  • mto: (19.1.5 lenasys)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: galaxyabstractor@gmail.com-20130410154932-4vizlzk0ar5gykvi
* Added an simple admin panel to the codeviewer-cmssy stuff
* Redesigned a bit like the mockups - still stuff to come
* Implemented the codeviewer + admin panel again using the Framework CodeIgniter instead 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    this.lineCommentStart = "//";
 
55
    this.blockComment = {start: "/*", end: "*/"};
 
56
 
 
57
    this.getNextLineIndent = function(state, line, tab) {
 
58
        var indent = this.$getIndent(line);
 
59
 
 
60
        var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
 
61
        var tokens = tokenizedLine.tokens;
 
62
        var endState = tokenizedLine.state;
 
63
 
 
64
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
 
65
            return indent;
 
66
        }
 
67
 
 
68
        if (state == "start" || state == "no_regex") {
 
69
            var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
 
70
            if (match) {
 
71
                indent += tab;
 
72
            }
 
73
        } else if (state == "doc-start") {
 
74
            if (endState == "start" || endState == "no_regex") {
 
75
                return "";
 
76
            }
 
77
            var match = line.match(/^\s*(\/?)\*/);
 
78
            if (match) {
 
79
                if (match[1]) {
 
80
                    indent += " ";
 
81
                }
 
82
                indent += "* ";
 
83
            }
 
84
        }
 
85
 
 
86
        return indent;
 
87
    };
 
88
 
 
89
    this.checkOutdent = function(state, line, input) {
 
90
        return this.$outdent.checkOutdent(line, input);
 
91
    };
 
92
 
 
93
    this.autoOutdent = function(state, doc, row) {
 
94
        this.$outdent.autoOutdent(doc, row);
 
95
    };
 
96
 
 
97
    this.createWorker = function(session) {
 
98
        var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
 
99
        worker.attachToDocument(session.getDocument());
 
100
 
 
101
        worker.on("jslint", function(results) {
 
102
            session.setAnnotations(results.data);
 
103
        });
 
104
 
 
105
        worker.on("terminate", function() {
 
106
            session.clearAnnotations();
 
107
        });
 
108
 
 
109
        return worker;
 
110
    };
 
111
 
 
112
}).call(Mode.prototype);
 
113
 
 
114
exports.Mode = Mode;
 
115
});
 
116
 
 
117
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) {
 
118
 
 
119
 
 
120
var oop = require("../lib/oop");
 
121
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
 
122
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
123
 
 
124
var JavaScriptHighlightRules = function() {
 
125
    var keywordMapper = this.createKeywordMapper({
 
126
        "variable.language":
 
127
            "Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|"  + // Constructors
 
128
            "Namespace|QName|XML|XMLList|"                                             + // E4X
 
129
            "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|"   +
 
130
            "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|"                    +
 
131
            "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|"   + // Errors
 
132
            "SyntaxError|TypeError|URIError|"                                          +
 
133
            "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
 
134
            "isNaN|parseFloat|parseInt|"                                               +
 
135
            "JSON|Math|"                                                               + // Other
 
136
            "this|arguments|prototype|window|document"                                 , // Pseudo
 
137
        "keyword":
 
138
            "const|yield|import|get|set|" +
 
139
            "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
 
140
            "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
 
141
            "__parent__|__count__|escape|unescape|with|__proto__|" +
 
142
            "class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
 
143
        "storage.type":
 
144
            "const|let|var|function",
 
145
        "constant.language":
 
146
            "null|Infinity|NaN|undefined",
 
147
        "support.function":
 
148
            "alert",
 
149
        "constant.language.boolean": "true|false"
 
150
    }, "identifier");
 
151
    var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
 
152
    var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
 
153
 
 
154
    var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
 
155
        "u[0-9a-fA-F]{4}|" + // unicode
 
156
        "[0-2][0-7]{0,2}|" + // oct
 
157
        "3[0-6][0-7]?|" + // oct
 
158
        "37[0-7]?|" + // oct
 
159
        "[4-7][0-7]?|" + //oct
 
160
        ".)";
 
161
 
 
162
    this.$rules = {
 
163
        "no_regex" : [
 
164
            {
 
165
                token : "comment",
 
166
                regex : /\/\/.*$/
 
167
            },
 
168
            DocCommentHighlightRules.getStartRule("doc-start"),
 
169
            {
 
170
                token : "comment", // multi line comment
 
171
                regex : /\/\*/,
 
172
                next : "comment"
 
173
            }, {
 
174
                token : "string",
 
175
                regex : "'(?=.)",
 
176
                next  : "qstring"
 
177
            }, {
 
178
                token : "string",
 
179
                regex : '"(?=.)',
 
180
                next  : "qqstring"
 
181
            }, {
 
182
                token : "constant.numeric", // hex
 
183
                regex : /0[xX][0-9a-fA-F]+\b/
 
184
            }, {
 
185
                token : "constant.numeric", // float
 
186
                regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
 
187
            }, {
 
188
                token : [
 
189
                    "storage.type", "punctuation.operator", "support.function",
 
190
                    "punctuation.operator", "entity.name.function", "text","keyword.operator"
 
191
                ],
 
192
                regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
 
193
                next: "function_arguments"
 
194
            }, {
 
195
                token : [
 
196
                    "storage.type", "punctuation.operator", "entity.name.function", "text",
 
197
                    "keyword.operator", "text", "storage.type", "text", "paren.lparen"
 
198
                ],
 
199
                regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
 
200
                next: "function_arguments"
 
201
            }, {
 
202
                token : [
 
203
                    "entity.name.function", "text", "keyword.operator", "text", "storage.type",
 
204
                    "text", "paren.lparen"
 
205
                ],
 
206
                regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
 
207
                next: "function_arguments"
 
208
            }, {
 
209
                token : [
 
210
                    "storage.type", "punctuation.operator", "entity.name.function", "text",
 
211
                    "keyword.operator", "text",
 
212
                    "storage.type", "text", "entity.name.function", "text", "paren.lparen"
 
213
                ],
 
214
                regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
 
215
                next: "function_arguments"
 
216
            }, {
 
217
                token : [
 
218
                    "storage.type", "text", "entity.name.function", "text", "paren.lparen"
 
219
                ],
 
220
                regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
 
221
                next: "function_arguments"
 
222
            }, {
 
223
                token : [
 
224
                    "entity.name.function", "text", "punctuation.operator",
 
225
                    "text", "storage.type", "text", "paren.lparen"
 
226
                ],
 
227
                regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
 
228
                next: "function_arguments"
 
229
            }, {
 
230
                token : [
 
231
                    "text", "text", "storage.type", "text", "paren.lparen"
 
232
                ],
 
233
                regex : "(:)(\\s*)(function)(\\s*)(\\()",
 
234
                next: "function_arguments"
 
235
            }, {
 
236
                token : "keyword",
 
237
                regex : "(?:" + kwBeforeRe + ")\\b",
 
238
                next : "start"
 
239
            }, {
 
240
                token : ["punctuation.operator", "support.function"],
 
241
                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(?=\()/
 
242
            }, {
 
243
                token : ["punctuation.operator", "support.function.dom"],
 
244
                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(?=\()/
 
245
            }, {
 
246
                token : ["punctuation.operator", "support.constant"],
 
247
                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/
 
248
            }, {
 
249
                token : ["storage.type", "punctuation.operator", "support.function.firebug"],
 
250
                regex : /(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/
 
251
            }, {
 
252
                token : keywordMapper,
 
253
                regex : identifierRe
 
254
            }, {
 
255
                token : "keyword.operator",
 
256
                regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
 
257
                next  : "start"
 
258
            }, {
 
259
                token : "punctuation.operator",
 
260
                regex : /\?|\:|\,|\;|\./,
 
261
                next  : "start"
 
262
            }, {
 
263
                token : "paren.lparen",
 
264
                regex : /[\[({]/,
 
265
                next  : "start"
 
266
            }, {
 
267
                token : "paren.rparen",
 
268
                regex : /[\])}]/
 
269
            }, {
 
270
                token : "keyword.operator",
 
271
                regex : /\/=?/,
 
272
                next  : "start"
 
273
            }, {
 
274
                token: "comment",
 
275
                regex: /^#!.*$/
 
276
            }
 
277
        ],
 
278
        "start": [
 
279
            DocCommentHighlightRules.getStartRule("doc-start"),
 
280
            {
 
281
                token : "comment", // multi line comment
 
282
                regex : "\\/\\*",
 
283
                next : "comment_regex_allowed"
 
284
            }, {
 
285
                token : "comment",
 
286
                regex : "\\/\\/.*$",
 
287
                next : "start"
 
288
            }, {
 
289
                token: "string.regexp",
 
290
                regex: "\\/",
 
291
                next: "regex",
 
292
            }, {
 
293
                token : "text",
 
294
                regex : "\\s+|^$",
 
295
                next : "start"
 
296
            }, {
 
297
                token: "empty",
 
298
                regex: "",
 
299
                next: "no_regex"
 
300
            }
 
301
        ],
 
302
        "regex": [
 
303
            {
 
304
                token: "regexp.keyword.operator",
 
305
                regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
 
306
            }, {
 
307
                token: "string.regexp",
 
308
                regex: "/\\w*",
 
309
                next: "no_regex",
 
310
            }, {
 
311
                token : "invalid",
 
312
                regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
 
313
            }, {
 
314
                token : "constant.language.escape",
 
315
                regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?]/
 
316
            }, {
 
317
                token : "constant.language.delimiter",
 
318
                regex: /\|/
 
319
            }, {
 
320
                token: "constant.language.escape",
 
321
                regex: /\[\^?/,
 
322
                next: "regex_character_class",
 
323
            }, {
 
324
                token: "empty",
 
325
                regex: "$",
 
326
                next: "no_regex"
 
327
            }, {
 
328
                defaultToken: "string.regexp"
 
329
            }
 
330
        ],
 
331
        "regex_character_class": [
 
332
            {
 
333
                token: "regexp.keyword.operator",
 
334
                regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
 
335
            }, {
 
336
                token: "constant.language.escape",
 
337
                regex: "]",
 
338
                next: "regex",
 
339
            }, {
 
340
                token: "constant.language.escape",
 
341
                regex: "-"
 
342
            }, {
 
343
                token: "empty",
 
344
                regex: "$",
 
345
                next: "no_regex"
 
346
            }, {
 
347
                defaultToken: "string.regexp.charachterclass"
 
348
            }
 
349
        ],
 
350
        "function_arguments": [
 
351
            {
 
352
                token: "variable.parameter",
 
353
                regex: identifierRe
 
354
            }, {
 
355
                token: "punctuation.operator",
 
356
                regex: "[, ]+",
 
357
            }, {
 
358
                token: "punctuation.operator",
 
359
                regex: "$",
 
360
            }, {
 
361
                token: "empty",
 
362
                regex: "",
 
363
                next: "no_regex"
 
364
            }
 
365
        ],
 
366
        "comment_regex_allowed" : [
 
367
            {token : "comment", regex : "\\*\\/", next : "start"},
 
368
            {defaultToken : "comment"}
 
369
        ],
 
370
        "comment" : [
 
371
            {token : "comment", regex : "\\*\\/", next : "no_regex"},
 
372
            {defaultToken : "comment"}
 
373
        ],
 
374
        "qqstring" : [
 
375
            {
 
376
                token : "constant.language.escape",
 
377
                regex : escapedRe
 
378
            }, {
 
379
                token : "string",
 
380
                regex : "\\\\$",
 
381
                next  : "qqstring",
 
382
            }, {
 
383
                token : "string",
 
384
                regex : '"|$',
 
385
                next  : "no_regex",
 
386
            }, {
 
387
                defaultToken: "string"
 
388
            }
 
389
        ],
 
390
        "qstring" : [
 
391
            {
 
392
                token : "constant.language.escape",
 
393
                regex : escapedRe
 
394
            }, {
 
395
                token : "string",
 
396
                regex : "\\\\$",
 
397
                next  : "qstring",
 
398
            }, {
 
399
                token : "string",
 
400
                regex : "'|$",
 
401
                next  : "no_regex",
 
402
            }, {
 
403
                defaultToken: "string"
 
404
            }
 
405
        ]
 
406
    };
 
407
 
 
408
    this.embedRules(DocCommentHighlightRules, "doc-",
 
409
        [ DocCommentHighlightRules.getEndRule("no_regex") ]);
 
410
};
 
411
 
 
412
oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
 
413
 
 
414
exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
 
415
});
 
416
 
 
417
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
418
 
 
419
 
 
420
var oop = require("../lib/oop");
 
421
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
422
 
 
423
var DocCommentHighlightRules = function() {
 
424
 
 
425
    this.$rules = {
 
426
        "start" : [ {
 
427
            token : "comment.doc.tag",
 
428
            regex : "@[\\w\\d_]+" // TODO: fix email addresses
 
429
        }, {
 
430
            token : "comment.doc.tag",
 
431
            regex : "\\bTODO\\b"
 
432
        }, {
 
433
            defaultToken : "comment.doc"
 
434
        }]
 
435
    };
 
436
};
 
437
 
 
438
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
 
439
 
 
440
DocCommentHighlightRules.getStartRule = function(start) {
 
441
    return {
 
442
        token : "comment.doc", // doc comment
 
443
        regex : "\\/\\*(?=\\*)",
 
444
        next  : start
 
445
    };
 
446
};
 
447
 
 
448
DocCommentHighlightRules.getEndRule = function (start) {
 
449
    return {
 
450
        token : "comment.doc", // closing comment
 
451
        regex : "\\*\\/",
 
452
        next  : start
 
453
    };
 
454
};
 
455
 
 
456
 
 
457
exports.DocCommentHighlightRules = DocCommentHighlightRules;
 
458
 
 
459
});
 
460
 
 
461
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
 
462
 
 
463
 
 
464
var Range = require("../range").Range;
 
465
 
 
466
var MatchingBraceOutdent = function() {};
 
467
 
 
468
(function() {
 
469
 
 
470
    this.checkOutdent = function(line, input) {
 
471
        if (! /^\s+$/.test(line))
 
472
            return false;
 
473
 
 
474
        return /^\s*\}/.test(input);
 
475
    };
 
476
 
 
477
    this.autoOutdent = function(doc, row) {
 
478
        var line = doc.getLine(row);
 
479
        var match = line.match(/^(\s*\})/);
 
480
 
 
481
        if (!match) return 0;
 
482
 
 
483
        var column = match[1].length;
 
484
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
 
485
 
 
486
        if (!openBracePos || openBracePos.row == row) return 0;
 
487
 
 
488
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
 
489
        doc.replace(new Range(row, 0, row, column-1), indent);
 
490
    };
 
491
 
 
492
    this.$getIndent = function(line) {
 
493
        return line.match(/^\s*/)[0];
 
494
    };
 
495
 
 
496
}).call(MatchingBraceOutdent.prototype);
 
497
 
 
498
exports.MatchingBraceOutdent = MatchingBraceOutdent;
 
499
});
 
500
 
 
501
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
 
502
 
 
503
 
 
504
var oop = require("../../lib/oop");
 
505
var Behaviour = require("../behaviour").Behaviour;
 
506
var TokenIterator = require("../../token_iterator").TokenIterator;
 
507
var lang = require("../../lib/lang");
 
508
 
 
509
var SAFE_INSERT_IN_TOKENS =
 
510
    ["text", "paren.rparen", "punctuation.operator"];
 
511
var SAFE_INSERT_BEFORE_TOKENS =
 
512
    ["text", "paren.rparen", "punctuation.operator", "comment"];
 
513
 
 
514
 
 
515
var autoInsertedBrackets = 0;
 
516
var autoInsertedRow = -1;
 
517
var autoInsertedLineEnd = "";
 
518
var maybeInsertedBrackets = 0;
 
519
var maybeInsertedRow = -1;
 
520
var maybeInsertedLineStart = "";
 
521
var maybeInsertedLineEnd = "";
 
522
 
 
523
var CstyleBehaviour = function () {
 
524
    
 
525
    CstyleBehaviour.isSaneInsertion = function(editor, session) {
 
526
        var cursor = editor.getCursorPosition();
 
527
        var iterator = new TokenIterator(session, cursor.row, cursor.column);
 
528
        if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
 
529
            var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
 
530
            if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
 
531
                return false;
 
532
        }
 
533
        iterator.stepForward();
 
534
        return iterator.getCurrentTokenRow() !== cursor.row ||
 
535
            this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
 
536
    };
 
537
    
 
538
    CstyleBehaviour.$matchTokenType = function(token, types) {
 
539
        return types.indexOf(token.type || token) > -1;
 
540
    };
 
541
    
 
542
    CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
 
543
        var cursor = editor.getCursorPosition();
 
544
        var line = session.doc.getLine(cursor.row);
 
545
        if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
 
546
            autoInsertedBrackets = 0;
 
547
        autoInsertedRow = cursor.row;
 
548
        autoInsertedLineEnd = bracket + line.substr(cursor.column);
 
549
        autoInsertedBrackets++;
 
550
    };
 
551
    
 
552
    CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
 
553
        var cursor = editor.getCursorPosition();
 
554
        var line = session.doc.getLine(cursor.row);
 
555
        if (!this.isMaybeInsertedClosing(cursor, line))
 
556
            maybeInsertedBrackets = 0;
 
557
        maybeInsertedRow = cursor.row;
 
558
        maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
 
559
        maybeInsertedLineEnd = line.substr(cursor.column);
 
560
        maybeInsertedBrackets++;
 
561
    };
 
562
    
 
563
    CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
 
564
        return autoInsertedBrackets > 0 &&
 
565
            cursor.row === autoInsertedRow &&
 
566
            bracket === autoInsertedLineEnd[0] &&
 
567
            line.substr(cursor.column) === autoInsertedLineEnd;
 
568
    };
 
569
    
 
570
    CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
 
571
        return maybeInsertedBrackets > 0 &&
 
572
            cursor.row === maybeInsertedRow &&
 
573
            line.substr(cursor.column) === maybeInsertedLineEnd &&
 
574
            line.substr(0, cursor.column) == maybeInsertedLineStart;
 
575
    };
 
576
    
 
577
    CstyleBehaviour.popAutoInsertedClosing = function() {
 
578
        autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
 
579
        autoInsertedBrackets--;
 
580
    };
 
581
    
 
582
    CstyleBehaviour.clearMaybeInsertedClosing = function() {
 
583
        maybeInsertedBrackets = 0;
 
584
        maybeInsertedRow = -1;
 
585
    };
 
586
 
 
587
    this.add("braces", "insertion", function (state, action, editor, session, text) {
 
588
        var cursor = editor.getCursorPosition();
 
589
        var line = session.doc.getLine(cursor.row);
 
590
        if (text == '{') {
 
591
            var selection = editor.getSelectionRange();
 
592
            var selected = session.doc.getTextRange(selection);
 
593
            if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
 
594
                return {
 
595
                    text: '{' + selected + '}',
 
596
                    selection: false
 
597
                };
 
598
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
599
                if (/[\]\}\)]/.test(line[cursor.column])) {
 
600
                    CstyleBehaviour.recordAutoInsert(editor, session, "}");
 
601
                    return {
 
602
                        text: '{}',
 
603
                        selection: [1, 1]
 
604
                    };
 
605
                } else {
 
606
                    CstyleBehaviour.recordMaybeInsert(editor, session, "{");
 
607
                    return {
 
608
                        text: '{',
 
609
                        selection: [1, 1]
 
610
                    };
 
611
                }
 
612
            }
 
613
        } else if (text == '}') {
 
614
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
615
            if (rightChar == '}') {
 
616
                var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
 
617
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
618
                    CstyleBehaviour.popAutoInsertedClosing();
 
619
                    return {
 
620
                        text: '',
 
621
                        selection: [1, 1]
 
622
                    };
 
623
                }
 
624
            }
 
625
        } else if (text == "\n" || text == "\r\n") {
 
626
            var closing = "";
 
627
            if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
 
628
                closing = lang.stringRepeat("}", maybeInsertedBrackets);
 
629
                CstyleBehaviour.clearMaybeInsertedClosing();
 
630
            }
 
631
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
632
            if (rightChar == '}' || closing !== "") {
 
633
                var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
 
634
                if (!openBracePos)
 
635
                     return null;
 
636
 
 
637
                var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
 
638
                var next_indent = this.$getIndent(line);
 
639
 
 
640
                return {
 
641
                    text: '\n' + indent + '\n' + next_indent + closing,
 
642
                    selection: [1, indent.length, 1, indent.length]
 
643
                };
 
644
            }
 
645
        }
 
646
    });
 
647
 
 
648
    this.add("braces", "deletion", function (state, action, editor, session, range) {
 
649
        var selected = session.doc.getTextRange(range);
 
650
        if (!range.isMultiLine() && selected == '{') {
 
651
            var line = session.doc.getLine(range.start.row);
 
652
            var rightChar = line.substring(range.end.column, range.end.column + 1);
 
653
            if (rightChar == '}') {
 
654
                range.end.column++;
 
655
                return range;
 
656
            } else {
 
657
                maybeInsertedBrackets--;
 
658
            }
 
659
        }
 
660
    });
 
661
 
 
662
    this.add("parens", "insertion", function (state, action, editor, session, text) {
 
663
        if (text == '(') {
 
664
            var selection = editor.getSelectionRange();
 
665
            var selected = session.doc.getTextRange(selection);
 
666
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
 
667
                return {
 
668
                    text: '(' + selected + ')',
 
669
                    selection: false
 
670
                };
 
671
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
672
                CstyleBehaviour.recordAutoInsert(editor, session, ")");
 
673
                return {
 
674
                    text: '()',
 
675
                    selection: [1, 1]
 
676
                };
 
677
            }
 
678
        } else if (text == ')') {
 
679
            var cursor = editor.getCursorPosition();
 
680
            var line = session.doc.getLine(cursor.row);
 
681
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
682
            if (rightChar == ')') {
 
683
                var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
 
684
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
685
                    CstyleBehaviour.popAutoInsertedClosing();
 
686
                    return {
 
687
                        text: '',
 
688
                        selection: [1, 1]
 
689
                    };
 
690
                }
 
691
            }
 
692
        }
 
693
    });
 
694
 
 
695
    this.add("parens", "deletion", function (state, action, editor, session, range) {
 
696
        var selected = session.doc.getTextRange(range);
 
697
        if (!range.isMultiLine() && selected == '(') {
 
698
            var line = session.doc.getLine(range.start.row);
 
699
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
700
            if (rightChar == ')') {
 
701
                range.end.column++;
 
702
                return range;
 
703
            }
 
704
        }
 
705
    });
 
706
 
 
707
    this.add("brackets", "insertion", function (state, action, editor, session, text) {
 
708
        if (text == '[') {
 
709
            var selection = editor.getSelectionRange();
 
710
            var selected = session.doc.getTextRange(selection);
 
711
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
 
712
                return {
 
713
                    text: '[' + selected + ']',
 
714
                    selection: false
 
715
                };
 
716
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
717
                CstyleBehaviour.recordAutoInsert(editor, session, "]");
 
718
                return {
 
719
                    text: '[]',
 
720
                    selection: [1, 1]
 
721
                };
 
722
            }
 
723
        } else if (text == ']') {
 
724
            var cursor = editor.getCursorPosition();
 
725
            var line = session.doc.getLine(cursor.row);
 
726
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
727
            if (rightChar == ']') {
 
728
                var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
 
729
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
730
                    CstyleBehaviour.popAutoInsertedClosing();
 
731
                    return {
 
732
                        text: '',
 
733
                        selection: [1, 1]
 
734
                    };
 
735
                }
 
736
            }
 
737
        }
 
738
    });
 
739
 
 
740
    this.add("brackets", "deletion", function (state, action, editor, session, range) {
 
741
        var selected = session.doc.getTextRange(range);
 
742
        if (!range.isMultiLine() && selected == '[') {
 
743
            var line = session.doc.getLine(range.start.row);
 
744
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
745
            if (rightChar == ']') {
 
746
                range.end.column++;
 
747
                return range;
 
748
            }
 
749
        }
 
750
    });
 
751
 
 
752
    this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
 
753
        if (text == '"' || text == "'") {
 
754
            var quote = text;
 
755
            var selection = editor.getSelectionRange();
 
756
            var selected = session.doc.getTextRange(selection);
 
757
            if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
 
758
                return {
 
759
                    text: quote + selected + quote,
 
760
                    selection: false
 
761
                };
 
762
            } else {
 
763
                var cursor = editor.getCursorPosition();
 
764
                var line = session.doc.getLine(cursor.row);
 
765
                var leftChar = line.substring(cursor.column-1, cursor.column);
 
766
                if (leftChar == '\\') {
 
767
                    return null;
 
768
                }
 
769
                var tokens = session.getTokens(selection.start.row);
 
770
                var col = 0, token;
 
771
                var quotepos = -1; // Track whether we're inside an open quote.
 
772
 
 
773
                for (var x = 0; x < tokens.length; x++) {
 
774
                    token = tokens[x];
 
775
                    if (token.type == "string") {
 
776
                      quotepos = -1;
 
777
                    } else if (quotepos < 0) {
 
778
                      quotepos = token.value.indexOf(quote);
 
779
                    }
 
780
                    if ((token.value.length + col) > selection.start.column) {
 
781
                        break;
 
782
                    }
 
783
                    col += tokens[x].value.length;
 
784
                }
 
785
                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)))) {
 
786
                    if (!CstyleBehaviour.isSaneInsertion(editor, session))
 
787
                        return;
 
788
                    return {
 
789
                        text: quote + quote,
 
790
                        selection: [1,1]
 
791
                    };
 
792
                } else if (token && token.type === "string") {
 
793
                    var rightChar = line.substring(cursor.column, cursor.column + 1);
 
794
                    if (rightChar == quote) {
 
795
                        return {
 
796
                            text: '',
 
797
                            selection: [1, 1]
 
798
                        };
 
799
                    }
 
800
                }
 
801
            }
 
802
        }
 
803
    });
 
804
 
 
805
    this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
 
806
        var selected = session.doc.getTextRange(range);
 
807
        if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
 
808
            var line = session.doc.getLine(range.start.row);
 
809
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
810
            if (rightChar == selected) {
 
811
                range.end.column++;
 
812
                return range;
 
813
            }
 
814
        }
 
815
    });
 
816
 
 
817
};
 
818
 
 
819
oop.inherits(CstyleBehaviour, Behaviour);
 
820
 
 
821
exports.CstyleBehaviour = CstyleBehaviour;
 
822
});
 
823
 
 
824
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
 
825
 
 
826
 
 
827
var oop = require("../../lib/oop");
 
828
var Range = require("../../range").Range;
 
829
var BaseFoldMode = require("./fold_mode").FoldMode;
 
830
 
 
831
var FoldMode = exports.FoldMode = function(commentRegex) {
 
832
    if (commentRegex) {
 
833
        this.foldingStartMarker = new RegExp(
 
834
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
 
835
        );
 
836
        this.foldingStopMarker = new RegExp(
 
837
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
 
838
        );
 
839
    }
 
840
};
 
841
oop.inherits(FoldMode, BaseFoldMode);
 
842
 
 
843
(function() {
 
844
 
 
845
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
 
846
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
 
847
 
 
848
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
849
        var line = session.getLine(row);
 
850
        var match = line.match(this.foldingStartMarker);
 
851
        if (match) {
 
852
            var i = match.index;
 
853
 
 
854
            if (match[1])
 
855
                return this.openingBracketBlock(session, match[1], row, i);
 
856
 
 
857
            return session.getCommentFoldRange(row, i + match[0].length, 1);
 
858
        }
 
859
 
 
860
        if (foldStyle !== "markbeginend")
 
861
            return;
 
862
 
 
863
        var match = line.match(this.foldingStopMarker);
 
864
        if (match) {
 
865
            var i = match.index + match[0].length;
 
866
 
 
867
            if (match[1])
 
868
                return this.closingBracketBlock(session, match[1], row, i);
 
869
 
 
870
            return session.getCommentFoldRange(row, i, -1);
 
871
        }
 
872
    };
 
873
 
 
874
}).call(FoldMode.prototype);
 
875
 
 
876
});