/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-less.js

  • Committer: Gustav Hatvigsson
  • Date: 2013-05-31 06:15:46 UTC
  • mfrom: (90.1.20 lenasys2)
  • Revision ID: gustav.hartvigsson@gmail.com-20130531061546-vj8z28sq375kvghq
Merged Jonsson:s changes:
Fixed the layout on cms index so the arrows and dots marks expanded objects.
Fixed so the course content is sorted by course occasion and not by name

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/less', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/less_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/css', '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 LessHighlightRules = require("./less_highlight_rules").LessHighlightRules;
 
38
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
 
39
var CssBehaviour = require("./behaviour/css").CssBehaviour;
 
40
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
 
41
 
 
42
var Mode = function() {
 
43
    this.$tokenizer = new Tokenizer(new LessHighlightRules().getRules());
 
44
    this.$outdent = new MatchingBraceOutdent();
 
45
    this.$behaviour = new CssBehaviour();
 
46
    this.foldingRules = new CStyleFoldMode();
 
47
};
 
48
oop.inherits(Mode, TextMode);
 
49
 
 
50
(function() {
 
51
 
 
52
    this.lineCommentStart = "//";
 
53
    this.blockComment = {start: "/*", end: "*/"};
 
54
    
 
55
    this.getNextLineIndent = function(state, line, tab) {
 
56
        var indent = this.$getIndent(line);
 
57
        var tokens = this.$tokenizer.getLineTokens(line, state).tokens;
 
58
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
 
59
            return indent;
 
60
        }
 
61
 
 
62
        var match = line.match(/^.*\{\s*$/);
 
63
        if (match) {
 
64
            indent += tab;
 
65
        }
 
66
 
 
67
        return indent;
 
68
    };
 
69
 
 
70
    this.checkOutdent = function(state, line, input) {
 
71
        return this.$outdent.checkOutdent(line, input);
 
72
    };
 
73
 
 
74
    this.autoOutdent = function(state, doc, row) {
 
75
        this.$outdent.autoOutdent(doc, row);
 
76
    };
 
77
 
 
78
}).call(Mode.prototype);
 
79
 
 
80
exports.Mode = Mode;
 
81
 
 
82
});
 
