Projekt

Obecné

Profil

Stáhnout (10.3 KB) Statistiky
| Větev: | Tag: | Revize:
1
ace.define("ace/mode/json_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 JsonHighlightRules = function() {
8
    this.$rules = {
9
        "start" : [
10
            {
11
                token : "variable", // single line
12
                regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)'
13
            }, {
14
                token : "string", // single line
15
                regex : '"',
16
                next  : "string"
17
            }, {
18
                token : "constant.numeric", // hex
19
                regex : "0[xX][0-9a-fA-F]+\\b"
20
            }, {
21
                token : "constant.numeric", // float
22
                regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
23
            }, {
24
                token : "constant.language.boolean",
25
                regex : "(?:true|false)\\b"
26
            }, {
27
                token : "text", // single quoted strings are not allowed
28
                regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
29
            }, {
30
                token : "comment", // comments are not allowed, but who cares?
31
                regex : "\\/\\/.*$"
32
            }, {
33
                token : "comment.start", // comments are not allowed, but who cares?
34
                regex : "\\/\\*",
35
                next  : "comment"
36
            }, {
37
                token : "paren.lparen",
38
                regex : "[[({]"
39
            }, {
40
                token : "paren.rparen",
41
                regex : "[\\])}]"
42
            }, {
43
                token : "text",
44
                regex : "\\s+"
45
            }
46
        ],
47
        "string" : [
48
            {
49
                token : "constant.language.escape",
50
                regex : /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|["\\\/bfnrt])/
51
            }, {
52
                token : "string",
53
                regex : '"|$',
54
                next  : "start"
55
            }, {
56
                defaultToken : "string"
57
            }
58
        ],
59
        "comment" : [
60
            {
61
                token : "comment.end", // comments are not allowed, but who cares?
62
                regex : "\\*\\/",
63
                next  : "start"
64
            }, {
65
                defaultToken: "comment"
66
            }
67
        ]
68
    };
69
    
70
};
71

    
72
oop.inherits(JsonHighlightRules, TextHighlightRules);
73

    
74
exports.JsonHighlightRules = JsonHighlightRules;
75
});
76

    
77
ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
78
"use strict";
79

    
80
var Range = require("../range").Range;
81

    
82
var MatchingBraceOutdent = function() {};
83

    
84
(function() {
85

    
86
    this.checkOutdent = function(line, input) {
87
        if (! /^\s+$/.test(line))
88
            return false;
89

    
90
        return /^\s*\}/.test(input);
91
    };
92

    
93
    this.autoOutdent = function(doc, row) {
94
        var line = doc.getLine(row);
95
        var match = line.match(/^(\s*\})/);
96

    
97
        if (!match) return 0;
98

    
99
        var column = match[1].length;
100
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
101

    
102
        if (!openBracePos || openBracePos.row == row) return 0;
103

    
104
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
105
        doc.replace(new Range(row, 0, row, column-1), indent);
106
    };
107

    
108
    this.$getIndent = function(line) {
109
        return line.match(/^\s*/)[0];
110
    };
