/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 js/ace/mode-jsx.js

  • Committer: Erik Wikström
  • Date: 2013-03-28 07:43:18 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: wikxen@gmail.com-20130328074318-9v6krijkyap59nct
Removed trunk folder and moved its contents to the root

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
define('ace/mode/jsx', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/jsx_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
2
 
 
3
 
 
4
 
var oop = require("../lib/oop");
5
 
var TextMode = require("./text").Mode;
6
 
var Tokenizer = require("../tokenizer").Tokenizer;
7
 
var JsxHighlightRules = require("./jsx_highlight_rules").JsxHighlightRules;
8
 
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
9
 
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
10
 
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
11
 
 
12
 
function Mode() {
13
 
    this.$tokenizer = new Tokenizer(new JsxHighlightRules().getRules());
14
 
    this.$outdent = new MatchingBraceOutdent();
15
 
    this.$behaviour = new CstyleBehaviour();
16
 
    this.foldingRules = new CStyleFoldMode();
17
 
}
18
 
oop.inherits(Mode, TextMode);
19
 
 
20
 
(function() {
21
 
 
22
 
    this.lineCommentStart = "//";
23
 
    this.blockComment = {start: "/*", end: "*/"};
24
 
 
25
 
    this.getNextLineIndent = function(state, line, tab) {
26
 
        var indent = this.$getIndent(line);
27
 
 
28
 
        var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
29
 
        var tokens = tokenizedLine.tokens;
30
 
 
31
 
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
32
 
            return indent;
33
 
        }
34
 
 
35
 
        if (state == "start") {
36
 
            var match = line.match(/^.*[\{\(\[]\s*$/);
37
 
            if (match) {
38
 
                indent += tab;
39
 
            }
40
 
        }
41
 
 
42
 
        return indent;
43
 
    };
44
 
 
45
 
    this.checkOutdent = function(state, line, input) {
46
 
        return this.$outdent.checkOutdent(line, input);
47
 
    };
48
 
 
49
 
    this.autoOutdent = function(state, doc, row) {
50
 
        this.$outdent.autoOutdent(doc, row);
51
 
    };
52
 
 
53
 
}).call(Mode.prototype);
54
 
 
55
 
exports.Mode = Mode;
56
 
});
57
 
define('ace/mode/jsx_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
58
 
var oop = require("../lib/oop");
59
 
var lang = require("../lib/lang");
60
 
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
61
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
62
 
 
63
 
var JsxHighlightRules = function() {
64
 
    var keywords = lang.arrayToMap(
65
 
        ("break|do|instanceof|typeof|case|else|new|var|catch|finally|return|void|continue|for|switch|default|while|function|this|" +
66
 
         "if|throw|" +
67
 
         "delete|in|try|" +
68
 
         "class|extends|super|import|from|into|implements|interface|static|mixin|override|abstract|final|" +
69
 
         "number|int|string|boolean|variant|" +
70
 
         "log|assert").split("|")
71
 
    );
72
 
    
73
 
    var buildinConstants = lang.arrayToMap(
74
 
        ("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
75
 
    );
76
 
    
77
 
    var reserved = lang.arrayToMap(
78
 
        ("debugger|with|" +
79
 
         "const|export|" +
80
 
         "let|private|public|yield|protected|" +
81
 
         "extern|native|as|operator|__fake__|__readonly__").split("|")
82
 
    );
83
 
    
84
 
    var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
85
 
    
86
 
    this.$rules = {
87
 
        "start" : [
88
 
            {
89
 
                token : "comment",
90
 
                regex : "\\/\\/.*$"
91
 
            },
92
 
            DocCommentHighlightRules.getStartRule("doc-start"),
93
 
            {
94
 
                token : "comment", // multi line comment
95
 
                regex : "\\/\\*",
96
 
                next : "comment"
97
 
            }, {
98
 
                token : "string.regexp",
99
 
                regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
100
 
            }, {
101
 
                token : "string", // single line
102
 
                regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
103
 
            }, {
104
 
                token : "string", // single line
105
 
                regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
106
 
            }, {
107
 
                token : "constant.numeric", // hex
108
 
                regex : "0[xX][0-9a-fA-F]+\\b"
109
 
            }, {
110
 
                token : "constant.numeric", // float
111
 
                regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
112
 
            }, {
113
 
                token : "constant.language.boolean",
114
 
                regex : "(?:true|false)\\b"
115
 
            }, {
116
 
                token : [
117
 
                    "storage.type",
118
 
                    "text",
119
 
                    "entity.name.function"
120
 
                ],
121
 
                regex : "(function)(\\s+)(" + identifierRe + ")"
122
 
            }, {
123
 
                token : function(value) {
124
 
                    if (value == "this")
125
 
                        return "variable.language";
126
 
                    else if (value == "function")
127
 
                        return "storage.type";
128
 
                    else if (keywords.hasOwnProperty(value) || reserved.hasOwnProperty(value))
129
 
                        return "keyword";
130
 
                    else if (buildinConstants.hasOwnProperty(value))
131
 
                        return "constant.language";
132
 
                    else if (/^_?[A-Z][a-zA-Z0-9_]*$/.test(value))
133
 
                        return "language.support.class";
134
 
                    else
135
 
                        return "identifier";
136
 
                },
137
 
                regex : identifierRe
138
 
            }, {
139
 
                token : "keyword.operator",
140
 
                regex : "!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
141
 
            }, {
142
 
                token : "punctuation.operator",
143
 
                regex : "\\?|\\:|\\,|\\;|\\."
144
 
            }, {
145
 
                token : "paren.lparen",
146
 
                regex : "[[({<]"
147
 
            }, {
148
 
                token : "paren.rparen",
149
 
                regex : "[\\])}>]"
150
 
            }, {
151
 
                token : "text",
152
 
                regex : "\\s+"
153
 
            }
154
 
        ],
155
 
        "comment" : [
156
 
            {
157
 
                token : "comment", // closing comment
158
 
                regex : ".*?\\*\\/",
159
 
                next : "start"
160
 
            }, {
161
 
                token : "comment", // comment spanning whole line
162
 
                regex : ".+"
163
 
            }
164
 
        ]
165
 
    };
166
 
    
167
 
    this.embedRules(DocCommentHighlightRules, "doc-",
168
 
        [ DocCommentHighlightRules.getEndRule("start") ]);
169
 
};
170
 
 
171
 
oop.inherits(JsxHighlightRules, TextHighlightRules);
172
 
 
173
 
exports.JsxHighlightRules = JsxHighlightRules;
174
 
});
175
 
 
176
 
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
177
 
 
178
 
 
179
 
var oop = require("../lib/oop");
180
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
181
 
 
182
 
var DocCommentHighlightRules = function() {
183
 
 
184
 
    this.$rules = {
185
 
        "start" : [ {
186
 
            token : "comment.doc.tag",
187
 
            regex : "@[\\w\\d_]+" // TODO: fix email addresses
188
 
        }, {
189
 
            token : "comment.doc.tag",
190
 
            regex : "\\bTODO\\b"
191
 
        }, {
192
 
            defaultToken : "comment.doc"
193
 
        }]
194
 
    };
195
 
};
196
 
 
197
 
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
198
 
 
199
 
DocCommentHighlightRules.getStartRule = function(start) {
200
 
    return {
201
 
        token : "comment.doc", // doc comment
202
 
        regex : "\\/\\*(?=\\*)",
203
 
        next  : start
204
 
    };
205
 
};
206
 
 
207
 
DocCommentHighlightRules.getEndRule = function (start) {
208
 
    return {
209
 
        token : "comment.doc", // closing comment
210
 
        regex : "\\*\\/",
211
 
        next  : start
212
 
    };
213
 
};
214
 
 
215
 
 
216
 
exports.DocCommentHighlightRules = DocCommentHighlightRules;
217
 
 
218
 
});
219
 
 
220
 
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
221
 
 
222
 
 
223
 