83
 
 
84
define('ace/mode/less_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
85
 
 
86
 
 
87
var oop = require("../lib/oop");
 
88
var lang = require("../lib/lang");
 
89
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
90
 
 
91
var LessHighlightRules = function() {
 
92
    
 
93
    var properties = lang.arrayToMap( (function () {
 
94
 
 
95
        var browserPrefix = ("-webkit-|-moz-|-o-|-ms-|-svg-|-pie-|-khtml-").split("|");
 
96
        
 
97
        var prefixProperties = ("appearance|background-clip|background-inline-policy|background-origin|" + 
 
98
             "background-size|binding|border-bottom-colors|border-left-colors|" + 
 
99
             "border-right-colors|border-top-colors|border-end|border-end-color|" + 
 
100
             "border-end-style|border-end-width|border-image|border-start|" + 
 
101
             "border-start-color|border-start-style|border-start-width|box-align|" + 
 
102
             "box-direction|box-flex|box-flexgroup|box-ordinal-group|box-orient|" + 
 
103
             "box-pack|box-sizing|column-count|column-gap|column-width|column-rule|" + 
 
104
             "column-rule-width|column-rule-style|column-rule-color|float-edge|" + 
 
105
             "font-feature-settings|font-language-override|force-broken-image-icon|" + 
 
106
             "image-region|margin-end|margin-start|opacity|outline|outline-color|" + 
 
107
             "outline-offset|outline-radius|outline-radius-bottomleft|" + 
 
108
             "outline-radius-bottomright|outline-radius-topleft|outline-radius-topright|" + 
 
109
             "outline-style|outline-width|padding-end|padding-start|stack-sizing|" + 
 
110
             "tab-size|text-blink|text-decoration-color|text-decoration-line|" + 
 
111
             "text-decoration-style|transform|transform-origin|transition|" + 
 
112
             "transition-delay|transition-duration|transition-property|" + 
 
113
             "transition-timing-function|user-focus|user-input|user-modify|user-select|" +
 
114
             "window-shadow|border-radius").split("|");
 
115
        
 
116
        var properties = ("azimuth|background-attachment|background-color|background-image|" +
 
117
            "background-position|background-repeat|background|border-bottom-color|" +
 
118
            "border-bottom-style|border-bottom-width|border-bottom|border-collapse|" +
 
119
            "border-color|border-left-color|border-left-style|border-left-width|" +
 
120
            "border-left|border-right-color|border-right-style|border-right-width|" +
 
121
            "border-right|border-spacing|border-style|border-top-color|" +
 
122
            "border-top-style|border-top-width|border-top|border-width|border|" +
 
123
            "bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|" +
 
124
            "counter-reset|cue-after|cue-before|cue|cursor|direction|display|" +
 
125
            "elevation|empty-cells|float|font-family|font-size-adjust|font-size|" +
 
126
            "font-stretch|font-style|font-variant|font-weight|font|height|left|" +
 
127
            "letter-spacing|line-height|list-style-image|list-style-position|" +
 
128
            "list-style-type|list-style|margin-bottom|margin-left|margin-right|" +
 
129
            "margin-top|marker-offset|margin|marks|max-height|max-width|min-height|" +
 
130
            "min-width|opacity|orphans|outline-color|" +
 
131
            "outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|" +
 
132
            "padding-left|padding-right|padding-top|padding|page-break-after|" +
 
133
            "page-break-before|page-break-inside|page|pause-after|pause-before|" +
 
134
            "pause|pitch-range|pitch|play-during|position|quotes|richness|right|" +
 
135
            "size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|" +
 
136
            "stress|table-layout|text-align|text-decoration|text-indent|" +
 
137
            "text-shadow|text-transform|top|unicode-bidi|vertical-align|" +
 
138
            "visibility|voice-family|volume|white-space|widows|width|word-spacing|" +
 
139
            "z-index").split("|");
 
140
        var ret = [];
 
141
        for (var i=0, ln=browserPrefix.length; i<ln; i++) {
 
142
            Array.prototype.push.apply(
 
143
                ret,
 
144
                (( browserPrefix[i] + prefixProperties.join("|" + browserPrefix[i]) ).split("|"))
 
145
            );
 
146
        }
 
147
        Array.prototype.push.apply(ret, prefixProperties);
 
148
        Array.prototype.push.apply(ret, properties);
 
149
        
 
150
        return ret;
 
151
        
 
152
    })() );
 
153
    
 
154
 
 
155
 
 
156
    var functions = lang.arrayToMap(
 
157
        ("hsl|hsla|rgb|rgba|url|attr|counter|counters|lighten|darken|saturate|" +
 
158
        "desaturate|fadein|fadeout|fade|spin|mix|hue|saturation|lightness|" +
 
159
        "alpha|round|ceil|floor|percentage|color|iscolor|isnumber|isstring|" +
 
160
        "iskeyword|isurl|ispixel|ispercentage|isem").split("|")
 
161
    );
 
162
 
 
163
    var constants = lang.arrayToMap(
 
164
        ("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|" +
 
165
        "block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|" +
 
166
        "char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|" +
 
167
        "decimal-leading-zero|decimal|default|disabled|disc|" +
 
168
        "distribute-all-lines|distribute-letter|distribute-space|" +
 
169
        "distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|" +
 
170
        "hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|" +
 
171
        "ideograph-alpha|ideograph-numeric|ideograph-parenthesis|" +
 
172
        "ideograph-space|inactive|inherit|inline-block|inline|inset|inside|" +
 
173
        "inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|" +
 
174
        "keep-all|left|lighter|line-edge|line-through|line|list-item|loose|" +
 
175
        "lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|" +
 
176
        "medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|" +
 
177
        "nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|" +
 
178
        "overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|" +
 
179
        "ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|" +
 
180
        "solid|square|static|strict|super|sw-resize|table-footer-group|" +
 
181
        "table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|" +
 
182
        "transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|" +
 
183
        "vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|" +
 
184
        "zero").split("|")
 
185
    );
 
186
 
 
187
    var colors = lang.arrayToMap(
 
188
        ("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|" +
 
189
        "purple|red|silver|teal|white|yellow").split("|")
 
190
    );
 
191
    
 
192
    var keywords = lang.arrayToMap(
 
193
        ("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|" +
 
194
        "@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|" +
 
195
        "def|end|declare|when|not|and").split("|")
 
196
    );
 
197
    
 
198
    var tags = lang.arrayToMap(
 
199
        ("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|" + 
 
200
         "big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|" + 
 
201
         "command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|" + 
 
202
         "figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|" + 
 
203
         "header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|" + 
 
204
         "link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|" + 
 
205
         "option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|" + 
 
206
         "small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|" + 
 
207
         "textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp").split("|")
 
208
    );
 
209
 
 
210
    var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
 
211
 
 
212
    this.$rules = {
 
213
        "start" : [
 
214
            {
 
215
                token : "comment",
 
216
                regex : "\\/\\/.*$"
 
217
            },
 
218
            {
 
219
                token : "comment", // multi line comment
 
220
                regex : "\\/\\*",
 
221
                next : "comment"
 
222
            }, {
 
223
                token : "string", // single line
 
224
                regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
 
225
            }, {
 
226
                token : "string", // single line
 
227
                regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
 
228
            }, {
 
229
                token : "constant.numeric",
 
230
                regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
 
231
            }, {
 
232
                token : "constant.numeric", // hex6 color
 
233
                regex : "#[a-f0-9]{6}"
 
234
            }, {
 
235
                token : "constant.numeric", // hex3 color
 
236
                regex : "#[a-f0-9]{3}"
 
237
            }, {
 
238
                token : "constant.numeric",
 
239
                regex : numRe
 
240
            }, {
 
241
                token : function(value) {
 
242
                    if (keywords.hasOwnProperty(value))
 
243
                        return "keyword";
 
244
                    else
 
245
                        return "variable";
 
246
                },
 
247
                regex : "@[a-z0-9_\\-@]*\\b"
 
248
            }, {
 
249
                token : function(value) {
 
250
                    if (properties.hasOwnProperty(value.toLowerCase()))
 
251
                        return "support.type";
 
252
                    else if (keywords.hasOwnProperty(value))
 
253
                        return "keyword";
 
254
                    else if (constants.hasOwnProperty(value))
 
255
                        return "constant.language";
 
256
                    else if (functions.hasOwnProperty(value))
 
257
                        return "support.function";
 
258
                    else if (colors.hasOwnProperty(value.toLowerCase()))
 
259
                        return "support.constant.color";
 
260
                    else if (tags.hasOwnProperty(value.toLowerCase()))
 
261
                        return "variable.language";
 
262
                    else
 
263
                        return "text";
 
264
                },
 
265
                regex : "\\-?[@a-z_][@a-z0-9_\\-]*"
 
266
            }, {
 
267
                token: "variable.language",
 
268
                regex: "#[a-z0-9-_]+"
 
269
            }, {
 
270
                token: "variable.language",
 
271
                regex: "\\.[a-z0-9-_]+"
 
272
            }, {
 
273
                token: "variable.language",
 
274
                regex: ":[a-z0-9-_]+"
 
275
            }, {
 
276
                token: "constant",
 
277
                regex: "[a-z0-9-_]+"
 
278
            }, {
 
279
                token : "keyword.operator",
 
280
                regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
 
281
            }, {
 
282
                token : "paren.lparen",
 
283
                regex : "[[({]"
 
284
            }, {
 
285
                token : "paren.rparen",
 
286
                regex : "[\\])}]"
 
287
            }, {
 
288
                token : "text",
 
289
                regex : "\\s+"
 
290
            }, {
 
291
                caseInsensitive: true
 
292
            }
 
293
        ],
 
294
        "comment" : [
 
295
            {
 
296
                token : "comment", // closing comment
 
297
                regex : ".*?\\*\\/",
 
298
                next : "start"
 
299
            }, {
 
300
                token : "comment", // comment spanning whole line
 
301
                regex : ".+"
 
302
            }
 
303
        ]
 
304
    };
 
305
};
 
306
 
 
307
oop.inherits(LessHighlightRules, TextHighlightRules);
 
308
 
 
309
exports.LessHighlightRules = LessHighlightRules;
 
310
 
 
311
});
 