111

    
112
}).call(MatchingBraceOutdent.prototype);
113

    
114
exports.MatchingBraceOutdent = MatchingBraceOutdent;
115
});
116

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

    
120
var oop = require("../../lib/oop");
121
var Range = require("../../range").Range;
122
var BaseFoldMode = require("./fold_mode").FoldMode;
123

    
124
var FoldMode = exports.FoldMode = function(commentRegex) {
125
    if (commentRegex) {
126
        this.foldingStartMarker = new RegExp(
127
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
128
        );
129
        this.foldingStopMarker = new RegExp(
130
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
131
        );
132
    }
133
};
134
oop.inherits(FoldMode, BaseFoldMode);
135

    
136
(function() {
137
    
138
    this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
139
    this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
140
    this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
141
    this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
142
    this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
143
    this._getFoldWidgetBase = this.getFoldWidget;
144
    this.getFoldWidget = function(session, foldStyle, row) {
145
        var line = session.getLine(row);
146
    
147
        if (this.singleLineBlockCommentRe.test(line)) {
148
            if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
149
                return "";
150
        }
151
    
152
        var fw = this._getFoldWidgetBase(session, foldStyle, row);
153
    
154
        if (!fw && this.startRegionRe.test(line))
155
            return "start"; // lineCommentRegionStart
156
    
157
        return fw;
158
    };
159

    
160
    this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
161
        var line = session.getLine(row);
162
        
163
        if (this.startRegionRe.test(line))
164
            return this.getCommentRegionBlock(session, line, row);
165
        
166
        var match = line.match(this.foldingStartMarker);
167
        if (match) {
168
            var i = match.index;
169

    
170
            if (match[1])
171
                return this.openingBracketBlock(session, match[1], row, i);
172
                
173
            var range = session.getCommentFoldRange(row, i + match[0].length, 1);
174
            
175
            if (range && !range.isMultiLine()) {
176
                if (forceMultiline) {
177
                    range = this.getSectionRange(session, row);
178
                } else if (foldStyle != "all")
179
                    range = null;
180
            }
181
            
182
            return range;
183
        }
184

    
185
        if (foldStyle === "markbegin")
186
            return;
187

    
188
        var match = line.match(this.foldingStopMarker);
189
        if (match) {
190
            var i = match.index + match[0].length;
191

    
192
            if (match[1])
193
                return this.closingBracketBlock(session, match[1], row, i);
194

    
195
            return session.getCommentFoldRange(row, i, -1);
196
        }
197
    };
198
    
199
    this.getSectionRange = function(session, row) {
200
        var line = session.getLine(row);
201
        var startIndent = line.search(/\S/);
202
        var startRow = row;
203
        var startColumn = line.length;
204
        row = row + 1;
205
        var endRow = row;
206
        var maxRow = session.getLength();
207
        while (++row < maxRow) {
208
            line = session.getLine(row);
209
            var indent = line.search(/\S/);
210
            if (indent === -1)
211
                continue;
212
            if  (startIndent > indent)
213
                break;
214
            var subRange = this.getFoldWidgetRange(session, "all", row);
215
            
216
            if (subRange) {
217
                if (subRange.start.row <= startRow) {
218
                    break;
219
                } else if (subRange.isMultiLine()) {
220
                    row = subRange.end.row;
221
                } else if (startIndent == indent) {
222
                    break;
223
                }
224
            }
225
            endRow = row;
226
        }
227
        
228
        return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
229
    };
230
    this.getCommentRegionBlock = function(session, line, row) {
231
        var startColumn = line.search(/\s*$/);
232
        var maxRow = session.getLength();
233
        var startRow = row;
234
        
235
        var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
236
        var depth = 1;
237
        while (++row < maxRow) {
238
            line = session.getLine(row);
239
            var m = re.exec(line);
240
            if (!m) continue;
241
            if (m[1]) depth--;
242
            else depth++;
243

    
244
            if (!depth) break;
245
        }
246

    
247
        var endRow = row;
248
        if (endRow > startRow) {
249
            return new Range(startRow, startColumn, endRow, line.length);
250
        }
251
    };
252

    
253
}).call(FoldMode.prototype);
254

    
255
});
256

    
257
ace.define("ace/mode/json",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/json_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/worker/worker_client"], function(require, exports, module) {
258
"use strict";
259

    
260
var oop = require("../lib/oop");
261
var TextMode = require("./text").Mode;
262
var HighlightRules = require("./json_highlight_rules").JsonHighlightRules;
263
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
264
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
265
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
266
var WorkerClient = require("../worker/worker_client").WorkerClient;
267

    
268
var Mode = function() {
269
    this.HighlightRules = HighlightRules;
270
    this.$outdent = new MatchingBraceOutdent();
271
    this.$behaviour = new CstyleBehaviour();
272
    this.foldingRules = new CStyleFoldMode();
273
};
274
oop.inherits(Mode, TextMode);
275

    
276
(function() {
277

    
278
    this.lineCommentStart = "//";
279
    this.blockComment = {start: "/*", end: "*/"};
280
    
281
    this.getNextLineIndent = function(state, line, tab) {
282
        var indent = this.$getIndent(line);
283

    
284
        if (state == "start") {
285
            var match = line.match(/^.*[\{\(\[]\s*$/);
286
            if (match) {
287
                indent += tab;
288
            }
289
        }
290

    
291
        return indent;
292
    };
293

    
294
    this.checkOutdent = function(state, line, input) {
295
        return this.$outdent.checkOutdent(line, input);
296
    };
297

    
298
    this.autoOutdent = function(state, doc, row) {
299
        this.$outdent.autoOutdent(doc, row);
300
    };
301

    
302
    this.createWorker = function(session) {
303
        var worker = new WorkerClient(["ace"], "ace/mode/json_worker", "JsonWorker");
304
        worker.attachToDocument(session.getDocument());
305

    
306
        worker.on("annotate", function(e) {
307
            session.setAnnotations(e.data);
308
        });
309

    
310
        worker.on("terminate", function() {
311
            session.clearAnnotations();
312
        });
313

    
314
        return worker;
315
    };
316

    
317

    
318
    this.$id = "ace/mode/json";
319
}).call(Mode.prototype);
320

    
321
exports.Mode = Mode;
322
});                (function() {
323
                    ace.require(["ace/mode/json"], function(m) {
324
                        if (typeof module == "object" && typeof exports == "object" && module) {
325
                            module.exports = m;
326
                        }
327
                    });
328
                })();
329
            
(97-97/244)