/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
15.1.1 by galaxyAbstractor
Started implementation of a new codeviewer using Ace
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/glsl', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/c_cpp', 'ace/tokenizer', 'ace/mode/glsl_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
32
33
34
var oop = require("../lib/oop");
35
var CMode = require("./c_cpp").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var glslHighlightRules = require("./glsl_highlight_rules").glslHighlightRules;
38
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39
var Range = require("../range").Range;
40
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
41
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
42
43
var Mode = function() {
44
    this.$tokenizer = new Tokenizer(new glslHighlightRules().getRules());
45
    this.$outdent = new MatchingBraceOutdent();
46
    this.$behaviour = new CstyleBehaviour();
47
    this.foldingRules = new CStyleFoldMode();
48
};
49
oop.inherits(Mode, CMode);
50
51
exports.Mode = Mode;
52
});
53
54
define('ace/mode/c_cpp', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/c_cpp_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
55
56
57
var oop = require("../lib/oop");
58
var TextMode = require("./text").Mode;
59
var Tokenizer = require("../tokenizer").Tokenizer;
60
var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
61
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
62
var Range = require("../range").Range;
63
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
64
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
65
66
var Mode = function() {
67
    this.$tokenizer = new Tokenizer(new c_cppHighlightRules().getRules());
68
    this.$outdent = new MatchingBraceOutdent();
69
    this.$behaviour = new CstyleBehaviour();
70
    this.foldingRules = new CStyleFoldMode();
71
};
72
oop.inherits(Mode, TextMode);
73
74
(function() {
75
76
    this.lineCommentStart = "//";
77
    this.blockComment = {start: "/*", end: "*/"};
78
79
    this.getNextLineIndent = function(state, line, tab) {
80
        var indent = this.$getIndent(line);
81
82
        var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
83
        var tokens = tokenizedLine.tokens;
84
        var endState = tokenizedLine.state;
85
86
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
87
            return indent;
88
        }
89
90
        if (state == "start") {
91
            var match = line.match(/^.*[\{\(\[]\s*$/);
92
            if (match) {
93
                indent += tab;
94
            }
95
        } else if (state == "doc-start") {
96
            if (endState == "start") {
97
                return "";
98
            }
99
            var match = line.match(/^\s*(\/?)\*/);
100
            if (match) {
101
                if (match[1]) {
102
                    indent += " ";
103
                }
104
                indent += "* ";
105
            }
106
        }
107
108
        return indent;
109
    };
110
111
    this.checkOutdent = function(state, line, input) {
112
        return this.$outdent.checkOutdent(line, input);
113
    };
114
115
    this.autoOutdent = function(state, doc, row) {
116
        this.$outdent.autoOutdent(doc, row);
117
    };
118
119
}).call(Mode.prototype);
120
121
exports.Mode = Mode;
122
});
123
define('ace/mode/c_cpp_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
124
125
126
var oop = require("../lib/oop");
127
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
128
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
129
var cFunctions = exports.cFunctions = "\\s*\\bhypot(?:f|l)?|s(?:scanf|ystem|nprintf|ca(?:nf|lb(?:n(?:f|l)?|ln(?:f|l)?))|i(?:n(?:h(?:f|l)?|f|l)?|gn(?:al|bit))|tr(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?)|error|pbrk|ftime|len|rchr|xfrm)|printf|et(?:jmp|vbuf|locale|buf)|qrt(?:f|l)?|w(?:scanf|printf)|rand)|n(?:e(?:arbyint(?:f|l)?|xt(?:toward(?:f|l)?|after(?:f|l)?))|an(?:f|l)?)|c(?:s(?:in(?:h(?:f|l)?|f|l)?|qrt(?:f|l)?)|cos(?:h(?:f)?|f|l)?|imag(?:f|l)?|t(?:ime|an(?:h(?:f|l)?|f|l)?)|o(?:s(?:h(?:f|l)?|f|l)?|nj(?:f|l)?|pysign(?:f|l)?)|p(?:ow(?:f|l)?|roj(?:f|l)?)|e(?:il(?:f|l)?|xp(?:f|l)?)|l(?:o(?:ck|g(?:f|l)?)|earerr)|a(?:sin(?:h(?:f|l)?|f|l)?|cos(?:h(?:f|l)?|f|l)?|tan(?:h(?:f|l)?|f|l)?|lloc|rg(?:f|l)?|bs(?:f|l)?)|real(?:f|l)?|brt(?:f|l)?)|t(?:ime|o(?:upper|lower)|an(?:h(?:f|l)?|f|l)?|runc(?:f|l)?|gamma(?:f|l)?|mp(?:nam|file))|i(?:s(?:space|n(?:ormal|an)|cntrl|inf|digit|u(?:nordered|pper)|p(?:unct|rint)|finite|w(?:space|c(?:ntrl|type)|digit|upper|p(?:unct|rint)|lower|al(?:num|pha)|graph|xdigit|blank)|l(?:ower|ess(?:equal|greater)?)|al(?:num|pha)|gr(?:eater(?:equal)?|aph)|xdigit|blank)|logb(?:f|l)?|max(?:div|abs))|di(?:v|fftime)|_Exit|unget(?:c|wc)|p(?:ow(?:f|l)?|ut(?:s|c(?:har)?|wc(?:har)?)|error|rintf)|e(?:rf(?:c(?:f|l)?|f|l)?|x(?:it|p(?:2(?:f|l)?|f|l|m1(?:f|l)?)?))|v(?:s(?:scanf|nprintf|canf|printf|w(?:scanf|printf))|printf|f(?:scanf|printf|w(?:scanf|printf))|w(?:scanf|printf)|a_(?:start|copy|end|arg))|qsort|f(?:s(?:canf|e(?:tpos|ek))|close|tell|open|dim(?:f|l)?|p(?:classify|ut(?:s|c|w(?:s|c))|rintf)|e(?:holdexcept|set(?:e(?:nv|xceptflag)|round)|clearexcept|testexcept|of|updateenv|r(?:aiseexcept|ror)|get(?:e(?:nv|xceptflag)|round))|flush|w(?:scanf|ide|printf|rite)|loor(?:f|l)?|abs(?:f|l)?|get(?:s|c|pos|w(?:s|c))|re(?:open|e|ad|xp(?:f|l)?)|m(?:in(?:f|l)?|od(?:f|l)?|a(?:f|l|x(?:f|l)?)?))|l(?:d(?:iv|exp(?:f|l)?)|o(?:ngjmp|cal(?:time|econv)|g(?:1(?:p(?:f|l)?|0(?:f|l)?)|2(?:f|l)?|f|l|b(?:f|l)?)?)|abs|l(?:div|abs|r(?:int(?:f|l)?|ound(?:f|l)?))|r(?:int(?:f|l)?|ound(?:f|l)?)|gamma(?:f|l)?)|w(?:scanf|c(?:s(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?|mbs)|pbrk|ftime|len|r(?:chr|tombs)|xfrm)|to(?:b|mb)|rtomb)|printf|mem(?:set|c(?:hr|py|mp)|move))|a(?:s(?:sert|ctime|in(?:h(?:f|l)?|f|l)?)|cos(?:h(?:f|l)?|f|l)?|t(?:o(?:i|f|l(?:l)?)|exit|an(?:h(?:f|l)?|2(?:f|l)?|f|l)?)|b(?:s|ort))|g(?:et(?:s|c(?:har)?|env|wc(?:har)?)|mtime)|r(?:int(?:f|l)?|ound(?:f|l)?|e(?:name|alloc|wind|m(?:ove|quo(?:f|l)?|ainder(?:f|l)?))|a(?:nd|ise))|b(?:search|towc)|m(?:odf(?:f|l)?|em(?:set|c(?:hr|py|mp)|move)|ktime|alloc|b(?:s(?:init|towcs|rtowcs)|towc|len|r(?:towc|len)))\\b"
130
131
var c_cppHighlightRules = function() {
132
133
    var keywordControls = (
134
        "break|case|continue|default|do|else|for|goto|if|_Pragma|" +
135
        "return|switch|while|catch|operator|try|throw|using"
136
    );
137
    
138
    var storageType = (
139
        "asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" +
140
        "_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void|" +
141
        "class|wchar_t|template"
142
    );
143
144
    var storageModifiers = (
145
        "const|extern|register|restrict|static|volatile|inline|private:|" +
146
        "protected:|public:|friend|explicit|virtual|export|mutable|typename"
147
    );
148
149
    var keywordOperators = (
150
        "and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|typeid|xor|xor_eq" +
151
        "const_cast|dynamic_cast|reinterpret_cast|static_cast|sizeof|namespace"
152
    );
153
154
    var builtinConstants = (
155
        "NULL|true|false|TRUE|FALSE"
156
    );
157
158
    var keywordMapper = this.$keywords = this.createKeywordMapper({
159
        "keyword.control" : keywordControls,
160
        "storage.type" : storageType,
161
        "storage.modifier" : storageModifiers,
162
        "keyword.operator" : keywordOperators,
163
        "variable.language": "this",
164
        "constant.language": builtinConstants
165
    }, "identifier");
166
167
    var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\d\\$_\u00a1-\uffff]*\\b";
168
169
    this.$rules = {
170
        "start" : [
171
            {
172
                token : "comment",
173
                regex : "\\/\\/.*$"
174
            },
175
            DocCommentHighlightRules.getStartRule("doc-start"),
176
            {
177
                token : "comment", // multi line comment
178
                regex : "\\/\\*",
179
                next : "comment"
180
            }, {
181
                token : "string", // single line
182
                regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
183
            }, {
184
                token : "string", // multi line string start
185
                regex : '["].*\\\\$',
186
                next : "qqstring"
187
            }, {
188
                token : "string", // single line
189
                regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
190
            }, {
191
                token : "string", // multi line string start
192
                regex : "['].*\\\\$",
193
                next : "qstring"
194
            }, {
195
                token : "constant.numeric", // hex
196
                regex : "0[xX][0-9a-fA-F]+\\b"
197
            }, {
198
                token : "constant.numeric", // float
199
                regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
200
            }, {
201
                token : "keyword", // pre-compiler directives
202
                regex : "(?:#include|#import|#pragma|#line|#define|#undef|#if|#ifdef|#else|#elif|#ifndef)\\b",
203
                next  : "directive"
204
            }, {
205
                token : "keyword", // special case pre-compiler directive
206
                regex : "(?:#endif)\\b"
207
            }, {
208
                token : "support.function.C99.c",
209
                regex : cFunctions
210
            }, {
211
                token : keywordMapper,
212
                regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
213
            }, {
214
                token : "keyword.operator",
215
                regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)"
216
            }, {
217
              token : "punctuation.operator",
218
              regex : "\\?|\\:|\\,|\\;|\\."
219
            }, {
220
                token : "paren.lparen",
221
                regex : "[[({]"
222
            }, {
223
                token : "paren.rparen",
224
                regex : "[\\])}]"
225
            }, {
226
                token : "text",
227
                regex : "\\s+"
228
            }
229
        ],
230
        "comment" : [
231
            {
232
                token : "comment", // closing comment
233
                regex : ".*?\\*\\/",
234
                next : "start"
235
            }, {
236
                token : "comment", // comment spanning whole line
237
                regex : ".+"
238
            }
239
        ],
240
        "qqstring" : [
241
            {
242
                token : "string",
243
                regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
244
                next : "start"
245
            }, {
246
                token : "string",
247
                regex : '.+'
248
            }
249
        ],
250
        "qstring" : [
251
            {
252
                token : "string",
253
                regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
254
                next : "start"
255
            }, {
256
                token : "string",
257
                regex : '.+'
258
            }
259
        ],
260
        "directive" : [
261
            {
262
                token : "constant.other.multiline",
263
                regex : /\\/
264
            },
265
            {
266
                token : "constant.other.multiline",
267
                regex : /.*\\/
268
            },
269
            {
270
                token : "constant.other",
271
                regex : "\\s*<.+?>",
272
                next : "start"
273
            },
274
            {
275
                token : "constant.other", // single line
276
                regex : '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
277
                next : "start"
278
            }, 
279
            {
280
                token : "constant.other", // single line
281
                regex : "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
282
                next : "start"
283
            },
284
            {
285
                token : "constant.other",
286
                regex : /[^\\\/]+/,
287
                next : "start"
288
            }
289
        ]
290
    };
291
292
    this.embedRules(DocCommentHighlightRules, "doc-",
293
        [ DocCommentHighlightRules.getEndRule("start") ]);
294
};
295
296
oop.inherits(c_cppHighlightRules, TextHighlightRules);
297
298
exports.c_cppHighlightRules = c_cppHighlightRules;
299
});
300
301
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
302
303
304
var oop = require("../lib/oop");
305
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
306
307
var DocCommentHighlightRules = function() {
308
309
    this.$rules = {
310
        "start" : [ {
311
            token : "comment.doc.tag",
312
            regex : "@[\\w\\d_]+" // TODO: fix email addresses
313
        }, {
314
            token : "comment.doc.tag",
315
            regex : "\\bTODO\\b"
316
        }, {
317
            defaultToken : "comment.doc"
318
        }]
319
    };
320
};
321
322
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
323
324
DocCommentHighlightRules.getStartRule = function(start) {
325
    return {
326
        token : "comment.doc", // doc comment
327
        regex : "\\/\\*(?=\\*)",
328
        next  : start
329
    };
330
};
331
332
DocCommentHighlightRules.getEndRule = function (start) {
333
    return {
334
        token : "comment.doc", // closing comment
335
        regex : "\\*\\/",
336
        next  : start
337
    };
338
};
339
340
341
exports.DocCommentHighlightRules = DocCommentHighlightRules;
342
343
});
344
345
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
346
347
348
var Range = require("../range").Range;
349
350
var MatchingBraceOutdent = function() {};
351
352
(function() {
353
354
    this.checkOutdent = function(line, input) {
355
        if (! /^\s+$/.test(line))
356
            return false;
357
358
        return /^\s*\}/.test(input);
359
    };
360
361
    this.autoOutdent = function(doc, row) {
362
        var line = doc.getLine(row);
363
        var match = line.match(/^(\s*\})/);
364
365
        if (!match) return 0;
366
367
        var column = match[1].length;
368
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
369
370
        if (!openBracePos || openBracePos.row == row) return 0;
371
372
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
373
        doc.replace(new Range(row, 0, row, column-1), indent);
374
    };