312
 
 
313
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
 
314
 
 
315
 
 
316
var Range = require("../range").Range;
 
317
 
 
318
var MatchingBraceOutdent = function() {};
 
319
 
 
320
(function() {
 
321
 
 
322
    this.checkOutdent = function(line, input) {
 
323
        if (! /^\s+$/.test(line))
 
324
            return false;
 
325
 
 
326
        return /^\s*\}/.test(input);
 
327
    };
 
328
 
 
329
    this.autoOutdent = function(doc, row) {
 
330
        var line = doc.getLine(row);
 
331
        var match = line.match(/^(\s*\})/);
 
332
 
 
333
        if (!match) return 0;
 
334
 
 
335
        var column = match[1].length;
 
336
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
 
337
 
 
338
        if (!openBracePos || openBracePos.row == row) return 0;
 
339
 
 
340
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
 
341
        doc.replace(new Range(row, 0, row, column-1), indent);
 
342
    };
 
343
 
 
344
    this.$getIndent = function(line) {
 
345
        return line.match(/^\s*/)[0];
 
346
    };
 
347
 
 
348
}).call(MatchingBraceOutdent.prototype);
 
349
 
 
350
exports.MatchingBraceOutdent = MatchingBraceOutdent;
 
351
});
 
352
 
 
353
define('ace/mode/behaviour/css', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/mode/behaviour/cstyle', 'ace/token_iterator'], function(require, exports, module) {
 
354
 
 
355
 
 
356
var oop = require("../../lib/oop");
 
357
var Behaviour = require("../behaviour").Behaviour;
 
358
var CstyleBehaviour = require("./cstyle").CstyleBehaviour;
 
359
var TokenIterator = require("../../token_iterator").TokenIterator;
 
360
 
 
361
var CssBehaviour = function () {
 
362
 
 
363
    this.inherit(CstyleBehaviour);
 
364
 
 
365
    this.add("colon", "insertion", function (state, action, editor, session, text) {
 
366
        if (text === ':') {
 
367
            var cursor = editor.getCursorPosition();
 
368
            var iterator = new TokenIterator(session, cursor.row, cursor.column);
 
369
            var token = iterator.getCurrentToken();
 
370
            if (token && token.value.match(/\s+/)) {
 
371
                token = iterator.stepBackward();
 
372
            }
 
373
            if (token && token.type === 'support.type') {
 
374
                var line = session.doc.getLine(cursor.row);
 
375
                var rightChar = line.substring(cursor.column, cursor.column + 1);
 
376
                if (rightChar === ':') {
 
377
                    return {
 
378
                       text: '',
 
379
                       selection: [1, 1]
 
380
                    }
 
381
                }
 
382
                if (!line.substring(cursor.column).match(/^\s*;/)) {
 
383
                    return {
 
384
                       text: ':;',
 
385
                       selection: [1, 1]
 
386
                    }
 
387
                }
 
388
            }
 
389
        }
 
390
    });
 
391
 
 
392
    this.add("colon", "deletion", function (state, action, editor, session, range) {
 
393
        var selected = session.doc.getTextRange(range);
 
394
        if (!range.isMultiLine() && selected === ':') {
 
395
            var cursor = editor.getCursorPosition();
 
396
            var iterator = new TokenIterator(session, cursor.row, cursor.column);
 
397
            var token = iterator.getCurrentToken();
 
398
            if (token && token.value.match(/\s+/)) {
 
399
                token = iterator.stepBackward();
 
400
            }
 
401
            if (token && token.type === 'support.type') {
 
402
                var line = session.doc.getLine(range.start.row);
 
403
                var rightChar = line.substring(range.end.column, range.end.column + 1);
 
404
                if (rightChar === ';') {
 
405
                    range.end.column ++;
 
406
                    return range;
 
407
                }
 
408
            }
 
409
        }
 
410
    });
 
411
 
 
412
    this.add("semicolon", "insertion", function (state, action, editor, session, text) {
 
413
        if (text === ';') {
 
414
            var cursor = editor.getCursorPosition();
 
415
            var line = session.doc.getLine(cursor.row);
 
416
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
417
            if (rightChar === ';') {
 
418
                return {
 
419
                   text: '',
 
420
                   selection: [1, 1]
 
421
                }
 
422
            }
 
423
        }
 
424
    });
 
425
 
 
426
}
 
427
oop.inherits(CssBehaviour, CstyleBehaviour);
 
428
 
 
429
exports.CssBehaviour = CssBehaviour;
 
430
});
 
