Projekt

Obecné

Profil

Stáhnout (14.4 KB) Statistiky
| Větev: | Tag: | Revize:
1
ace.define("ace/mode/coffee_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
2
"use strict";
3

    
4
    var oop = require("../lib/oop");
5
    var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
6

    
7
    oop.inherits(CoffeeHighlightRules, TextHighlightRules);
8

    
9
    function CoffeeHighlightRules() {
10
        var identifier = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
11

    
12
        var keywords = (
13
            "this|throw|then|try|typeof|super|switch|return|break|by|continue|" +
14
            "catch|class|in|instanceof|is|isnt|if|else|extends|for|own|" +
15
            "finally|function|while|when|new|no|not|delete|debugger|do|loop|of|off|" +
16
            "or|on|unless|until|and|yes|yield|export|import|default"
17
        );
18

    
19
        var langConstant = (
20
            "true|false|null|undefined|NaN|Infinity"
21
        );
22

    
23
        var illegal = (
24
            "case|const|function|var|void|with|enum|implements|" +
25
            "interface|let|package|private|protected|public|static"
26
        );
27

    
28
        var supportClass = (
29
            "Array|Boolean|Date|Function|Number|Object|RegExp|ReferenceError|String|" +
30
            "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" +
31
            "SyntaxError|TypeError|URIError|"  +
32
            "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
33
            "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray"
34
        );
35

    
36
        var supportFunction = (
37
            "Math|JSON|isNaN|isFinite|parseInt|parseFloat|encodeURI|" +
38
            "encodeURIComponent|decodeURI|decodeURIComponent|String|"
39
        );
40

    
41
        var variableLanguage = (
42
            "window|arguments|prototype|document"
43
        );
44

    
45
        var keywordMapper = this.createKeywordMapper({
46
            "keyword": keywords,
47
            "constant.language": langConstant,
48
            "invalid.illegal": illegal,
49
            "language.support.class": supportClass,
50
            "language.support.function": supportFunction,
51
            "variable.language": variableLanguage
52
        }, "identifier");
53

    
54
        var functionRule = {
55
            token: ["paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type"],
56
            regex: /(?:(\()((?:"[^")]*?"|'[^')]*?'|\/[^\/)]*?\/|[^()"'\/])*?)(\))(\s*))?([\-=]>)/.source
57
        };
58

    
59
        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]?|.)/;
60

    
61
        this.$rules = {
62
            start : [
63
                {
64
                    token : "constant.numeric",
65
                    regex : "(?:0x[\\da-fA-F]+|(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:[eE][+-]?\\d+)?)"
66
                }, {
67
                    stateName: "qdoc",
68
                    token : "string", regex : "'''", next : [
69
                        {token : "string", regex : "'''", next : "start"},
70
                        {token : "constant.language.escape", regex : stringEscape},
71
                        {defaultToken: "string"}
72
                    ]
73
                }, {
74
                    stateName: "qqdoc",
75
                    token : "string",
76
                    regex : '"""',
77
                    next : [
78
                        {token : "string", regex : '"""', next : "start"},
79
                        {token : "paren.string", regex : '#{', push : "start"},
80
                        {token : "constant.language.escape", regex : stringEscape},
81
                        {defaultToken: "string"}
82
                    ]
83
                }, {
84
                    stateName: "qstring",
85
                    token : "string", regex : "'", next : [
86
                        {token : "string", regex : "'", next : "start"},
87
                        {token : "constant.language.escape", regex : stringEscape},
88
                        {defaultToken: "string"}
89
                    ]
90
                }, {
91
                    stateName: "qqstring",
92
                    token : "string.start", regex : '"', next : [
93
                        {token : "string.end", regex : '"', next : "start"},
94
                        {token : "paren.string", regex : '#{', push : "start"},
95
                        {token : "constant.language.escape", regex : stringEscape},
96
                        {defaultToken: "string"}
97
                    ]
98
                }, {
99
                    stateName: "js",
100
                    token : "string", regex : "`", next : [
101
                        {token : "string", regex : "`", next : "start"},
102
                        {token : "constant.language.escape", regex : stringEscape},
103
                        {defaultToken: "string"}
104
                    ]
105
                }, {
106
                    regex: "[{}]", onMatch: function(val, state, stack) {
107
                        this.next = "";
108
                        if (val == "{" && stack.length) {
109
                            stack.unshift("start", state);
110
                            return "paren";
111
                        }
112
                        if (val == "}" && stack.length) {
113
                            stack.shift();
114
                            this.next = stack.shift() || "";
115
                            if (this.next.indexOf("string") != -1)
116
                                return "paren.string";
117
                        }
118
                        return "paren";
119
                    }
120
                }, {
121
                    token : "string.regex",
122
                    regex : "///",
123
                    next : "heregex"
124
                }, {
125
                    token : "string.regex",
126
                    regex : /(?:\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)(?:[imgy]{0,4})(?!\w)/
127
                }, {
128
                    token : "comment",
129
                    regex : "###(?!#)",
130
                    next : "comment"
131
                }, {
132
                    token : "comment",
133
                    regex : "#.*"
134
                }, {
135
                    token : ["punctuation.operator", "text", "identifier"],
136
                    regex : "(\\.)(\\s*)(" + illegal + ")"
137
                }, {
138
                    token : "punctuation.operator",
139
                    regex : "\\.{1,3}"
140
                }, {
141
                    token : ["keyword", "text", "language.support.class",
142
                     "text", "keyword", "text", "language.support.class"],
143
                    regex : "(class)(\\s+)(" + identifier + ")(?:(\\s+)(extends)(\\s+)(" + identifier + "))?"
144
                }, {
145
                    token : ["entity.name.function", "text", "keyword.operator", "text"].concat(functionRule.token),
146
                    regex : "(" + identifier + ")(\\s*)([=:])(\\s*)" + functionRule.regex
147
                }, 
148
                functionRule, 
149
                {
150
                    token : "variable",
151
                    regex : "@(?:" + identifier + ")?"
152
                }, {
153
                    token: keywordMapper,
154
                    regex : identifier
155
                }, {
156
                    token : "punctuation.operator",
157
                    regex : "\\,|\\."
158
                }, {
159
                    token : "storage.type",
160
                    regex : "[\\-=]>"
161
                }, {
162
                    token : "keyword.operator",
163
                    regex : "(?:[-+*/%<>&|^!?=]=|>>>=?|\\-\\-|\\+\\+|::|&&=|\\|\\|=|<<=|>>=|\\?\\.|\\.{2,3}|[!*+-=><])"
164
                }, {
165
                    token : "paren.lparen",
166
                    regex : "[({[]"
167
                }, {
168
                    token : "paren.rparen",
169
                    regex : "[\\]})]"
170
                }, {
171
                    token : "text",
172
                    regex : "\\s+"
173
                }],
174

    
175

    
176
            heregex : [{
177
                token : "string.regex",
178
                regex : '.*?///[imgy]{0,4}',
179
                next : "start"
180
            }, {
181
                token : "comment.regex",
182
                regex : "\\s+(?:#.*)?"
183
            }, {
184
                token : "string.regex",
185
                regex : "\\S+"
186
            }],
187

    
188
            comment : [{
189
                token : "comment",
190
                regex : '###',
191
                next : "start"
192
            }, {
193
                defaultToken : "comment"
194
            }]
195
        };
196
        this.normalizeRules();
197
    }
198

    
199
    exports.CoffeeHighlightRules = CoffeeHighlightRules;
200
});
201

    
202
ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
203
"use strict";
204

    
205
var Range = require("../range").Range;
206

    
207
var MatchingBraceOutdent = function() {};
208

    
209
(function() {
210

    
211
    this.checkOutdent = function(line, input) {
212
        if (! /^\s+$/.test(line))
213
            return false;
214

    
215
        return /^\s*\}/.test(input);
216
    };
217

    
218
    this.autoOutdent = function(doc, row) {
219
        var line = doc.getLine(row);
220
        var match = line.match(/^(\s*\})/);
221

    
222
        if (!match) return 0;
223

    
224
        var column = match[1].length;
225
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
226

    
227
        if (!openBracePos || openBracePos.row == row) return 0;
228

    
229
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
230
        doc.replace(new Range(row, 0, row, column-1), indent);
231
    };
