/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/js/ace/mode-c_cpp.js

  • Committer: Erik Wikström
  • Date: 2013-04-09 09:21:05 UTC
  • mto: (21.1.1 lenasys)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: wikxen@gmail.com-20130409092105-u1u3gxbql1vx65a7
Added missing WebGL javascript files, moved bothe them and the existing ones to /js. Updated references

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/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) {
32
 
 
33
 
 
34
 
var oop = require("../lib/oop");
35
 
var TextMode = require("./text").Mode;
36
 
var Tokenizer = require("../tokenizer").Tokenizer;
37
 
var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
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 c_cppHighlightRules().getRules());
45
 
    this.$outdent = new MatchingBraceOutdent();
46
 
    this.$behaviour = new CstyleBehaviour();
47
 
    this.foldingRules = new CStyleFoldMode();
48
 
};
49
 
oop.inherits(Mode, TextMode);
50
 
 
51
 
(function() {
52
 
 
53
 
    this.lineCommentStart = "//";
54
 
    this.blockComment = {start: "/*", end: "*/"};
55
 
 
56
 
    this.getNextLineIndent = function(state, line, tab) {
57
 
        var indent = this.$getIndent(line);
58
 
 
59
 
        var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
60
 
        var tokens = tokenizedLine.tokens;
61
 
        var endState = tokenizedLine.state;
62
 
 
63
 
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
64
 
            return indent;
65
 
        }
66
 
 
67
 
        if (state == "start") {
68
 
            var match = line.match(/^.*[\{\(\[]\s*$/);
69
 
            if (match) {
70
 
                indent += tab;
71
 
            }
72
 
        } else if (state == "doc-start") {
73
 
            if (endState == "start") {
74
 
                return "";
75
 
            }
76
 
            var match = line.match(/^\s*(\/?)\*/);
77
 
            if (match) {
78
 
                if (match[1]) {
79
 
                    indent += " ";
80
 
                }
81
 
                indent += "* ";
82
 
            }
83
 
        }
84
 
 
85
 
        return indent;
86
 
    };
87
 
 
88
 
    this.checkOutdent = function(state, line, input) {
89
 
        return this.$outdent.checkOutdent(line, input);
90
 
    };
91
 
 
92
 
    this.autoOutdent = function(state, doc, row) {
93
 
        this.$outdent.autoOutdent(doc, row);
94
 
    };
95
 
 
96
 
}).call(Mode.prototype);
97
 
 
98
 
exports.Mode = Mode;
99
 
});
100
 
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) {
101
 
 
102
 
 
103
 
var oop = require("../lib/oop");
104
 
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
105
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
106
 
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"
107
 
 
108
 
var c_cppHighlightRules = function() {
109
 
 
110
 
    var keywordControls = (
111
 
        "break|case|continue|default|do|else|for|goto|if|_Pragma|" +
112
 
        "return|switch|while|catch|operator|try|throw|using"
113
 
    );
114
 
    
115
 
    var storageType = (
116
 
        "asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" +
117
 
        "_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void|" +
118
 
        "class|wchar_t|template"
119
 
    );
120
 
 
121
 
    var storageModifiers = (
122
 
        "const|extern|register|restrict|static|volatile|inline|private:|" +
123
 
        "protected:|public:|friend|explicit|virtual|export|mutable|typename"
124
 
    );
125
 
 
126
 
    var keywordOperators = (
127
 
        "and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|typeid|xor|xor_eq" +
128
 
        "const_cast|dynamic_cast|reinterpret_cast|static_cast|sizeof|namespace"
129
 
    );
130
 
 
131
 
    var builtinConstants = (
132
 
        "NULL|true|false|TRUE|FALSE"
133
 
    );
134
 
 
135
 
    var keywordMapper = this.$keywords = this.createKeywordMapper({
136
 
        "keyword.control" : keywordControls,
137
 
        "storage.type" : storageType,
138
 
        "storage.modifier" : storageModifiers,
139
 
        "keyword.operator" : keywordOperators,
140
 
        "variable.language": "this",
141
 
        "constant.language": builtinConstants
142
 
    }, "identifier");
143
 
 
144
 
    var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\d\\$_\u00a1-\uffff]*\\b";
145
 
 
146
 
    this.$rules = {
147
 
        "start" : [
148
 
            {
149
 
                token : "comment",
150
 
                regex : "\\/\\/.*$"
151
 
            },
152
 
            DocCommentHighlightRules.getStartRule("doc-start"),
153
 
            {
154
 
                token : "comment", // multi line comment
155
 
                regex : "\\/\\*",
156
 
                next : "comment"
157
 
            }, {
158
 
                token : "string", // single line
159
 
                regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
160
 
            }, {
161
 
                token : "string", // multi line string start
162
 
                regex : '["].*\\\\$',
163
 
                next : "qqstring"
164
 
            }, {
165
 
                token : "string", // single line
166
 
                regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
167
 
            }, {
168
 
                token : "string", // multi line string start
169
 
                regex : "['].*\\\\$",
170
 
                next : "qstring"
171
 
            }, {
172
 
                token : "constant.numeric", // hex
173
 
                regex : "0[xX][0-9a-fA-F]+\\b"
174
 
            }, {
175
 
                token : "constant.numeric", // float
176
 
                regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
177
 
            }, {
178
 
                token : "keyword", // pre-compiler directives
179
 
                regex : "(?:#include|#import|#pragma|#line|#define|#undef|#if|#ifdef|#else|#elif|#ifndef)\\b",
180
 
                next  : "directive"
181
 
            }, {
182
 
                token : "keyword", // special case pre-compiler directive
183
 
                regex : "(?:#endif)\\b"
184
 
            }, {
185
 
                token : "support.function.C99.c",
186
 
                regex : cFunctions
187
 
            }, {
188
 
                token : keywordMapper,
189
 
                regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
190
 
            }, {
191
 
                token : "keyword.operator",
192
 
                regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)"
193
 
            }, {
194
 
              token : "punctuation.operator",
195
 
              regex : "\\?|\\:|\\,|\\;|\\."
196
 
            }, {
197
 
                token : "paren.lparen",
198
 
                regex : "[[({]"
199
 
            }, {
200
 
                token : "paren.rparen",
201
 
                regex : "[\\])}]"
202
 
            }, {
203
 
                token : "text",
204
 
                regex : "\\s+"
205
 
            }
206
 
        ],
207
 
        "comment" : [
208
 
            {
209
 
                token : "comment", // closing comment
210
 
                regex : ".*?\\*\\/",
211
 
                next : "start"
212
 
            }, {
213
 
                token : "comment", // comment spanning whole line
214
 
                regex : ".+"
215
 
            }
216
 
        ],
217
 
        "qqstring" : [
218
 
            {
219
 
                token : "string",
220
 
                regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
221
 
                next : "start"
222
 
            }, {
223
 
                token : "string",
224
 
                regex : '.+'
225
 
            }
226
 
        ],
227
 
        "qstring" : [
228
 
            {
229
 
                token : "string",
230
 
                regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
231
 
                next : "start"
232
 
            }, {
233
 
                token : "string",
234
 
                regex : '.+'
235
 
            }
236
 
        ],
237
 
        "directive" : [
238
 
            {
239
 
                token : "constant.other.multiline",
240
 
                regex : /\\/
241
 
            },
242
 
            {
243
 
                token : "constant.other.multiline",
244
 
                regex : /.*\\/
245
 
            },
246
 
            {
247
 
                token : "constant.other",
248
 
                regex : "\\s*<.+?>",
249
 
                next : "start"
250
 
            },
251
 
            {
252
 
                token : "constant.other", // single line
253
 
                regex : '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
254
 
                next : "start"
255
 
            }, 
256
 
            {
257
 
                token : "constant.other", // single line
258
 
                regex : "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
259
 
                next : "start"
260
 
            },
261
 
            {
262
 
                token : "constant.other",
263
 
                regex : /[^\\\/]+/,
264
 
                next : "start"
265
 
            }
266
 
        ]
267
 
    };