431
 
 
432
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
 
433
 
 
434
 
 
435
var oop = require("../../lib/oop");
 
436
var Behaviour = require("../behaviour").Behaviour;
 
437
var TokenIterator = require("../../token_iterator").TokenIterator;
 
438
var lang = require("../../lib/lang");
 
439
 
 
440
var SAFE_INSERT_IN_TOKENS =
 
441
    ["text", "paren.rparen", "punctuation.operator"];
 
442
var SAFE_INSERT_BEFORE_TOKENS =
 
443
    ["text", "paren.rparen", "punctuation.operator", "comment"];
 
444
 
 
445
 
 
446
var autoInsertedBrackets = 0;
 
447
var autoInsertedRow = -1;
 
448
var autoInsertedLineEnd = "";
 
449
var maybeInsertedBrackets = 0;
 
450
var maybeInsertedRow = -1;
 
451
var maybeInsertedLineStart = "";
 
452
var maybeInsertedLineEnd = "";
 
453
 
 
454
var CstyleBehaviour = function () {
 
455
    
 
456
    CstyleBehaviour.isSaneInsertion = function(editor, session) {
 
457
        var cursor = editor.getCursorPosition();
 
458
        var iterator = new TokenIterator(session, cursor.row, cursor.column);
 
459
        if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
 
460
            var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
 
461
            if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
 
462
                return false;
 
463
        }
 
464
        iterator.stepForward();
 
465
        return iterator.getCurrentTokenRow() !== cursor.row ||
 
466
            this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
 
467
    };
 
