/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-coffee.js

  • Committer: galaxyAbstractor
  • Date: 2013-04-10 15:58:59 UTC
  • mfrom: (20.1.1 lenasys)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: galaxyabstractor@gmail.com-20130410155859-cih60kaz5es8savt
CodeIgniter implementation of basic CMS system

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/coffee', ['require', 'exports', 'module' , 'ace/tokenizer', 'ace/mode/coffee_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/folding/coffee', 'ace/range', 'ace/mode/text', 'ace/worker/worker_client', 'ace/lib/oop'], function(require, exports, module) {
 
32
 
 
33
 
 
34
var Tokenizer = require("../tokenizer").Tokenizer;
 
35
var Rules = require("./coffee_highlight_rules").CoffeeHighlightRules;
 
36
var Outdent = require("./matching_brace_outdent").MatchingBraceOutdent;
 
37
var FoldMode = require("./folding/coffee").FoldMode;
 
38
var Range = require("../range").Range;
 
39
var TextMode = require("./text").Mode;
 
40
var WorkerClient = require("../worker/worker_client").WorkerClient;
 
41
var oop = require("../lib/oop");
 
42
 
 
43
function Mode() {
 
44
    this.$tokenizer = new Tokenizer(new Rules().getRules());
 
45
    this.$outdent = new Outdent();
 
46
    this.foldingRules = new FoldMode();
 
47
}
 
48
 
 
49
oop.inherits(Mode, TextMode);
 