232

    
233
    this.$getIndent = function(line) {
234
        return line.match(/^\s*/)[0];
235
    };
236

    
237
}).call(MatchingBraceOutdent.prototype);
238

    
239
exports.MatchingBraceOutdent = MatchingBraceOutdent;
240
});
241

    
242
ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
243
"use strict";
244

    
245
var oop = require("../../lib/oop");
246
var BaseFoldMode = require("./fold_mode").FoldMode;
247
var Range = require("../../range").Range;
248

    
249
var FoldMode = exports.FoldMode = function() {};
250
oop.inherits(FoldMode, BaseFoldMode);
251

    
252
(function() {
253

    
254
    this.getFoldWidgetRange = function(session, foldStyle, row) {
255
        var range = this.indentationBlock(session, row);
256
        if (range)
257
            return range;
258

    
259
        var re = /\S/;
260
        var line = session.getLine(row);
261
        var startLevel = line.search(re);
262
        if (startLevel == -1 || line[startLevel] != "#")
263
            return;
264

    
265
        var startColumn = line.length;
266
        var maxRow = session.getLength();
267
        var startRow = row;
268
        var endRow = row;
269

    
270
        while (++row < maxRow) {
271
            line = session.getLine(row);
272
            var level = line.search(re);
273

    
274
            if (level == -1)
275
                continue;
276

    
277
            if (line[level] != "#")
278
                break;
279

    
280
            endRow = row;
281
        }
282

    
283
        if (endRow > startRow) {
284
            var endColumn = session.getLine(endRow).length;
285
            return new Range(startRow, startColumn, endRow, endColumn);
286
        }
287
    };
288
    this.getFoldWidget = function(session, foldStyle, row) {
289
        var line = session.getLine(row);
290
        var indent = line.search(/\S/);
291
        var next = session.getLine(row + 1);
292
        var prev = session.getLine(row - 1);
293
        var prevIndent = prev.search(/\S/);
294
        var nextIndent = next.search(/\S/);
295

    
296
        if (indent == -1) {
297
            session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
298
            return "";
299
        }
300
        if (prevIndent == -1) {
301
            if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
302
                session.foldWidgets[row - 1] = "";
303
                session.foldWidgets[row + 1] = "";
304
                return "start";
305
            }
306
        } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
307
            if (session.getLine(row - 2).search(/\S/) == -1) {
308
                session.foldWidgets[row - 1] = "start";
309
                session.foldWidgets[row + 1] = "";
310
                return "";
311
            }
312
        }
313

    
314
        if (prevIndent!= -1 && prevIndent < indent)
315
            session.foldWidgets[row - 1] = "start";
316
        else
317
            session.foldWidgets[row - 1] = "";
318

    
319
        if (indent < nextIndent)
320
            return "start";
321
        else
322
            return "";
323
    };