468
    
 
469
    CstyleBehaviour.$matchTokenType = function(token, types) {
 
470
        return types.indexOf(token.type || token) > -1;
 
471
    };
 
472
    
 
473
    CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
 
474
        var cursor = editor.getCursorPosition();
 
475
        var line = session.doc.getLine(cursor.row);
 
476
        if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
 
477
            autoInsertedBrackets = 0;
 
478
        autoInsertedRow = cursor.row;
 
479
        autoInsertedLineEnd = bracket + line.substr(cursor.column);
 
480
        autoInsertedBrackets++;
 
481
    };
 
482
    
 
483
    CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
 
484
        var cursor = editor.getCursorPosition();
 
485
        var line = session.doc.getLine(cursor.row);
 
486
        if (!this.isMaybeInsertedClosing(cursor, line))
 
487
            maybeInsertedBrackets = 0;
 
488
        maybeInsertedRow = cursor.row;
 
489
        maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
 
490
        maybeInsertedLineEnd = line.substr(cursor.column);
 
491
        maybeInsertedBrackets++;
 
492
    };
 
493
    
 
494
    CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
 
495
        return autoInsertedBrackets > 0 &&
 
496
            cursor.row === autoInsertedRow &&
 
497
            bracket === autoInsertedLineEnd[0] &&
 
498
            line.substr(cursor.column) === autoInsertedLineEnd;
 
499
    };
 
500
    
 
501
    CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
 
502
        return maybeInsertedBrackets > 0 &&
 
503
            cursor.row === maybeInsertedRow &&
 
504
            line.substr(cursor.column) === maybeInsertedLineEnd &&
 
505
            line.substr(0, cursor.column) == maybeInsertedLineStart;
 
506
    };
 
507
    
 
508
    CstyleBehaviour.popAutoInsertedClosing = function() {
 
509
        autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
 
510
        autoInsertedBrackets--;
 
511
    };
 
512
    
 
513
    CstyleBehaviour.clearMaybeInsertedClosing = function() {
 
514
        maybeInsertedBrackets = 0;
 
515
        maybeInsertedRow = -1;
 
516
    };
 
517
 
 
518
    this.add("braces", "insertion", function (state, action, editor, session, text) {
 
519
        var cursor = editor.getCursorPosition();
 
520
        var line = session.doc.getLine(cursor.row);
 
521
        if (text == '{') {
 
522
            var selection = editor.getSelectionRange();
 
523
            var selected = session.doc.getTextRange(selection);
 
524
            if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
 
525
                return {
 
526
                    text: '{' + selected + '}',
 
527
                    selection: false
 
528
                };
 
529
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
530
                if (/[\]\}\)]/.test(line[cursor.column])) {
 
531
                    CstyleBehaviour.recordAutoInsert(editor, session, "}");
 
532
                    return {
 
533
                        text: '{}',
 
534
                        selection: [1, 1]
 
535
                    };
 
536
                } else {
 
537
                    CstyleBehaviour.recordMaybeInsert(editor, session, "{");
 
538
                    return {
 
539
                        text: '{',
 
540
                        selection: [1, 1]
 
541
                    };
 
542
                }
 
543
            }
 