375
376
    this.$getIndent = function(line) {
377
        return line.match(/^\s*/)[0];
378
    };
379
380
}).call(MatchingBraceOutdent.prototype);
381
382
exports.MatchingBraceOutdent = MatchingBraceOutdent;
383
});
384
385
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
386
387
388
var oop = require("../../lib/oop");
389
var Behaviour = require("../behaviour").Behaviour;
390
var TokenIterator = require("../../token_iterator").TokenIterator;
391
var lang = require("../../lib/lang");
392
393
var SAFE_INSERT_IN_TOKENS =
394
    ["text", "paren.rparen", "punctuation.operator"];
395
var SAFE_INSERT_BEFORE_TOKENS =
396
    ["text", "paren.rparen", "punctuation.operator", "comment"];
397
398
399
var autoInsertedBrackets = 0;
400
var autoInsertedRow = -1;
401
var autoInsertedLineEnd = "";
402
var maybeInsertedBrackets = 0;
403
var maybeInsertedRow = -1;
404
var maybeInsertedLineStart = "";
405
var maybeInsertedLineEnd = "";
406
407
var CstyleBehaviour = function () {
408
    
409
    CstyleBehaviour.isSaneInsertion = function(editor, session) {
410
        var cursor = editor.getCursorPosition();
411
        var iterator = new TokenIterator(session, cursor.row, cursor.column);
412
        if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
413
            var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
414
            if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
415
                return false;
416
        }
417
        iterator.stepForward();
418
        return iterator.getCurrentTokenRow() !== cursor.row ||
419
            this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
420
    };