var Range = require("../range").Range;
224
 
 
225
 
var MatchingBraceOutdent = function() {};
226
 
 
227
 
(function() {
228
 
 
229
 
    this.checkOutdent = function(line, input) {
230
 
        if (! /^\s+$/.test(line))
231
 
            return false;
232
 
 
233
 
        return /^\s*\}/.test(input);
234
 
    };
235
 
 
236
 
    this.autoOutdent = function(doc, row) {
237
 
        var line = doc.getLine(row);
238
 
        var match = line.match(/^(\s*\})/);
239
 
 
240
 
        if (!match) return 0;
241
 
 
242
 
        var column = match[1].length;
243
 
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
244
 
 
245
 
        if (!openBracePos || openBracePos.row == row) return 0;
246
 
 
247
 
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
248
 
        doc.replace(new Range(row, 0, row, column-1), indent);
249
 
    };
250
 
 
251
 
    this.$getIndent = function(line) {
252
 
        return line.match(/^\s*/)[0];
253
 
    };
254
 
 
255
 
}).call(MatchingBraceOutdent.prototype);
256
 
 
257
 
exports.MatchingBraceOutdent = MatchingBraceOutdent;
258
 
});
259
 
 
260
 
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
261
 
 
262
 
 
263
 
var oop = require("../../lib/oop");
264
 