544
        } else if (text == '}') {
 
545
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
546
            if (rightChar == '}') {
 
547
                var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
 
548
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
549
                    CstyleBehaviour.popAutoInsertedClosing();
 
550
                    return {
 
551
                        text: '',
 
552
                        selection: [1, 1]
 
553
                    };
 
554
                }
 
555
            }
 
556
        } else if (text == "\n" || text == "\r\n") {
 
557
            var closing = "";
 
558
            if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
 
559
                closing = lang.stringRepeat("}", maybeInsertedBrackets);
 
560
                CstyleBehaviour.clearMaybeInsertedClosing();
 
561
            }
 
562
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
563
            if (rightChar == '}' || closing !== "") {
 
564
                var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
 
565
                if (!openBracePos)
 
566
                     return null;
 
567
 
 
568
                var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
 
569
                var next_indent = this.$getIndent(line);
 
570
 
 
571
                return {
 
572
                    text: '\n' + indent + '\n' + next_indent + closing,
 
573
                    selection: [1, indent.length, 1, indent.length]
 
574
                };
 
575
            }
 
576
        }
 
577
    });
 
578
 
 
579
    this.add("braces", "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.end.column, range.end.column + 1);
 
584
            if (rightChar == '}') {
 
585
                range.end.column++;
 
586
                return range;
 
587
            } else {
 
588
                maybeInsertedBrackets--;
 
589
            }
 
590
        }
 
591
    });
 
592
 
 
593
    this.add("parens", "insertion", function (state, action, editor, session, text) {
 
594
        if (text == '(') {
 
595
            var selection = editor.getSelectionRange();
 
596
            var selected = session.doc.getTextRange(selection);
 
597
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
 
598
                return {
 
599
                    text: '(' + selected + ')',
 
600
                    selection: false
 
601
                };
 
602
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
603
                CstyleBehaviour.recordAutoInsert(editor, session, ")");
 
604
                return {
 
605
                    text: '()',
 
606
                    selection: [1, 1]
 
607
                };
 
608
            }
 
609
        } else if (text == ')') {
 
610
            var cursor = editor.getCursorPosition();
 
611
            var line = session.doc.getLine(cursor.row);
 
612
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
613
            if (rightChar == ')') {
 
614
                var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
 
615
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
616
                    CstyleBehaviour.popAutoInsertedClosing();
 
617
                    return {
 
618
                        text: '',
 
619
                        selection: [1, 1]
 
620
                    };
 
621
                }
 
622
            }
 
623
        }
 
624
    });
 
625
 
 
626
    this.add("parens", "deletion", function (state, action, editor, session, range) {
 
627
        var selected = session.doc.getTextRange(range);
 
628
        if (!range.isMultiLine() && selected == '(') {
 
629
            var line = session.doc.getLine(range.start.row);
 
630
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
631
            if (rightChar == ')') {
 
632
                range.end.column++;
 
633
                return range;
 
634
            }
 
635
        }
 
636
    });
 
637
 
 
638
    this.add("brackets", "insertion", function (state, action, editor, session, text) {
 
639
        if (text == '[') {
 
640
            var selection = editor.getSelectionRange();
 
641
            var selected = session.doc.getTextRange(selection);
 
642
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
 
643
                return {
 
644
                    text: '[' + selected + ']',
 
645
                    selection: false
 
646
                };
 
647
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
648
                CstyleBehaviour.recordAutoInsert(editor, session, "]");
 
649
                return {
 
650
                    text: '[]',
 
651
                    selection: [1, 1]
 
652
                };
 
653
            }
 
654
        } else if (text == ']') {
 
655
            var cursor = editor.getCursorPosition();
 
656
            var line = session.doc.getLine(cursor.row);
 
657
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
658
            if (rightChar == ']') {
 
659
                var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
 
660
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
661
                    CstyleBehaviour.popAutoInsertedClosing();
 
662
                    return {
 
663
                        text: '',
 
664
                        selection: [1, 1]
 
665
                    };
 
666
                }
 
667
            }
 
668
        }
 
669
    });
 
670
 
 
671
    this.add("brackets", "deletion", function (state, action, editor, session, range) {
 
672
        var selected = session.doc.getTextRange(range);
 
673
        if (!range.isMultiLine() && selected == '[') {
 
674
            var line = session.doc.getLine(range.start.row);
 
675
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
676
            if (rightChar == ']') {
 
677
                range.end.column++;
 
678
                return range;
 
679
            }
 
680
        }
 
681
    });
 