421
    
422
    CstyleBehaviour.$matchTokenType = function(token, types) {
423
        return types.indexOf(token.type || token) > -1;
424
    };
425
    
426
    CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
427
        var cursor = editor.getCursorPosition();
428
        var line = session.doc.getLine(cursor.row);
429
        if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
430
            autoInsertedBrackets = 0;
431
        autoInsertedRow = cursor.row;
432
        autoInsertedLineEnd = bracket + line.substr(cursor.column);
433
        autoInsertedBrackets++;
434
    };
435
    
436
    CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
437
        var cursor = editor.getCursorPosition();
438
        var line = session.doc.getLine(cursor.row);
439
        if (!this.isMaybeInsertedClosing(cursor, line))
440
            maybeInsertedBrackets = 0;
441
        maybeInsertedRow = cursor.row;
442
        maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
443
        maybeInsertedLineEnd = line.substr(cursor.column);
444
        maybeInsertedBrackets++;
445
    };
446
    
447
    CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
448
        return autoInsertedBrackets > 0 &&
449
            cursor.row === autoInsertedRow &&
450
            bracket === autoInsertedLineEnd[0] &&
451
            line.substr(cursor.column) === autoInsertedLineEnd;
452
    };
453
    
454
    CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
455
        return maybeInsertedBrackets > 0 &&