50
 
 
51
(function() {
 
52
    
 
53
    var indenter = /(?:[({[=:]|[-=]>|\b(?:else|switch|try|catch(?:\s*[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)?|finally))\s*$/;
 
54
    var commentLine = /^(\s*)#/;
 
55
    var hereComment = /^\s*###(?!#)/;
 
56
    var indentation = /^\s*/;
 
57
    
 
58
    this.getNextLineIndent = function(state, line, tab) {
 
59
        var indent = this.$getIndent(line);
 
60
        var tokens = this.$tokenizer.getLineTokens(line, state).tokens;
 
61
    
 
62
        if (!(tokens.length && tokens[tokens.length - 1].type === 'comment') &&
 
63
            state === 'start' && indenter.test(line))
 
64
            indent += tab;
 
65
        return indent;
 
66
    };
 
67
    
 
68
    this.toggleCommentLines = function(state, doc, startRow, endRow){
 
69
        console.log("toggle");
 
70
        var range = new Range(0, 0, 0, 0);
 
71
        for (var i = startRow; i <= endRow; ++i) {
 
72
            var line = doc.getLine(i);
 
73
            if (hereComment.test(line))
 
74
                continue;
 
75
                
 
76
            if (commentLine.test(line))
 
77
                line = line.replace(commentLine, '$1');
 
78
            else
 
79
                line = line.replace(indentation, '$&#');
 
80
    
 
81
            range.end.row = range.start.row = i;
 
82
            range.end.column = line.length + 1;
 
83
            doc.replace(range, line);
 
84
        }
 
85
    };
 
86
    
 
87
    this.checkOutdent = function(state, line, input) {
 
88
        return this.$outdent.checkOutdent(line, input);
 
89
    };
 
90
    
 
91
    this.autoOutdent = function(state, doc, row) {
 
92
        this.$outdent.autoOutdent(doc, row);
 
93
    };
 
94
    
 
95
    this.createWorker = function(session) {
 
96
        var worker = new WorkerClient(["ace"], "ace/mode/coffee_worker", "Worker");
 
97
        worker.attachToDocument(session.getDocument());
 
98
        
 
99
        worker.on("error", function(e) {
 
100
            session.setAnnotations([e.data]);
 
101
        });
 
102
        
 
103
        worker.on("ok", function(e) {
 
104
            session.clearAnnotations();
 
105
        });
 
106
        
 
107
        return worker;
 
108
    };
 
109
 
 
110
}).call(Mode.prototype);
 
111
 
 
112
exports.Mode = Mode;
 
113
 
 
114
});
 
115
 
 
116
define('ace/mode/coffee_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
117
 
 
118
 
 
119
    var oop = require("../lib/oop");
 
120
    var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
121
 
 
122
    oop.inherits(CoffeeHighlightRules, TextHighlightRules);
 
123
 
 
124
    function CoffeeHighlightRules() {
 
125
        var identifier = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
 
126
 
 
127
        var keywords = (
 
128
            "this|throw|then|try|typeof|super|switch|return|break|by|continue|" +
 
129
            "catch|class|in|instanceof|is|isnt|if|else|extends|for|forown|" +
 
130
            "finally|function|while|when|new|no|not|delete|debugger|do|loop|of|off|" +
 
131
            "or|on|unless|until|and|yes"
 
132
        );
 
133
 
 
134
        var langConstant = (
 
135
            "true|false|null|undefined|NaN|Infinity"
 
136
        );
 
137
 
 
138
        var illegal = (
 
139
            "case|const|default|function|var|void|with|enum|export|implements|" +
 
140
            "interface|let|package|private|protected|public|static|yield|" +
 
141
            "__hasProp|slice|bind|indexOf"
 
142
        );
 
143
 
 
144
        var supportClass = (
 
145
            "Array|Boolean|Date|Function|Number|Object|RegExp|ReferenceError|String|" +
 
146
            "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" +
 
147
            "SyntaxError|TypeError|URIError|"  +
 
148
            "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
 
149
            "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray"
 
150
        );
 
151
 
 
152
        var supportFunction = (
 
153
            "Math|JSON|isNaN|isFinite|parseInt|parseFloat|encodeURI|" +
 
154
            "encodeURIComponent|decodeURI|decodeURIComponent|String|"
 
155
        );
 
156
 
 
157
        var variableLanguage = (
 
158
            "window|arguments|prototype|document"
 
159
        );
 
160
 
 
161
        var keywordMapper = this.createKeywordMapper({
 
162
            "keyword": keywords,
 
163
            "constant.language": langConstant,
 
164
            "invalid.illegal": illegal,
 
165
            "language.support.class": supportClass,
 
166
            "language.support.function": supportFunction,
 
167
            "variable.language": variableLanguage
 
168
        }, "identifier");
 
169
 
 
170
        var functionRule = {
 
171
            token: ["paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type"],
 
172
            regex: /(?:(\()((?:"[^")]*?"|'[^')]*?'|\/[^\/)]*?\/|[^()\"'\/])*?)(\))(\s*))?([\-=]>)/.source
 
173
        };
 
174
 
 
175
        var stringEscape = /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)/;
 
176
 
 
177
        this.$rules = {
 
178
            start : [
 
179
                {
 
180
                    token : "constant.numeric",
 
181
                    regex : "(?:0x[\\da-fA-F]+|(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:[eE][+-]?\\d+)?)"
 
182
                }, {
 
183
                    stateName: "qdoc",
 
184
                    token : "string", regex : "'''", next : [
 
185
                        {token : "string", regex : "'''", next : "start"},
 
186
                        {token : "constant.language.escape", regex : stringEscape},
 
187
                        {defaultToken: "string"}
 
188
                    ]
 
189
                }, {
 
190
                    stateName: "qqdoc",
 
191
                    token : "string",
 
192
                    regex : '"""',
 
193
                    next : [
 
194
                        {token : "string", regex : '"""', next : "start"},
 
195
                        {token : "constant.language.escape", regex : stringEscape},
 
196
                        {defaultToken: "string"}
 
197
                    ]
 
198
                }, {
 
199
                    stateName: "qstring",
 
200
                    token : "string", regex : "'", next : [
 
201
                        {token : "string", regex : "'", next : "start"},
 
202
                        {token : "constant.language.escape", regex : stringEscape},
 
203
                        {defaultToken: "string"}
 
204
                    ]
 
205
                }, {
 
206
                    stateName: "qqstring",
 
207
                    token : "string.start", regex : '"', next : [
 
208
                        {token : "string.end", regex : '"', next : "start"},
 
209
                        {token : "constant.language.escape", regex : stringEscape},
 
210
                        {defaultToken: "string"}
 
211
                    ]
 
212
                }, {
 
213
                    stateName: "js",
 
214
                    token : "string", regex : "`", next : [
 
215
                        {token : "string", regex : "`", next : "start"},
 
216
                        {token : "constant.language.escape", regex : stringEscape},
 
217
                        {defaultToken: "string"}
 
218
                    ]
 
219
                }, {
 
220
                    token : "string.regex",
 
221
                    regex : "///",
 
222
                    next : "heregex"
 
223
                }, {
 
224
                    token : "string.regex",
 
225
                    regex : /(?:\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)(?:[imgy]{0,4})(?!\w)/
 
226
                }, {
 
227
                    token : "comment",
 
228
                    regex : "###(?!#)",
 
229
                    next : "comment"
 
230
                }, {
 
231
                    token : "comment",
 
232
                    regex : "#.*"
 
233
                }, {
 
234
                    token : ["punctuation.operator", "text", "identifier"],
 
235
                    regex : "(\\.)(\\s*)(" + illegal + ")"
 
236
                }, {
 
237
                    token : "punctuation.operator",
 
238
                    regex : "\\."
 
239
                }, {
 
240
                    token : ["keyword", "text", "language.support.class",
 
241
                     "text", "keyword", "text", "language.support.class"],
 
242
                    regex : "(class)(\\s+)(" + identifier + ")(?:(\\s+)(extends)(\\s+)(" + identifier + "))?"
 
243
                }, {
 
244
                    token : ["entity.name.function", "text", "keyword.operator", "text"].concat(functionRule.token),
 
245
                    regex : "(" + identifier + ")(\\s*)([=:])(\\s*)" + functionRule.regex
 
246
                }, 
 
247
                functionRule, 
 
248
                {
 
249
                    token : "variable",
 
250
                    regex : "@(?:" + identifier + ")?"
 
251
                }, {
 
252
                    token: keywordMapper,
 
253
                    regex : identifier
 
254
                }, {
 
255
                    token : "punctuation.operator",
 
256
                    regex : "\\,|\\."
 
257
                }, {
 
258
                    token : "storage.type",
 
259
                    regex : "[\\-=]>"
 
260
                }, {
 
261
                    token : "keyword.operator",
 
262
                    regex : "(?:[-+*/%<>&|^!?=]=|>>>=?|\\-\\-|\\+\\+|::|&&=|\\|\\|=|<<=|>>=|\\?\\.|\\.{2,3}|[!*+-=><])"
 
263
                }, {
 
264
                    token : "paren.lparen",
 
265
                    regex : "[({[]"
 
266
                }, {
 
267
                    token : "paren.rparen",
 
268
                    regex : "[\\]})]"
 
269
                }, {
 
270
                    token : "text",
 
271
                    regex : "\\s+"
 
272
                }],
 
273
 
 
274
 
 
275
            heregex : [{
 
276
                token : "string.regex",
 
277
                regex : '.*?///[imgy]{0,4}',
 
278
                next : "start"
 
279
            }, {
 
280
                token : "comment.regex",
 
281
                regex : "\\s+(?:#.*)?"
 
282
            }, {
 
283
                token : "string.regex",
 
284
                regex : "\\S+"
 
285
            }],
 
286
 
 
287
            comment : [{
 
288
                token : "comment",
 
289
                regex : '###',
 
290
                next : "start"
 
291
            }, {
 
292
                defaultToken : "comment",
 
293
            }]
 
294
        };
 
295
        this.normalizeRules();
 
296
    }
 
297
 
 
298
    exports.CoffeeHighlightRules = CoffeeHighlightRules;
 
299
});
 
300
 
 
301
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
 
302
 
 
303
 
 
304
var Range = require("../range").Range;
 
305
 
 
306
var MatchingBraceOutdent = function() {};
 
307
 
 
308
(function() {
 
309
 
 
310
    this.checkOutdent = function(line, input) {
 
311
        if (! /^\s+$/.test(line))
 
312
            return false;
 
313
 
 
314
        return /^\s*\}/.test(input);
 
315
    };
 
316
 
 
317
    this.autoOutdent = function(doc, row) {
 
318
        var line = doc.getLine(row);
 
319
        var match = line.match(/^(\s*\})/);
 
320
 
 
321
        if (!match) return 0;
 
322
 
 
323
        var column = match[1].length;
 
324
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
 
325
 
 
326
        if (!openBracePos || openBracePos.row == row) return 0;
 
327
 
 
328
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
 
329
        doc.replace(new Range(row, 0, row, column-1), indent);
 
330
    };
 
331
 
 
332
    this.$getIndent = function(line) {
 
333
        return line.match(/^\s*/)[0];
 
334
    };
 
335
 
 
336
}).call(MatchingBraceOutdent.prototype);
 