268
 
 
269
 
    this.embedRules(DocCommentHighlightRules, "doc-",
270
 
        [ DocCommentHighlightRules.getEndRule("start") ]);
271
 
};
272
 
 
273
 
oop.inherits(c_cppHighlightRules, TextHighlightRules);
274
 
 
275
 
exports.c_cppHighlightRules = c_cppHighlightRules;
276
 
});
277
 
 
278
 
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
279
 
 
280
 
 
281
 
var oop = require("../lib/oop");
282
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
283
 
 
284
 
var DocCommentHighlightRules = function() {
285
 
 
286
 
    this.$rules = {
287
 
        "start" : [ {
288
 
            token : "comment.doc.tag",
289
 
            regex : "@[\\w\\d_]+" // TODO: fix email addresses
290
 
        }, {
291
 
            token : "comment.doc.tag",
292
 
            regex : "\\bTODO\\b"
293
 
        }, {
294
 
            defaultToken : "comment.doc"
295
 
        }]
296
 
    };
297
 
};
298
 
 
299
 
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
300
 
 
301
 
DocCommentHighlightRules.getStartRule = function(start) {
302
 
    return {
303
 
        token : "comment.doc", // doc comment
304
 
        regex : "\\/\\*(?=\\*)",
305
 
        next  : start
306
 
    };
307
 
};
308
 
 
309
 