456
            cursor.row === maybeInsertedRow &&
457
            line.substr(cursor.column) === maybeInsertedLineEnd &&
458
            line.substr(0, cursor.column) == maybeInsertedLineStart;
459
    };
460
    
461
    CstyleBehaviour.popAutoInsertedClosing = function() {
462
        autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
463
        autoInsertedBrackets--;
464
    };
465
    
466
    CstyleBehaviour.clearMaybeInsertedClosing = function() {
467
        maybeInsertedBrackets = 0;
468
        maybeInsertedRow = -1;
469
    };
470
471
    this.add("braces", "insertion", function (state, action, editor, session, text) {
472
        var cursor = editor.getCursorPosition();
473
        var line = session.doc.getLine(cursor.row);
474
        if (text == '{') {
475
            var selection = editor.getSelectionRange();
476
            var selected = session.doc.getTextRange(selection);
477
            if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
478
                return {
479
                    text: '{' + selected + '}',
480
                    selection: false
481
                };
482
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
483
                if (/[\]\}\)]/.test(line[cursor.column])) {
484
                    CstyleBehaviour.recordAutoInsert(editor, session, "}");
485
                    return {
486
                        text: '{}',
487
                        selection: [1, 1]
488
                    };
489
                } else {
490
                    CstyleBehaviour.recordMaybeInsert(editor, session, "{");
491
                    return {
492
                        text: '{',
493
                        selection: [1, 1]
494
                    };
495
                }