324

    
325
}).call(FoldMode.prototype);
326

    
327
});
328

    
329
ace.define("ace/mode/coffee",["require","exports","module","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) {
330
"use strict";
331

    
332
var Rules = require("./coffee_highlight_rules").CoffeeHighlightRules;
333
var Outdent = require("./matching_brace_outdent").MatchingBraceOutdent;
334
var FoldMode = require("./folding/coffee").FoldMode;
335
var Range = require("../range").Range;
336
var TextMode = require("./text").Mode;
337
var WorkerClient = require("../worker/worker_client").WorkerClient;
338
var oop = require("../lib/oop");
339

    
340
function Mode() {
341
    this.HighlightRules = Rules;
342
    this.$outdent = new Outdent();
343
    this.foldingRules = new FoldMode();
344
}
345

    
346
oop.inherits(Mode, TextMode);
347

    
348
(function() {
349
    var indenter = /(?:[({[=:]|[-=]>|\b(?:else|try|(?:swi|ca)tch(?:\s+[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)?|finally))\s*$|^\s*(else\b\s*)?(?:if|for|while|loop)\b(?!.*\bthen\b)/;
350
    
351
    this.lineCommentStart = "#";
352
    this.blockComment = {start: "###", end: "###"};
353
    
354
    this.getNextLineIndent = function(state, line, tab) {
355
        var indent = this.$getIndent(line);
356
        var tokens = this.getTokenizer().getLineTokens(line, state).tokens;
357
    
358
        if (!(tokens.length && tokens[tokens.length - 1].type === 'comment') &&
359
            state === 'start' && indenter.test(line))
360
            indent += tab;
361
        return indent;
362
    };
363
    
364
    this.checkOutdent = function(state, line, input) {
365
        return this.$outdent.checkOutdent(line, input);
366
    };
367
    
368
    this.autoOutdent = function(state, doc, row) {
369
        this.$outdent.autoOutdent(doc, row);
370
    };
371
    
372
    this.createWorker = function(session) {
373
        var worker = new WorkerClient(["ace"], "ace/mode/coffee_worker", "Worker");
374
        worker.attachToDocument(session.getDocument());
375
        
376
        worker.on("annotate", function(e) {
377
            session.setAnnotations(e.data);
378
        });
379
        
380
        worker.on("terminate", function() {
381
            session.clearAnnotations();
382
        });
383
        
384
        return worker;
385
    };
386

    
387
    this.$id = "ace/mode/coffee";
388
    this.snippetFileId = "ace/snippets/coffee";
389
}).call(Mode.prototype);
390

    
391
exports.Mode = Mode;
392

    
393
});                (function() {
394
                    ace.require(["ace/mode/coffee"], function(m) {
395
                        if (typeof module == "object" && typeof exports == "object" && module) {
396
                            module.exports = m;
397
                        }
398
                    });
399
                })();
400
            
(46-46/244)