Projekt

Obecné

Profil

Stáhnout (13.8 KB) Statistiky
| Větev: | Tag: | Revize:
1
ace.define("ace/mode/doc_comment_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
var DocCommentHighlightRules = function() {
8
    this.$rules = {
9
        "start" : [ {
10
            token : "comment.doc.tag",
11
            regex : "@[\\w\\d_]+" // TODO: fix email addresses
12
        }, 
13
        DocCommentHighlightRules.getTagRule(),
14
        {
15
            defaultToken : "comment.doc",
16
            caseInsensitive: true
17
        }]
18
    };
19
};
20

    
21
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
22

    
23
DocCommentHighlightRules.getTagRule = function(start) {
24
    return {
25
        token : "comment.doc.tag.storage.type",
26
        regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
27
    };
28
};
29

    
30
DocCommentHighlightRules.getStartRule = function(start) {
31
    return {
32
        token : "comment.doc", // doc comment
33
        regex : "\\/\\*(?=\\*)",
34
        next  : start
35
    };
36
};
37

    
38
DocCommentHighlightRules.getEndRule = function (start) {
39
    return {
40
        token : "comment.doc", // closing comment
41
        regex : "\\*\\/",
42
        next  : start
43
    };
44
};
45

    
46

    
47
exports.DocCommentHighlightRules = DocCommentHighlightRules;
48

    
49
});
50

    
51
ace.define("ace/mode/golang_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
52
    var oop = require("../lib/oop");
53
    var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
54
    var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
55

    
56
    var GolangHighlightRules = function() {
57
        var keywords = (
58
            "else|break|case|return|goto|if|const|select|" +
59
            "continue|struct|default|switch|for|range|" +
60
            "func|import|package|chan|defer|fallthrough|go|interface|map|range|" +
61
            "select|type|var"
62
        );
63
        var builtinTypes = (
64
            "string|uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|" +
65
            "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error"
66
        );
67
        var builtinFunctions = (
68
            "new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append"
69
        );
70
        var builtinConstants = ("nil|true|false|iota");
71

    
72
        var keywordMapper = this.createKeywordMapper({
73
            "keyword": keywords,
74
            "constant.language": builtinConstants,
75
            "support.function": builtinFunctions,
76
            "support.type": builtinTypes
77
        }, "");
78
        
79
        var stringEscapeRe = "\\\\(?:[0-7]{3}|x\\h{2}|u{4}|U\\h{6}|[abfnrtv'\"\\\\])".replace(/\\h/g, "[a-fA-F\\d]");
80

    
81
        this.$rules = {
82
            "start" : [
83
                {
84
                    token : "comment",
85
                    regex : "\\/\\/.*$"
86
                },
87
                DocCommentHighlightRules.getStartRule("doc-start"),
88
                {
89
                    token : "comment.start", // multi line comment
90
                    regex : "\\/\\*",
91
                    next : "comment"
92
                }, {
93
                    token : "string", // single line
94
                    regex : /"(?:[^"\\]|\\.)*?"/
95
                }, {
96
                    token : "string", // raw
97
                    regex : '`',
98
                    next : "bqstring"
99
                }, {
100
                    token : "constant.numeric", // rune
101
                    regex : "'(?:[^\\'\uD800-\uDBFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|" + stringEscapeRe.replace('"', '')  + ")'"
102
                }, {
103
                    token : "constant.numeric", // hex
104
                    regex : "0[xX][0-9a-fA-F]+\\b" 
105
                }, {
106
                    token : "constant.numeric", // float
107
                    regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
108
                }, {
109
                    token : ["keyword", "text", "entity.name.function"],
110
                    regex : "(func)(\\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)\\b"
111
                }, {
112
                    token : function(val) {
113
                        if (val[val.length - 1] == "(") {
114
                            return [{
115
                                type: keywordMapper(val.slice(0, -1)) || "support.function",
116
                                value: val.slice(0, -1)
117
                            }, {
118
                                type: "paren.lparen",
119
                                value: val.slice(-1)
120
                            }];
121
                        }
122
                        
123
                        return keywordMapper(val) || "identifier";
124
                    },
125
                    regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b\\(?"
126
                }, {
127
                    token : "keyword.operator",
128
                    regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^="
129
                }, {
130
                    token : "punctuation.operator",
131
                    regex : "\\?|\\:|\\,|\\;|\\."
132
                }, {
133
                    token : "paren.lparen",
134
                    regex : "[[({]"
135
                }, {
136
                    token : "paren.rparen",
137
                    regex : "[\\])}]"
138
                }, {
139
                    token : "text",
140
                    regex : "\\s+"
141
                }
142
            ],
143
            "comment" : [
144
                {
145
                    token : "comment.end",
146
                    regex : "\\*\\/",
147
                    next : "start"
148
                }, {
149
                    defaultToken : "comment"
150
                }
151
            ],
152
            "bqstring" : [
153
                {
154
                    token : "string",
155
                    regex : '`',
156
                    next : "start"
157
                }, {
158
                    defaultToken : "string"
159
                }
160
            ]
161
        };
162

    
163
        this.embedRules(DocCommentHighlightRules, "doc-",
164
            [ DocCommentHighlightRules.getEndRule("start") ]);
165
    };