DocCommentHighlightRules.getEndRule = function (start) {
310
 
    return {
311
 
        token : "comment.doc", // closing comment
312
 
        regex : "\\*\\/",
313
 
        next  : start
314
 
    };
315
 
};
316
 
 
317
 
 
318
 
exports.DocCommentHighlightRules = DocCommentHighlightRules;
319
 
 
320
 
});
321
 
 
322
 
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
323
 
 
324
 
 
325
 
var Range = require("../range").Range;
326
 
 
327
 
var MatchingBraceOutdent = function() {};
328
 
 
329
 
(function() {
330
 
 
331
 
    this.checkOutdent = function(line, input) {
332
 
        if (! /^\s+$/.test(line))
333
 
            return false;
334
 
 
335
 
        return /^\s*\}/.test(input);
336
 
    };
337
 
 
338
 
    this.autoOutdent = function(doc, row) {
339
 
        var line = doc.getLine(row);
340
 
        var match = line.match(/^(\s*\})/);
341
 
 
342
 
        if (!match) return 0;
343
 
 
344
 
        var column = match[1].length;
345
 
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
346
 
 
347
 
        if (!openBracePos || openBracePos.row == row) return 0;
348
 
 
349
 
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
350
 
        doc.replace(new Range(row, 0, row, column-1), indent);
351
 
    };
352
 
 
353
 
    this.$getIndent = function(line) {
354
 
        return line.match(/^\s*/)[0];
355
 
    };
356
 
 
357
 
}).call(MatchingBraceOutdent.prototype);
358
 
 
359
 
exports.MatchingBraceOutdent = MatchingBraceOutdent;
360
 
});
361
 
 
362
 
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
363
 
 
364
 
 
365
 
var oop = require("../../lib/oop");
366
 
var Behaviour = require("../behaviour").Behaviour;
367
 
var TokenIterator = require("../../token_iterator").TokenIterator;
368
 
var lang = require("../../lib/lang");
369
 
 
370
 
var SAFE_INSERT_IN_TOKENS =
371
 
    ["text", "paren.rparen", "punctuation.operator"];
372
 
var SAFE_INSERT_BEFORE_TOKENS =
373
 
    ["text", "paren.rparen", "punctuation.operator", "comment"];
374
 
 
375
 
 
376
 
var autoInsertedBrackets = 0;
377
 
var autoInsertedRow = -1;
378
 
var autoInsertedLineEnd = "";
379
 
var maybeInsertedBrackets = 0;
380
 
var maybeInsertedRow = -1;
381
 
var maybeInsertedLineStart = "";
382
 
var maybeInsertedLineEnd = "";
383
 
 
384
 
var CstyleBehaviour = function () {
385
 
    
386
 
    CstyleBehaviour.isSaneInsertion = function(editor, session) {
387
 
        var cursor = editor.getCursorPosition();
388
 
        var iterator = new TokenIterator(session, cursor.row, cursor.column);
389
 
        if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
390
 
            var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
391
 
            if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
392
 
                return false;
393
 
        }
394
 
        iterator.stepForward();
395
 
        return iterator.getCurrentTokenRow() !== cursor.row ||
396
 
            this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
397
 
    };