var Behaviour = require("../behaviour").Behaviour;
265
 
var TokenIterator = require("../../token_iterator").TokenIterator;
266
 
var lang = require("../../lib/lang");
267
 
 
268
 
var SAFE_INSERT_IN_TOKENS =
269
 
    ["text", "paren.rparen", "punctuation.operator"];
270
 
var SAFE_INSERT_BEFORE_TOKENS =
271
 
    ["text", "paren.rparen", "punctuation.operator", "comment"];
272
 
 
273
 
 
274
 
var autoInsertedBrackets = 0;
275
 
var autoInsertedRow = -1;
276
 
var autoInsertedLineEnd = "";
277
 
var maybeInsertedBrackets = 0;
278
 
var maybeInsertedRow = -1;
279
 
var maybeInsertedLineStart = "";
280
 
var maybeInsertedLineEnd = "";
281
 
 
282
 
var CstyleBehaviour = function () {
283
 
    
284
 
    CstyleBehaviour.isSaneInsertion = function(editor, session) {
285
 
        var cursor = editor.getCursorPosition();
286
 
        var iterator = new TokenIterator(session, cursor.row, cursor.column);
287
 
        if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
288
 
            var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
289
 
            if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
290
 
                return false;
291
 
        }
292
 
        iterator.stepForward();
293
 
        return iterator.getCurrentTokenRow() !== cursor.row ||
294
 
            this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
295
 
    };
296
 
    
297
 
    CstyleBehaviour.$matchTokenType = function(token, types) {
298
 
        return types.indexOf(token.type || token) > -1;
299
 
    };
300
 
    
301
 
    CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
302
 
        var cursor = editor.getCursorPosition();
303
 
        var line = session.doc.getLine(cursor.row);
304
 
        if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
305
 
            autoInsertedBrackets = 0;
306
 
        autoInsertedRow = cursor.row;
307
 
        autoInsertedLineEnd = bracket + line.substr(cursor.column);
308
 
        autoInsertedBrackets++;
309
 
    };
310
 
    
311
 
    CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
312
 
        var cursor = editor.getCursorPosition();
313
 
        var line = session.doc.getLine(cursor.row);
314
 
        if (!this.isMaybeInsertedClosing(cursor, line))
315
 
            maybeInsertedBrackets = 0;
316
 
        maybeInsertedRow = cursor.row;
317
 
        maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
318
 
        maybeInsertedLineEnd = line.substr(cursor.column);
319
 
        maybeInsertedBrackets++;
320
 
    };
321
 
    
322
 
    CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
323
 
        return autoInsertedBrackets > 0 &&
324
 
            cursor.row === autoInsertedRow &&
325
 
            bracket === autoInsertedLineEnd[0] &&
326
 
            line.substr(cursor.column) === autoInsertedLineEnd;
327
 
    };
328
 
    
329
 
    CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
330
 
        return maybeInsertedBrackets > 0 &&
331
 
            cursor.row === maybeInsertedRow &&
332
 
            line.substr(cursor.column) === maybeInsertedLineEnd &&
333
 
            line.substr(0, cursor.column) == maybeInsertedLineStart;
334
 
    };
335
 
    
336
 
    CstyleBehaviour.popAutoInsertedClosing = function() {
337
 
        autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
338
 
        autoInsertedBrackets--;
339
 
    };
340
 
    
341
 
    CstyleBehaviour.clearMaybeInsertedClosing = function() {
342
 
        maybeInsertedBrackets = 0;
343
 
        maybeInsertedRow = -1;
344
 
    };
345
 
 
346
 
    this.add("braces", "insertion", function (state, action, editor, session, text) {
347
 
        var cursor = editor.getCursorPosition();
348
 
        var line = session.doc.getLine(cursor.row);
349
 
        if (text == '{') {
350
 
            var selection = editor.getSelectionRange();
351
 
            var selected = session.doc.getTextRange(selection);
352
 
            if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
353
 
                return {
354
 
                    text: '{' + selected + '}',
355
 
                    selection: false
356
 
                };
357
 
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
358
 
                if (/[\]\}\)]/.test(line[cursor.column])) {
359
 
                    CstyleBehaviour.recordAutoInsert(editor, session, "}");
360
 
                    return {
361
 
                        text: '{}',
362
 
                        selection: [1, 1]
363
 
                    };
364
 
                } else {
365
 
                    CstyleBehaviour.recordMaybeInsert(editor, session, "{");
366
 
                    return {
367
 
                        text: '{',
368
 
                        selection: [1, 1]
369
 
                    };
370
 
                }