496
            }
497
        } else if (text == '}') {
498
            var rightChar = line.substring(cursor.column, cursor.column + 1);
499
            if (rightChar == '}') {
500
                var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
501
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
502
                    CstyleBehaviour.popAutoInsertedClosing();
503
                    return {
504
                        text: '',
505
                        selection: [1, 1]
506
                    };
507
                }
508
            }
509
        } else if (text == "\n" || text == "\r\n") {
510
            var closing = "";
511
            if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
512
                closing = lang.stringRepeat("}", maybeInsertedBrackets);
513
                CstyleBehaviour.clearMaybeInsertedClosing();
514
            }
515
            var rightChar = line.substring(cursor.column, cursor.column + 1);
516
            if (rightChar == '}' || closing !== "") {
517
                var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
518
                if (!openBracePos)
519
                     return null;
520
521
                var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
522
                var next_indent = this.$getIndent(line);
523
524
                return {
525
                    text: '\n' + indent + '\n' + next_indent + closing,
526
                    selection: [1, indent.length, 1, indent.length]
527
                };
528
            }
529
        }
530
    });
531
532
    this.add("braces", "deletion", function (state, action, editor, session, range) {
533
        var selected = session.doc.getTextRange(range);
534
        if (!range.isMultiLine() && selected == '{') {
535
            var line = session.doc.getLine(range.start.row);
536
            var rightChar = line.substring(range.end.column, range.end.column + 1);
537
            if (rightChar == '}') {
538
                range.end.column++;
539
                return range;
540
            } else {
541
                maybeInsertedBrackets--;
542
            }
543
        }
544
    });
