Projekt

Obecné

Profil

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

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

    
8
function safeCreateRegexp(source, flag) {
9
    try {
10
        return new RegExp(source, flag);
11
    } catch(e) {}
12
}
13

    
14
var C9SearchHighlightRules = function() {
15
    this.$rules = {
16
        "start" : [
17
            {
18
                tokenNames : ["c9searchresults.constant.numeric", "c9searchresults.text", "c9searchresults.text", "c9searchresults.keyword"],
19
                regex : /(^\s+[0-9]+)(:)(\d*\s?)([^\r\n]+)/,
20
                onMatch : function(val, state, stack) {
21
                    var values = this.splitRegex.exec(val);
22
                    var types = this.tokenNames;
23
                    var tokens = [{
24
                        type: types[0],
25
                        value: values[1]
26
                    }, {
27
                        type: types[1],
28
                        value: values[2]
29
                    }];
30
                    
31
                    if (values[3]) {
32
                        if (values[3] == " ")
33
                            tokens[1] = { type: types[1], value: values[2] + " " };
34
                        else
35
                            tokens.push({ type: types[1], value: values[3] });
36
                    }
37
                    var regex = stack[1];
38
                    var str = values[4];
39
                    
40
                    var m;
41
                    var last = 0;
42
                    if (regex && regex.exec) {
43
                        regex.lastIndex = 0;
44
                        while (m = regex.exec(str)) {
45
                            var skipped = str.substring(last, m.index);
46
                            last = regex.lastIndex;
47
                            if (skipped)
48
                                tokens.push({type: types[2], value: skipped});
49
                            if (m[0])
50
                                tokens.push({type: types[3], value: m[0]});
51
                            else if (!skipped)
52
                                break;
53
                        }
54
                    }
55
                    if (last < str.length)
56
                        tokens.push({type: types[2], value: str.substr(last)});
57
                    return tokens;
58
                }
59
            },
60
            {
61
                regex : "^Searching for [^\\r\\n]*$",
62
                onMatch: function(val, state, stack) {
63
                    var parts = val.split("\x01");
64
                    if (parts.length < 3)
65
                        return "text";
66

    
67
                    var options, search;
68
                    
69
                    var i = 0;
70
                    var tokens = [{
71
                        value: parts[i++] + "'",
72
                        type: "text"
73
                    }, {
74
                        value: search = parts[i++],
75
                        type: "text" // "c9searchresults.keyword"
76
                    }, {
77
                        value: "'" + parts[i++],
78
                        type: "text"
79
                    }];
80
                    if (parts[2] !== " in") {
81
                        tokens.push({
82
                            value: "'" + parts[i++] + "'",
83
                            type: "text"
84
                        }, {
85
                            value: parts[i++],
86
                            type: "text"
87
                        });
88
                    }
89
                    tokens.push({
90
                        value: " " + parts[i++] + " ",
91
                        type: "text"
92
                    });
93
                    if (parts[i+1]) {
94
                        options = parts[i+1];
95
                        tokens.push({
96
                            value: "(" + parts[i+1] + ")",
97
                            type: "text"
98
                        });
99
                        i += 1;
100
                    } else {
101
                        i -= 1;
102
                    }
103
                    while (i++ < parts.length) {
104
                        parts[i] && tokens.push({
105
                            value: parts[i],
106
                            type: "text"
107
                        });
108
                    }
109
                    
110
                    if (search) {
111
                        if (!/regex/.test(options))
112
                            search = lang.escapeRegExp(search);
113
                        if (/whole/.test(options))
114
                            search = "\\b" + search + "\\b";
115
                    }
116
                    
117
                    var regex = search && safeCreateRegexp(
118
                        "(" + search + ")",
119
                        / sensitive/.test(options) ? "g" : "ig"
120
                    );
121
                    if (regex) {
122
                        stack[0] = state;
123
                        stack[1] = regex;
124
                    }
125
                    
126
                    return tokens;
127
                }
128
            },
129
            {
130
                regex : "^(?=Found \\d+ matches)",
131
                token : "text",
132
                next : "numbers"
133
            },
134
            {
135
                token : "string", // single line
136
                regex : "^\\S:?[^:]+",
137
                next : "numbers"
138
            }
139
        ],
140
        numbers:[{
141
            regex : "\\d+",
142
            token : "constant.numeric"
143
        }, {
144
            regex : "$",
145
            token : "text",
146
            next : "start"
147
        }]
148
    };
149
    this.normalizeRules();
150
};
151

    
152
oop.inherits(C9SearchHighlightRules, TextHighlightRules);
153

    
154
exports.C9SearchHighlightRules = C9SearchHighlightRules;
155

    
156
});
157

    
158
ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
159
"use strict";
160

    
161
var Range = require("../range").Range;
162

    
163
var MatchingBraceOutdent = function() {};
164

    
165
(function() {
166

    
167
    this.checkOutdent = function(line, input) {
168
        if (! /^\s+$/.test(line))
169
            return false;
170

    
171
        return /^\s*\}/.test(input);
172
    };
173

    
174
    this.autoOutdent = function(doc, row) {
175
        var line = doc.getLine(row);
176
        var match = line.match(/^(\s*\})/);
177

    
178
        if (!match) return 0;
179

    
180
        var column = match[1].length;
181
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
182

    
183
        if (!openBracePos || openBracePos.row == row) return 0;
184

    
185
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
186
        doc.replace(new Range(row, 0, row, column-1), indent);
187
    };