682
 
 
683
    this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
 
684
        if (text == '"' || text == "'") {
 
685
            var quote = text;
 
686
            var selection = editor.getSelectionRange();
 
687
            var selected = session.doc.getTextRange(selection);
 
688
            if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
 
689
                return {
 
690
                    text: quote + selected + quote,
 
691
                    selection: false
 
692
                };
 
693
            } else {
 
694
                var cursor = editor.getCursorPosition();
 
695
                var line = session.doc.getLine(cursor.row);
 
696
                var leftChar = line.substring(cursor.column-1, cursor.column);
 
697
                if (leftChar == '\\') {
 
698
                    return null;
 
699
                }
 
700
                var tokens = session.getTokens(selection.start.row);
 
701
                var col = 0, token;
 
702
                var quotepos = -1; // Track whether we're inside an open quote.
 
703
 
 
704
                for (var x = 0; x < tokens.length; x++) {
 
705
                    token = tokens[x];
 
706
                    if (token.type == "string") {
 
707
                      quotepos = -1;
 
708
                    } else if (quotepos < 0) {
 
709
                      quotepos = token.value.indexOf(quote);
 
710
                    }
 
711
                    if ((token.value.length + col) > selection.start.column) {
 
712
                        break;
 
713
                    }
 
714
                    col += tokens[x].value.length;
 
715
                }
 
716
                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)))) {
 
717
                    if (!CstyleBehaviour.isSaneInsertion(editor, session))
 
718
                        return;
 
719
                    return {
 
720
                        text: quote + quote,
 
721
                        selection: [1,1]
 
722
                    };
 
723
                } else if (token && token.type === "string") {
 
724
                    var rightChar = line.substring(cursor.column, cursor.column + 1);
 
725
                    if (rightChar == quote) {
 
726
                        return {
 
727
                            text: '',
 
728
                            selection: [1, 1]
 
729
                        };
 
730
                    }
 
731
                }
 
732
            }
 
733
        }
 
734
    });
 
735
 
 
736
    this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
 
737
        var selected = session.doc.getTextRange(range);
 
738
        if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
 
739
            var line = session.doc.getLine(range.start.row);
 
740
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
741
            if (rightChar == selected) {
 
742
                range.end.column++;
 
743
                return range;
 
744
            }
 
745
        }
 
746
    });
 
747
 
 
748
};
 
749
 
 
750
oop.inherits(CstyleBehaviour, Behaviour);
 
751
 
 
752
exports.CstyleBehaviour = CstyleBehaviour;
 
753
});
 
754
 
 
755
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
 
756
 
 
757
 
 
758
var oop = require("../../lib/oop");
 
759
var Range = require("../../range").Range;
 
760
var BaseFoldMode = require("./fold_mode").FoldMode;
 
761
 
 
762
var FoldMode = exports.FoldMode = function(commentRegex) {
 
763
    if (commentRegex) {
 
764
        this.foldingStartMarker = new RegExp(
 
765
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
 
766
        );
 
767
        this.foldingStopMarker = new RegExp(
 
768
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
 
769
        );
 
770
    }
 
771
};
 
772
oop.inherits(FoldMode, BaseFoldMode);
 
773
 
 
774
(function() {
 
775
 
 
776
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
 
777
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
 
778
 
 
779
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
780
        var line = session.getLine(row);
 
781
        var match = line.match(this.foldingStartMarker);
 
782
        if (match) {
 
783
            var i = match.index;
 
784
 
 
785
            if (match[1])
 
786
                return this.openingBracketBlock(session, match[1], row, i);
 
787
 
 
788
            return session.getCommentFoldRange(row, i + match[0].length, 1);
 
789
        }
 
790
 
 
791
        if (foldStyle !== "markbeginend")
 
792
            return;
 
793
 
 
794
        var match = line.match(this.foldingStopMarker);
 
795
        if (match) {
 
796
            var i = match.index + match[0].length;
 
797
 
 
798
            if (match[1])
 
799
                return this.closingBracketBlock(session, match[1], row, i);
 
800
 
 
801
            return session.getCommentFoldRange(row, i, -1);
 
802
        }
 
803
    };
 
804
 
 
805
}).call(FoldMode.prototype);
 
806
 
 
807
});