545
546
    this.add("parens", "insertion", function (state, action, editor, session, text) {
547
        if (text == '(') {
548
            var selection = editor.getSelectionRange();
549
            var selected = session.doc.getTextRange(selection);
550
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
551
                return {
552
                    text: '(' + selected + ')',
553
                    selection: false
554
                };
555
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
556
                CstyleBehaviour.recordAutoInsert(editor, session, ")");
557
                return {
558
                    text: '()',
559
                    selection: [1, 1]
560
                };
561
            }
562
        } else if (text == ')') {
563
            var cursor = editor.getCursorPosition();
564
            var line = session.doc.getLine(cursor.row);
565
            var rightChar = line.substring(cursor.column, cursor.column + 1);
566
            if (rightChar == ')') {
567
                var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
568
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
569
                    CstyleBehaviour.popAutoInsertedClosing();
570
                    return {
571
                        text: '',
572
                        selection: [1, 1]
573
                    };
574
                }
575
            }
576
        }
577
    });
578
579
    this.add("parens", "deletion", function (state, action, editor, session, range) {
580
        var selected = session.doc.getTextRange(range);
581
        if (!range.isMultiLine() && selected == '(') {
582
            var line = session.doc.getLine(range.start.row);
583
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
584
            if (rightChar == ')') {
585
                range.end.column++;
586
                return range;
587
            }
588
        }
589
    });
590
591
    this.add("brackets", "insertion", function (state, action, editor, session, text) {
592
        if (text == '[') {
593
            var selection = editor.getSelectionRange();
594
            var selected = session.doc.getTextRange(selection);
595
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
596
                return {
597
                    text: '[' + selected + ']',
598
                    selection: false
599
                };
600
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
601
                CstyleBehaviour.recordAutoInsert(editor, session, "]");
602
                return {
603
                    text: '[]',
604
                    selection: [1, 1]
605
                };
606
            }
607
        } else if (text == ']') {
608
            var cursor = editor.getCursorPosition();
609
            var line = session.doc.getLine(cursor.row);
610
            var rightChar = line.substring(cursor.column, cursor.column + 1);
611
            if (rightChar == ']') {
612
                var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
613
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
614
                    CstyleBehaviour.popAutoInsertedClosing();
615
                    return {
616
                        text: '',
617
                        selection: [1, 1]
618
                    };
619
                }
620
            }
621
        }
622
    });
623
624
    this.add("brackets", "deletion", function (state, action, editor, session, range) {
625
        var selected = session.doc.getTextRange(range);
626
        if (!range.isMultiLine() && selected == '[') {
627
            var line = session.doc.getLine(range.start.row);
628
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
629
            if (rightChar == ']') {
630
                range.end.column++;
631
                return range;
632
            }
633
        }
634
    });
635
636
    this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
637
        if (text == '"' || text == "'") {
638
            var quote = text;
639
            var selection = editor.getSelectionRange();
640
            var selected = session.doc.getTextRange(selection);
641
            if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
642
                return {
643
                    text: quote + selected + quote,
644
                    selection: false
645
                };
646
            } else {
647
                var cursor = editor.getCursorPosition();
648
                var line = session.doc.getLine(cursor.row);
649
                var leftChar = line.substring(cursor.column-1, cursor.column);
650
                if (leftChar == '\\') {
651
                    return null;
652
                }
653
                var tokens = session.getTokens(selection.start.row);
654
                var col = 0, token;
655
                var quotepos = -1; // Track whether we're inside an open quote.
656
657
                for (var x = 0; x < tokens.length; x++) {
658
                    token = tokens[x];
659
                    if (token.type == "string") {
660
                      quotepos = -1;
661
                    } else if (quotepos < 0) {
662
                      quotepos = token.value.indexOf(quote);
663
                    }
664
                    if ((token.value.length + col) > selection.start.column) {
665
                        break;
666
                    }
667
                    col += tokens[x].value.length;
668
                }
669
                if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
670
                    if (!CstyleBehaviour.isSaneInsertion(editor, session))
671
                        return;
672
                    return {
673
                        text: quote + quote,
674
                        selection: [1,1]
675
                    };
676
                } else if (token && token.type === "string") {
677
                    var rightChar = line.substring(cursor.column, cursor.column + 1);
678
                    if (rightChar == quote) {
679
                        return {
680
                            text: '',
681
                            selection: [1, 1]
682
                        };
683
                    }
684
                }
685
            }
686
        }
687
    });
688
689
    this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
690
        var selected = session.doc.getTextRange(range);
691
        if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
692
            var line = session.doc.getLine(range.start.row);
693
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
694
            if (rightChar == selected) {
695
                range.end.column++;
696
                return range;
697
            }
698
        }
699
    });