166
    oop.inherits(GolangHighlightRules, TextHighlightRules);
167

    
168
    exports.GolangHighlightRules = GolangHighlightRules;
169
});
170

    
171
ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
172
"use strict";
173

    
174
var Range = require("../range").Range;
175

    
176
var MatchingBraceOutdent = function() {};
177

    
178
(function() {
179

    
180
    this.checkOutdent = function(line, input) {
181
        if (! /^\s+$/.test(line))
182
            return false;
183

    
184
        return /^\s*\}/.test(input);
185
    };
186

    
187
    this.autoOutdent = function(doc, row) {
188
        var line = doc.getLine(row);
189
        var match = line.match(/^(\s*\})/);
190

    
191
        if (!match) return 0;
192

    
193
        var column = match[1].length;
194
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
195

    
196
        if (!openBracePos || openBracePos.row == row) return 0;
197

    
198
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
199
        doc.replace(new Range(row, 0, row, column-1), indent);
200
    };
201

    
202
    this.$getIndent = function(line) {
203
        return line.match(/^\s*/)[0];
204
    };
205

    
206
}).call(MatchingBraceOutdent.prototype);
207

    
208
exports.MatchingBraceOutdent = MatchingBraceOutdent;
209
});
210

    
211
ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
212
"use strict";
213

    
214
var oop = require("../../lib/oop");
215
var Range = require("../../range").Range;
216
var BaseFoldMode = require("./fold_mode").FoldMode;
217

    
218
var FoldMode = exports.FoldMode = function(commentRegex) {
219
    if (commentRegex) {
220
        this.foldingStartMarker = new RegExp(
221
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
222
        );
223
        this.foldingStopMarker = new RegExp(
224
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
225
        );
226
    }
227
};
228
oop.inherits(FoldMode, BaseFoldMode);
229

    
230
(function() {
231
    
232
    this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
233
    this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
234
    this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
235
    this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
236
    this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
237
    this._getFoldWidgetBase = this.getFoldWidget;
238
    this.getFoldWidget = function(session, foldStyle, row) {
239
        var line = session.getLine(row);
240
    
241
        if (this.singleLineBlockCommentRe.test(line)) {
242
            if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
243
                return "";
244
        }
245
    
246
        var fw = this._getFoldWidgetBase(session, foldStyle, row);
247
    
248
        if (!fw && this.startRegionRe.test(line))
249
            return "start"; // lineCommentRegionStart
250
    
251
        return fw;
252
    };
253

    
254
    this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
255
        var line = session.getLine(row);
256
        
257
        if (this.startRegionRe.test(line))
258
            return this.getCommentRegionBlock(session, line, row);
259
        
260
        var match = line.match(this.foldingStartMarker);
261
        if (match) {
262
            var i = match.index;
263

    
264
            if (match[1])
265
                return this.openingBracketBlock(session, match[1], row, i);
266
                
267
            var range = session.getCommentFoldRange(row, i + match[0].length, 1);
268
            
269
            if (range && !range.isMultiLine()) {
270
                if (forceMultiline) {
271
                    range = this.getSectionRange(session, row);
272
                } else if (foldStyle != "all")
273
                    range = null;
274
            }
275
            
276
            return range;
277
        }
278

    
279
        if (foldStyle === "markbegin")
280
            return;
281

    
282
        var match = line.match(this.foldingStopMarker);
283
        if (match) {
284
            var i = match.index + match[0].length;
285

    
286
            if (match[1])
287
                return this.closingBracketBlock(session, match[1], row, i);
288

    
289
            return session.getCommentFoldRange(row, i, -1);
290
        }
291
    };
292
    
293
    this.getSectionRange = function(session, row) {
294
        var line = session.getLine(row);
295
        var startIndent = line.search(/\S/);
296
        var startRow = row;
297
        var startColumn = line.length;
298
        row = row + 1;
299
        var endRow = row;
300
        var maxRow = session.getLength();
301
        while (++row < maxRow) {
302
            line = session.getLine(row);
303
            var indent = line.search(/\S/);
304
            if (indent === -1)
305
                continue;
306
            if  (startIndent > indent)
307
                break;
308
            var subRange = this.getFoldWidgetRange(session, "all", row);
309
            
310
            if (subRange) {
311
                if (subRange.start.row <= startRow) {
312
                    break;
313
                } else if (subRange.isMultiLine()) {
314
                    row = subRange.end.row;
315
                } else if (startIndent == indent) {
316
                    break;
317
                }
318
            }
319
            endRow = row;
320
        }
321
        
322
        return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
323
    };
324
    this.getCommentRegionBlock = function(session, line, row) {
325
        var startColumn = line.search(/\s*$/);
326
        var maxRow = session.getLength();
327
        var startRow = row;
328
        
329
        var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
330
        var depth = 1;
331
        while (++row < maxRow) {
332
            line = session.getLine(row);
333
            var m = re.exec(line);
334
            if (!m) continue;
335
            if (m[1]) depth--;
336
            else depth++;
337

    
338
            if (!depth) break;
339
        }
340

    
341
        var endRow = row;
342
        if (endRow > startRow) {
343
            return new Range(startRow, startColumn, endRow, line.length);
344
        }
345
    };
346

    
347
}).call(FoldMode.prototype);
348

    
349
});
350

    
351
ace.define("ace/mode/golang",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/golang_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
352

    
353
var oop = require("../lib/oop");
354
var TextMode = require("./text").Mode;
355
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
356
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
357
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
358
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
359

    
360
var Mode = function() {
361
    this.HighlightRules = GolangHighlightRules;
362
    this.$outdent = new MatchingBraceOutdent();
363
    this.foldingRules = new CStyleFoldMode();
364
    this.$behaviour = new CstyleBehaviour();
365
};
366
oop.inherits(Mode, TextMode);
367

    
368
(function() {
369
    
370
    this.lineCommentStart = "//";
371
    this.blockComment = {start: "/*", end: "*/"};
372

    
373
    this.getNextLineIndent = function(state, line, tab) {
374
        var indent = this.$getIndent(line);
375

    
376
        var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
377
        var tokens = tokenizedLine.tokens;
378
        var endState = tokenizedLine.state;
379

    
380
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
381
            return indent;
382
        }
383
        
384
        if (state == "start") {
385
            var match = line.match(/^.*[\{\(\[]\s*$/);
386
            if (match) {
387
                indent += tab;
388
            }
389
        }
390

    
391
        return indent;
392
    };//end getNextLineIndent
393

    
394
    this.checkOutdent = function(state, line, input) {
395
        return this.$outdent.checkOutdent(line, input);
396
    };
397

    
398
    this.autoOutdent = function(state, doc, row) {
399
        this.$outdent.autoOutdent(doc, row);
400
    };
401

    
402
    this.$id = "ace/mode/golang";
403
}).call(Mode.prototype);
404

    
405
exports.Mode = Mode;
406
});                (function() {
407
                    ace.require(["ace/mode/golang"], function(m) {
408
                        if (typeof module == "object" && typeof exports == "object" && module) {
409
                            module.exports = m;
410
                        }
411
                    });
412
                })();
413
            
(79-79/244)