398
 
    
399
 
    CstyleBehaviour.$matchTokenType = function(token, types) {
400
 
        return types.indexOf(token.type || token) > -1;
401
 
    };
402
 
    
403
 
    CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
404
 
        var cursor = editor.getCursorPosition();
405
 
        var line = session.doc.getLine(cursor.row);
406
 
        if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
407
 
            autoInsertedBrackets = 0;
408
 
        autoInsertedRow = cursor.row;
409
 
        autoInsertedLineEnd = bracket + line.substr(cursor.column);
410
 
        autoInsertedBrackets++;
411
 
    };
412
 
    
413
 
    CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
414
 
        var cursor = editor.getCursorPosition();
415
 
        var line = session.doc.getLine(cursor.row);
416
 
        if (!this.isMaybeInsertedClosing(cursor, line))
417
 
            maybeInsertedBrackets = 0;
418
 
        maybeInsertedRow = cursor.row;
419
 
        maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
420
 
        maybeInsertedLineEnd = line.substr(cursor.column);
421
 
        maybeInsertedBrackets++;
422
 
    };
423
 
    
424
 
    CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
425
 
        return autoInsertedBrackets > 0 &&
426
 
            cursor.row === autoInsertedRow &&
427
 
            bracket === autoInsertedLineEnd[0] &&
428
 
            line.substr(cursor.column) === autoInsertedLineEnd;
429
 
    };
430
 
    
431
 
    CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
432
 
        return maybeInsertedBrackets > 0 &&
433
 
            cursor.row === maybeInsertedRow &&
434
 
            line.substr(cursor.column) === maybeInsertedLineEnd &&
435
 
            line.substr(0, cursor.column) == maybeInsertedLineStart;
436
 
    };
437
 
    
438
 
    CstyleBehaviour.popAutoInsertedClosing = function() {
439
 
        autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
440
 
        autoInsertedBrackets--;
441
 
    };
442
 
    
443
 
    CstyleBehaviour.clearMaybeInsertedClosing = function() {
444
 
        maybeInsertedBrackets = 0;
445
 
        maybeInsertedRow = -1;
446
 
    };
447
 
 
448
 
    this.add("braces", "insertion", function (state, action, editor, session, text) {
449
 
        var cursor = editor.getCursorPosition();
450
 
        var line = session.doc.getLine(cursor.row);
451
 
        if (text == '{') {
452
 
            var selection = editor.getSelectionRange();
453
 
            var selected = session.doc.getTextRange(selection);
454
 
            if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
455
 
                return {
456
 
                    text: '{' + selected + '}',
457
 
                    selection: false
458
 
                };
459
 
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
460
 
                if (/[\]\}\)]/.test(line[cursor.column])) {
461
 
                    CstyleBehaviour.recordAutoInsert(editor, session, "}");
462
 
                    return {
463
 
                        text: '{}',
464
 
                        selection: [1, 1]
465
 
                    };
466
 
                } else {
467
 
                    CstyleBehaviour.recordMaybeInsert(editor, session, "{");
468
 
                    return {
469
 
                        text: '{',
470
 
                        selection: [1, 1]
471
 
                    };
472
 
                }
473
 
            }
474
 
        } else if (text == '}') {
475
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
476
 
            if (rightChar == '}') {
477
 
                var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
478
 
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
479
 
                    CstyleBehaviour.popAutoInsertedClosing();
480
 
                    return {
481
 
                        text: '',
482
 
                        selection: [1, 1]
483
 
                    };
484
 
                }
485
 
            }
486
 
        } else if (text == "\n" || text == "\r\n") {
487
 
            var closing = "";
488
 
            if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
489
 
                closing = lang.stringRepeat("}", maybeInsertedBrackets);
490
 
                CstyleBehaviour.clearMaybeInsertedClosing();
491
 
            }