700
701
};
702
703
oop.inherits(CstyleBehaviour, Behaviour);
704
705
exports.CstyleBehaviour = CstyleBehaviour;
706
});
707
708
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
709
710
711
var oop = require("../../lib/oop");
712
var Range = require("../../range").Range;
713
var BaseFoldMode = require("./fold_mode").FoldMode;
714
715
var FoldMode = exports.FoldMode = function(commentRegex) {
716
    if (commentRegex) {
717
        this.foldingStartMarker = new RegExp(
718
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
719
        );
720
        this.foldingStopMarker = new RegExp(
721
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
722
        );
723
    }
724
};
725
oop.inherits(FoldMode, BaseFoldMode);
726
727
(function() {
728
729
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
730
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
731
732
    this.getFoldWidgetRange = function(session, foldStyle, row) {
733
        var line = session.getLine(row);
734
        var match = line.match(this.foldingStartMarker);
735
        if (match) {
736
            var i = match.index;
737
738
            if (match[1])
739
                return this.openingBracketBlock(session, match[1], row, i);
740
741
            return session.getCommentFoldRange(row, i + match[0].length, 1);
742
        }
743
744
        if (foldStyle !== "markbeginend")
745
            return;
746
747
        var match = line.match(this.foldingStopMarker);
748
        if (match) {
749
            var i = match.index + match[0].length;
750
751
            if (match[1])
752
                return this.closingBracketBlock(session, match[1], row, i);
753
754
            return session.getCommentFoldRange(row, i, -1);
755
        }
756
    };
757
758
}).call(FoldMode.prototype);
759
760
});
761
762
define('ace/mode/glsl_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/c_cpp_highlight_rules'], function(require, exports, module) {
763
764
765
var oop = require("../lib/oop");
766
var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
767
768
var glslHighlightRules = function() {
769
770
    var keywords = (
771
        "attribute|const|uniform|varying|break|continue|do|for|while|" +
772
        "if|else|in|out|inout|float|int|void|bool|true|false|" +
773
        "lowp|mediump|highp|precision|invariant|discard|return|mat2|mat3|" +
774
        "mat4|vec2|vec3|vec4|ivec2|ivec3|ivec4|bvec2|bvec3|bvec4|sampler2D|" +
775
        "samplerCube|struct"
776
    );
777
778
    var buildinConstants = (
779
        "radians|degrees|sin|cos|tan|asin|acos|atan|pow|" +
780
        "exp|log|exp2|log2|sqrt|inversesqrt|abs|sign|floor|ceil|fract|mod|" +
781
        "min|max|clamp|mix|step|smoothstep|length|distance|dot|cross|" +
782
        "normalize|faceforward|reflect|refract|matrixCompMult|lessThan|" +
783
        "lessThanEqual|greaterThan|greaterThanEqual|equal|notEqual|any|all|" +
784
        "not|dFdx|dFdy|fwidth|texture2D|texture2DProj|texture2DLod|" +
785
        "texture2DProjLod|textureCube|textureCubeLod|" +
786
        "gl_MaxVertexAttribs|gl_MaxVertexUniformVectors|gl_MaxVaryingVectors|" +
787
        "gl_MaxVertexTextureImageUnits|gl_MaxCombinedTextureImageUnits|" +
788
        "gl_MaxTextureImageUnits|gl_MaxFragmentUniformVectors|gl_MaxDrawBuffers|" +
789
        "gl_DepthRangeParameters|gl_DepthRange|" +
790
        "gl_Position|gl_PointSize|" +
791
        "gl_FragCoord|gl_FrontFacing|gl_PointCoord|gl_FragColor|gl_FragData"
792
    );
793
794
    var keywordMapper = this.createKeywordMapper({
795
        "variable.language": "this",
796
        "keyword": keywords,
797
        "constant.language": buildinConstants
798
    }, "identifier");
799
800
    this.$rules = new c_cppHighlightRules().$rules;
801
    this.$rules.start.forEach(function(rule) {
802
        if (typeof rule.token == "function")
803
            rule.token = keywordMapper;
804
    })
805
};
806
807
oop.inherits(glslHighlightRules, c_cppHighlightRules);
808
809
exports.glslHighlightRules = glslHighlightRules;
810
});