337
 
 
338
exports.MatchingBraceOutdent = MatchingBraceOutdent;
 
339
});
 
340
 
 
341
define('ace/mode/folding/coffee', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
 
342
 
 
343
 
 
344
var oop = require("../../lib/oop");
 
345
var BaseFoldMode = require("./fold_mode").FoldMode;
 
346
var Range = require("../../range").Range;
 
347
 
 
348
var FoldMode = exports.FoldMode = function() {};
 
349
oop.inherits(FoldMode, BaseFoldMode);
 
350
 
 
351
(function() {
 
352
 
 
353
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
354
        var range = this.indentationBlock(session, row);
 
355
        if (range)
 
356
            return range;
 
357
 
 
358
        var re = /\S/;
 
359
        var line = session.getLine(row);
 
360
        var startLevel = line.search(re);
 
361
        if (startLevel == -1 || line[startLevel] != "#")
 
362
            return;
 
363
 
 
364
        var startColumn = line.length;
 
365
        var maxRow = session.getLength();
 
366
        var startRow = row;
 
367
        var endRow = row;
 
368
 
 
369
        while (++row < maxRow) {
 
370
            line = session.getLine(row);
 
371
            var level = line.search(re);
 
372
 
 
373
            if (level == -1)
 
374
                continue;
 
375
 
 
376
            if (line[level] != "#")
 
377
                break;
 
378
 
 
379
            endRow = row;
 
380
        }
 
381
 
 
382
        if (endRow > startRow) {
 
383
            var endColumn = session.getLine(endRow).length;
 
384
            return new Range(startRow, startColumn, endRow, endColumn);
 
385
        }
 
386
    };
 
387
    this.getFoldWidget = function(session, foldStyle, row) {
 
388
        var line = session.getLine(row);
 
389
        var indent = line.search(/\S/);
 
390
        var next = session.getLine(row + 1);
 
391
        var prev = session.getLine(row - 1);
 
392
        var prevIndent = prev.search(/\S/);
 
393
        var nextIndent = next.search(/\S/);
 
394
 
 
395
        if (indent == -1) {
 
396
            session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
 
397
            return "";
 
398
        }
 
399
        if (prevIndent == -1) {
 
400
            if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
 
401
                session.foldWidgets[row - 1] = "";
 
402
                session.foldWidgets[row + 1] = "";
 
403
                return "start";
 
404
            }
 
405
        } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
 
406
            if (session.getLine(row - 2).search(/\S/) == -1) {
 
407
                session.foldWidgets[row - 1] = "start";
 
408
                session.foldWidgets[row + 1] = "";
 
409
                return "";
 
410
            }
 
411
        }
 
412
 
 
413
        if (prevIndent!= -1 && prevIndent < indent)
 
414
            session.foldWidgets[row - 1] = "start";
 
415
        else
 
416
            session.foldWidgets[row - 1] = "";
 
417
 
 
418
        if (indent < nextIndent)
 
419
            return "start";
 
420
        else
 
421
            return "";
 
422
    };
 
423
 
 
424
}).call(FoldMode.prototype);
 
425
 
 
426
});