492
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
493
 
            if (rightChar == '}' || closing !== "") {
494
 
                var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
495
 
                if (!openBracePos)
496
 
                     return null;
497
 
 
498
 
                var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
499
 
                var next_indent = this.$getIndent(line);
500
 
 
501
 
                return {
502
 
                    text: '\n' + indent + '\n' + next_indent + closing,
503
 
                    selection: [1, indent.length, 1, indent.length]
504
 
                };
505
 
            }
506
 
        }
507
 
    });
508
 
 
509
 
    this.add("braces", "deletion", function (state, action, editor, session, range) {
510
 
        var selected = session.doc.getTextRange(range);
511
 
        if (!range.isMultiLine() && selected == '{') {
512
 
            var line = session.doc.getLine(range.start.row);
513
 
            var rightChar = line.substring(range.end.column, range.end.column + 1);
514
 
            if (rightChar == '}') {
515
 
                range.end.column++;
516
 
                return range;
517
 
            } else {
518
 
                maybeInsertedBrackets--;
519
 
            }
520
 
        }
521
 
    });
522
 
 
523
 
    this.add("parens", "insertion", function (state, action, editor, session, text) {
524
 
        if (text == '(') {
525
 
            var selection = editor.getSelectionRange();
526
 
            var selected = session.doc.getTextRange(selection);
527
 
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
528
 
                return {
529
 
                    text: '(' + selected + ')',
530
 
                    selection: false
531
 
                };
532
 
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
533
 
                CstyleBehaviour.recordAutoInsert(editor, session, ")");
534
 
                return {
535
 
                    text: '()',
536
 
                    selection: [1, 1]
537
 
                };
538
 
            }
539
 
        } else if (text == ')') {
540
 
            var cursor = editor.getCursorPosition();
541
 
            var line = session.doc.getLine(cursor.row);
542
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
543
 
            if (rightChar == ')') {
544
 
                var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
545
 
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
546
 
                    CstyleBehaviour.popAutoInsertedClosing();
547
 
                    return {
548
 
                        text: '',
549
 
                        selection: [1, 1]
550
 
                    };
551
 
                }
552
 
            }
553
 
        }
554
 
    });
555
 
 
556
 
    this.add("parens", "deletion", function (state, action, editor, session, range) {
557
 
        var selected = session.doc.getTextRange(range);
558
 
        if (!range.isMultiLine() && selected == '(') {
559
 
            var line = session.doc.getLine(range.start.row);
560
 
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
561
 
            if (rightChar == ')') {
562
 
                range.end.column++;
563
 
                return range;
564
 
            }
565
 
        }
566
 
    });
567
 
 
568
 
    this.add("brackets", "insertion", function (state, action, editor, session, text) {
569
 
        if (text == '[') {
570
 
            var selection = editor.getSelectionRange();
571
 
            var selected = session.doc.getTextRange(selection);
572
 
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
573
 
                return {
574
 
                    text: '[' + selected + ']',
575
 
                    selection: false
576
 
                };
577
 
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
578
 
                CstyleBehaviour.recordAutoInsert(editor, session, "]");
579
 
                return {
580
 
                    text: '[]',
581
 
                    selection: [1, 1]
582
 
                };
583
 
            }
584
 
        } else if (text == ']') {
585
 
            var cursor = editor.getCursorPosition();
586
 
            var line = session.doc.getLine(cursor.row);
587
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
588
 
            if (rightChar == ']') {
589
 
                var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
590
 
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
591
 
                    CstyleBehaviour.popAutoInsertedClosing();
592
 
                    return {
593
 
                        text: '',
594
 
                        selection: [1, 1]
595
 
                    };
596
 
                }
597
 
            }
598
 
        }
599
 
    });
600
 
 
601
 
    this.add("brackets", "deletion", function (state, action, editor, session, range) {
602
 
        var selected = session.doc.getTextRange(range);
603
 
        if (!range.isMultiLine() && selected == '[') {
604
 
            var line = session.doc.getLine(range.start.row);
605
 
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
606
 
            if (rightChar == ']') {
607
 
                range.end.column++;
608
 
                return range;
609
 
            }
610
 
        }
611
 
    });
612
 
 
613
 
    this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