371
 
            }
372
 
        } else if (text == '}') {
373
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
374
 
            if (rightChar == '}') {
375
 
                var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
376
 
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
377
 
                    CstyleBehaviour.popAutoInsertedClosing();
378
 
                    return {
379
 
                        text: '',
380
 
                        selection: [1, 1]
381
 
                    };
382
 
                }
383
 
            }
384
 
        } else if (text == "\n" || text == "\r\n") {
385
 
            var closing = "";
386
 
            if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
387
 
                closing = lang.stringRepeat("}", maybeInsertedBrackets);
388
 
                CstyleBehaviour.clearMaybeInsertedClosing();
389
 
            }
390
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
391
 
            if (rightChar == '}' || closing !== "") {
392
 
                var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
393
 
                if (!openBracePos)
394
 
                     return null;
395
 
 
396
 
                var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
397
 
                var next_indent = this.$getIndent(line);
398
 
 
399
 
                return {
400
 
                    text: '\n' + indent + '\n' + next_indent + closing,
401
 
                    selection: [1, indent.length, 1, indent.length]
402
 
                };
403
 
            }
404
 
        }
405
 
    });
406
 
 
407
 
    this.add("braces", "deletion", function (state, action, editor, session, range) {
408
 
        var selected = session.doc.getTextRange(range);
409
 
        if (!range.isMultiLine() && selected == '{') {
410
 
            var line = session.doc.getLine(range.start.row);
411
 
            var rightChar = line.substring(range.end.column, range.end.column + 1);
412
 
            if (rightChar == '}') {
413
 
                range.end.column++;
414
 
                return range;
415
 
            } else {
416
 
                maybeInsertedBrackets--;
417
 
            }
418
 
        }
419
 
    });
420
 
 
421
 
    this.add("parens", "insertion", function (state, action, editor, session, text) {
422
 
        if (text == '(') {
423
 
            var selection = editor.getSelectionRange();
424
 
            var selected = session.doc.getTextRange(selection);
425
 
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
426
 
                return {
427
 
                    text: '(' + selected + ')',
428
 
                    selection: false
429
 
                };
430
 
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
431
 
                CstyleBehaviour.recordAutoInsert(editor, session, ")");
432
 
                return {
433
 
                    text: '()',
434
 
                    selection: [1, 1]
435
 
                };
436
 
            }
437
 
        } else if (text == ')') {
438
 
            var cursor = editor.getCursorPosition();
439
 
            var line = session.doc.getLine(cursor.row);
440
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
441
 
            if (rightChar == ')') {
442
 
                var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
443
 
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
444
 
                    CstyleBehaviour.popAutoInsertedClosing();
445
 
                    return {
446
 
                        text: '',
447
 
                        selection: [1, 1]
448
 
                    };
449
 
                }
450
 
            }
451
 
        }
452
 
    });
453
 
 
454
 
    this.add("parens", "deletion", function (state, action, editor, session, range) {
455
 
        var selected = session.doc.getTextRange(range);
456
 
        if (!range.isMultiLine() && selected == '(') {
457
 
            var line = session.doc.getLine(range.start.row);
458
 
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
459
 
            if (rightChar == ')') {
460
 
                range.end.column++;
461
 
                return range;
462
 
            }
463
 
        }
464
 
    });
465
 
 
466
 
    this.add("brackets", "insertion", function (state, action, editor, session, text) {
467
 
        if (text == '[') {
468
 
            var selection = editor.getSelectionRange();
469
 
            var selected = session.doc.getTextRange(selection);
470
 
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
471
 
                return {
472
 
                    text: '[' + selected + ']',
473
 
                    selection: false
474
 
                };
475
 
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
476
 
                CstyleBehaviour.recordAutoInsert(editor, session, "]");
477
 
                return {
478
 
                    text: '[]',
479
 
                    selection: [1, 1]
480
 
                };
481
 
            }
482
 
        } else if (text == ']') {
483
 
            var cursor = editor.getCursorPosition();
484
 
            var line = session.doc.getLine(cursor.row);
485
 
            var rightChar = line.substring(cursor.column, cursor.column + 1);
486
 
            if (rightChar == ']') {
487
 
                var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
488
 
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
489
 
                    CstyleBehaviour.popAutoInsertedClosing();
490
 
                    return {
491
 
                        text: '',
492
 
                        selection: [1, 1]
493
 
                    };
494
 
                }
495
 
            }
496
 
        }
497
 
    });