188

    
189
    this.$getIndent = function(line) {
190
        return line.match(/^\s*/)[0];
191
    };
192

    
193
}).call(MatchingBraceOutdent.prototype);
194

    
195
exports.MatchingBraceOutdent = MatchingBraceOutdent;
196
});
197

    
198
ace.define("ace/mode/folding/c9search",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
199
"use strict";
200

    
201
var oop = require("../../lib/oop");
202
var Range = require("../../range").Range;
203
var BaseFoldMode = require("./fold_mode").FoldMode;
204

    
205
var FoldMode = exports.FoldMode = function() {};
206
oop.inherits(FoldMode, BaseFoldMode);
207

    
208
(function() {
209

    
210
    this.foldingStartMarker = /^(\S.*:|Searching for.*)$/;
211
    this.foldingStopMarker = /^(\s+|Found.*)$/;
212
    
213
    this.getFoldWidgetRange = function(session, foldStyle, row) {
214
        var lines = session.doc.getAllLines(row);
215
        var line = lines[row];
216
        var level1 = /^(Found.*|Searching for.*)$/;
217
        var level2 = /^(\S.*:|\s*)$/;
218
        var re = level1.test(line) ? level1 : level2;
219
        
220
        var startRow = row;
221
        var endRow = row;
222

    
223
        if (this.foldingStartMarker.test(line)) {
224
            for (var i = row + 1, l = session.getLength(); i < l; i++) {
225
                if (re.test(lines[i]))
226
                    break;
227
            }
228
            endRow = i;
229
        }
230
        else if (this.foldingStopMarker.test(line)) {
231
            for (var i = row - 1; i >= 0; i--) {
232
                line = lines[i];
233
                if (re.test(line))
234
                    break;
235
            }
236
            startRow = i;
237
        }
238
        if (startRow != endRow) {
239
            var col = line.length;
240
            if (re === level1)
241
                col = line.search(/\(Found[^)]+\)$|$/);
242
            return new Range(startRow, col, endRow, 0);
243
        }
244
    };
245
    
246
}).call(FoldMode.prototype);
247

    
248
});
249

    
250
ace.define("ace/mode/c9search",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/c9search_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/c9search"], function(require, exports, module) {
251
"use strict";
252

    
253
var oop = require("../lib/oop");
254
var TextMode = require("./text").Mode;
255
var C9SearchHighlightRules = require("./c9search_highlight_rules").C9SearchHighlightRules;
256
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
257
var C9StyleFoldMode = require("./folding/c9search").FoldMode;
258

    
259
var Mode = function() {
260
    this.HighlightRules = C9SearchHighlightRules;
261
    this.$outdent = new MatchingBraceOutdent();
262
    this.foldingRules = new C9StyleFoldMode();
263
};
264
oop.inherits(Mode, TextMode);
265

    
266
(function() {
267
    
268
    this.getNextLineIndent = function(state, line, tab) {
269
        var indent = this.$getIndent(line);
270
        return indent;
271
    };
272

    
273
    this.checkOutdent = function(state, line, input) {
274
        return this.$outdent.checkOutdent(line, input);
275
    };
276

    
277
    this.autoOutdent = function(state, doc, row) {
278
        this.$outdent.autoOutdent(doc, row);
279
    };
280

    
281
    this.$id = "ace/mode/c9search";
282
}).call(Mode.prototype);
283

    
284
exports.Mode = Mode;
285

    
286
});                (function() {
287
                    ace.require(["ace/mode/c9search"], function(m) {
288
                        if (typeof module == "object" && typeof exports == "object" && module) {
289
                            module.exports = m;
290
                        }
291
                    });
292
                })();
293
            
(41-41/244)