614
 
        if (text == '"' || text == "'") {
615
 
            var quote = text;
616
 
            var selection = editor.getSelectionRange();
617
 
            var selected = session.doc.getTextRange(selection);
618
 
            if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
619
 
                return {
620
 
                    text: quote + selected + quote,
621
 
                    selection: false
622
 
                };
623
 
            } else {
624
 
                var cursor = editor.getCursorPosition();
625
 
                var line = session.doc.getLine(cursor.row);
626
 
                var leftChar = line.substring(cursor.column-1, cursor.column);
627
 
                if (leftChar == '\\') {
628
 
                    return null;
629
 
                }
630
 
                var tokens = session.getTokens(selection.start.row);
631
 
                var col = 0, token;
632
 
                var quotepos = -1; // Track whether we're inside an open quote.
633
 
 
634
 
                for (var x = 0; x < tokens.length; x++) {
635
 
                    token = tokens[x];
636
 
                    if (token.type == "string") {
637
 
                      quotepos = -1;
638
 
                    } else if (quotepos < 0) {
639
 
                      quotepos = token.value.indexOf(quote);
640
 
                    }
641
 
                    if ((token.value.length + col) > selection.start.column) {
642
 
                        break;
643
 
                    }
644
 
                    col += tokens[x].value.length;
645
 
                }
646
 
                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)))) {
647
 
                    if (!CstyleBehaviour.isSaneInsertion(editor, session))
648
 
                        return;
649
 
                    return {
650
 
                        text: quote + quote,
651
 
                        selection: [1,1]
652
 
                    };
653
 
                } else if (token && token.type === "string") {
654
 
                    var rightChar = line.substring(cursor.column, cursor.column + 1);
655
 
                    if (rightChar == quote) {
656
 
                        return {
657
 
                            text: '',
658
 
                            selection: [1, 1]
659
 
                        };
660
 
                    }
661
 
                }
662
 
            }
663
 
        }
664
 
    });
665
 
 
666
 
    this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
667
 
        var selected = session.doc.getTextRange(range);
668
 
        if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
669
 
            var line = session.doc.getLine(range.start.row);
670
 
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
671
 
            if (rightChar == selected) {
672
 
                range.end.column++;
673
 
                return range;
674
 
            }
675
 
        }
676
 
    });
677
 
 
678
 
};
679
 
 
680
 
oop.inherits(CstyleBehaviour, Behaviour);
681
 
 
682
 
exports.CstyleBehaviour = CstyleBehaviour;
683
 
});
684
 
 
685
 
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
686
 
 
687
 
 
688
 
var oop = require("../../lib/oop");
689
 
var Range = require("../../range").Range;
690
 
var BaseFoldMode = require("./fold_mode").FoldMode;
691
 
 
692
 
var FoldMode = exports.FoldMode = function(commentRegex) {
693
 
    if (commentRegex) {
694
 
        this.foldingStartMarker = new RegExp(
695
 
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
696
 
        );
697
 
        this.foldingStopMarker = new RegExp(
698
 
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
699
 
        );
700
 
    }
701
 
};
702
 
oop.inherits(FoldMode, BaseFoldMode);
703
 
 
704
 
(function() {
705
 
 
706
 
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
707
 
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
708
 
 
709
 
    this.getFoldWidgetRange = function(session, foldStyle, row) {
710
 
        var line = session.getLine(row);
711
 
        var match = line.match(this.foldingStartMarker);
712
 
        if (match) {
713
 
            var i = match.index;
714
 
 
715
 
            if (match[1])
716
 
                return this.openingBracketBlock(session, match[1], row, i);
717
 
 
718
 
            return session.getCommentFoldRange(row, i + match[0].length, 1);
719
 
        }
720
 
 
721
 
        if (foldStyle !== "markbeginend")
722
 
            return;
723
 
 
724
 
        var match = line.match(this.foldingStopMarker);
725
 
        if (match) {
726
 
            var i = match.index + match[0].length;
727
 
 
728
 
            if (match[1])
729
 
                return this.closingBracketBlock(session, match[1], row, i);
730
 
 
731
 
            return session.getCommentFoldRange(row, i, -1);
732
 
        }
733
 
    };
734
 
 
735
 
}).call(FoldMode.prototype);
736
 
 
737
 
});