498
 
 
499
 
    this.add("brackets", "deletion", function (state, action, editor, session, range) {
500
 
        var selected = session.doc.getTextRange(range);
501
 
        if (!range.isMultiLine() && selected == '[') {
502
 
            var line = session.doc.getLine(range.start.row);
503
 
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
504
 
            if (rightChar == ']') {
505
 
                range.end.column++;
506
 
                return range;
507
 
            }
508
 
        }
509
 
    });
510
 
 
511
 
    this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
512
 
        if (text == '"' || text == "'") {
513
 
            var quote = text;
514
 
            var selection = editor.getSelectionRange();
515
 
            var selected = session.doc.getTextRange(selection);
516
 
            if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
517
 
                return {
518
 
                    text: quote + selected + quote,
519
 
                    selection: false
520
 
                };
521
 
            } else {
522
 
                var cursor = editor.getCursorPosition();
523
 
                var line = session.doc.getLine(cursor.row);
524
 
                var leftChar = line.substring(cursor.column-1, cursor.column);
525
 
                if (leftChar == '\\') {
526
 
                    return null;
527
 
                }
528
 
                var tokens = session.getTokens(selection.start.row);
529
 
                var col = 0, token;
530
 
                var quotepos = -1; // Track whether we're inside an open quote.
531
 
 
532
 
                for (var x = 0; x < tokens.length; x++) {
533
 
                    token = tokens[x];
534
 
                    if (token.type == "string") {
535
 
                      quotepos = -1;
536
 
                    } else if (quotepos < 0) {
537
 
                      quotepos = token.value.indexOf(quote);
538
 
                    }
539
 
                    if ((token.value.length + col) > selection.start.column) {
540
 
                        break;
541
 
                    }
542
 
                    col += tokens[x].value.length;
543
 
                }
544
 
                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)))) {
545
 
                    if (!CstyleBehaviour.isSaneInsertion(editor, session))
546
 
                        return;
547
 
                    return {
548
 
                        text: quote + quote,
549
 
                        selection: [1,1]
550
 
                    };
551
 
                } else if (token && token.type === "string") {
552
 
                    var rightChar = line.substring(cursor.column, cursor.column + 1);
553
 
                    if (rightChar == quote) {
554
 
                        return {
555
 
                            text: '',
556
 
                            selection: [1, 1]
557
 
                        };
558
 
                    }
559
 
                }
560
 
            }
561
 
        }
562
 
    });
563
 
 
564
 
    this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
565
 
        var selected = session.doc.getTextRange(range);
566
 
        if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
567
 
            var line = session.doc.getLine(range.start.row);
568
 
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
569
 
            if (rightChar == selected) {
570
 
                range.end.column++;
571
 
                return range;
572
 
            }
573
 
        }
574
 
    });
575
 
 
576
 
};
577
 
 
578
 
oop.inherits(CstyleBehaviour, Behaviour);
579
 
 
580
 
exports.CstyleBehaviour = CstyleBehaviour;
581
 
});
582
 
 
583
 
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
584
 
 
585
 
 
586
 
var oop = require("../../lib/oop");
587
 
var Range = require("../../range").Range;
588
 
var BaseFoldMode = require("./fold_mode").FoldMode;
589
 
 
590
 
var FoldMode = exports.FoldMode = function(commentRegex) {
591
 
    if (commentRegex) {
592
 
        this.foldingStartMarker = new RegExp(
593
 
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
594
 
        );
595
 
        this.foldingStopMarker = new RegExp(
596
 
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
597
 
        );
598
 
    }
599
 
};
600
 
oop.inherits(FoldMode, BaseFoldMode);
601
 
 
602
 
(function() {
603
 
 
604
 
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
605
 
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
606
 
 
607
 
    this.getFoldWidgetRange = function(session, foldStyle, row) {
608
 
        var line = session.getLine(row);
609
 
        var match = line.match(this.foldingStartMarker);
610
 
        if (match) {
611
 
            var i = match.index;
612
 
 
613
 
            if (match[1])
614
 
                return this.openingBracketBlock(session, match[1], row, i);
615
 
 
616
 
            return session.getCommentFoldRange(row, i + match[0].length, 1);
617
 
        }
618
 
 
619
 
        if (foldStyle !== "markbeginend")
620
 
            return;
621
 
 
622
 
        var match = line.match(this.foldingStopMarker);
623
 
        if (match) {
624
 
            var i = match.index + match[0].length;
625
 
 
626
 
            if (match[1])
627
 
                return this.closingBracketBlock(session, match[1], row, i);
628
 
 
629
 
            return session.getCommentFoldRange(row, i, -1);
630
 
        }
631
 
    };
632
 
 
633
 
}).call(FoldMode.prototype);
634
 
 
635
 
});