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

  • Committer: galaxyAbstractor
  • Date: 2013-04-10 15:49:32 UTC
  • mto: (19.1.5 lenasys)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: galaxyabstractor@gmail.com-20130410154932-4vizlzk0ar5gykvi
* Added an simple admin panel to the codeviewer-cmssy stuff
* Redesigned a bit like the mockups - still stuff to come
* Implemented the codeviewer + admin panel again using the Framework CodeIgniter instead 

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/scss', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/scss_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 ScssHighlightRules = require("./scss_highlight_rules").ScssHighlightRules;
 
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 ScssHighlightRules().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/scss_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 ScssHighlightRules = 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|bottom|" +
 
123
            "box-shadow|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|abs|adjust_color|adjust_hue|" +
 
158
         "alpha|join|blue|ceil|change_color|comparable|complement|darken|desaturate|" + 
 
159
         "floor|grayscale|green|hue|if|invert|join|length|lighten|lightness|mix|" + 
 
160
         "nth|opacify|opacity|percentage|quote|red|round|saturate|saturation|" +
 
161
         "scale_color|transparentize|type_of|unit|unitless|unqoute").split("|")
 
162
    );
 
163
 
 
164
    var constants = lang.arrayToMap(
 
165
        ("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|" +
 
166
        "block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|" +
 
167
        "char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|" +
 
168
        "decimal-leading-zero|decimal|default|disabled|disc|" +
 
169
        "distribute-all-lines|distribute-letter|distribute-space|" +
 
170
        "distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|" +
 
171
        "hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|" +
 
172
        "ideograph-alpha|ideograph-numeric|ideograph-parenthesis|" +
 
173
        "ideograph-space|inactive|inherit|inline-block|inline|inset|inside|" +
 
174
        "inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|" +
 
175
        "keep-all|left|lighter|line-edge|line-through|line|list-item|loose|" +
 
176
        "lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|" +
 
177
        "medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|" +
 
178
        "nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|" +
 
179
        "overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|" +
 
180
        "ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|" +
 
181
        "solid|square|static|strict|super|sw-resize|table-footer-group|" +
 
182
        "table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|" +
 
183
        "transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|" +
 
184
        "vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|" +
 
185
        "zero").split("|")
 
186
    );
 
187
 
 
188
    var colors = lang.arrayToMap(
 
189
        ("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|" +
 
190
        "purple|red|silver|teal|white|yellow").split("|")
 
191
    );
 
192
    
 
193
    var keywords = lang.arrayToMap(
 
194
        ("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|def|end|declare").split("|")
 
195
    )
 
196
    
 
197
    var tags = lang.arrayToMap(
 
198
        ("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|" + 
 
199
         "big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|" + 
 
200
         "command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|" + 
 
201
         "figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|" + 
 
202
         "header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|" + 
 
203
         "link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|" + 
 
204
         "option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|" + 
 
205
         "small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|" + 
 
206
         "textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp").split("|")
 
207
    );
 
208
 
 
209
    var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
 
210
 
 
211
    this.$rules = {
 
212
        "start" : [
 
213
            {
 
214
                token : "comment",
 
215
                regex : "\\/\\/.*$"
 
216
            },
 
217
            {
 
218
                token : "comment", // multi line comment
 
219
                regex : "\\/\\*",
 
220
                next : "comment"
 
221
            }, {
 
222
                token : "string", // single line
 
223
                regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
 
224
            }, {
 
225
                token : "string", // multi line string start
 
226
                regex : '["].*\\\\$',
 
227
                next : "qqstring"
 
228
            }, {
 
229
                token : "string", // single line
 
230
                regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
 
231
            }, {
 
232
                token : "string", // multi line string start
 
233
                regex : "['].*\\\\$",
 
234
                next : "qstring"
 
235
            }, {
 
236
                token : "constant.numeric",
 
237
                regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
 
238
            }, {
 
239
                token : "constant.numeric", // hex6 color
 
240
                regex : "#[a-f0-9]{6}"
 
241
            }, {
 
242
                token : "constant.numeric", // hex3 color
 
243
                regex : "#[a-f0-9]{3}"
 
244
            }, {
 
245
                token : "constant.numeric",
 
246
                regex : numRe
 
247
            }, {
 
248
                token : ["support.function", "string", "support.function"],
 
249
                regex : "(url\\()(.*)(\\))"
 
250
            }, {
 
251
                token : function(value) {
 
252
                    if (properties.hasOwnProperty(value.toLowerCase()))
 
253
                        return "support.type";
 
254
                    if (keywords.hasOwnProperty(value))
 
255
                        return "keyword";
 
256
                    else if (constants.hasOwnProperty(value))
 
257
                        return "constant.language";
 
258
                    else if (functions.hasOwnProperty(value))
 
259
                        return "support.function";
 
260
                    else if (colors.hasOwnProperty(value.toLowerCase()))
 
261
                        return "support.constant.color";
 
262
                    else if (tags.hasOwnProperty(value.toLowerCase()))
 
263
                        return "variable.language";
 
264
                    else
 
265
                        return "text";
 
266
                },
 
267
                regex : "\\-?[@a-z_][@a-z0-9_\\-]*"
 
268
            }, {
 
269
                token : "variable",
 
270
                regex : "[a-z_\\-$][a-z0-9_\\-$]*\\b"
 
271
            }, {
 
272
                token: "variable.language",
 
273
                regex: "#[a-z0-9-_]+"
 
274
            }, {
 
275
                token: "variable.language",
 
276
                regex: "\\.[a-z0-9-_]+"
 
277
            }, {
 
278
                token: "variable.language",
 
279
                regex: ":[a-z0-9-_]+"
 
280
            }, {
 
281
                token: "constant",
 
282
                regex: "[a-z0-9-_]+"
 
283
            }, {
 
284
                token : "keyword.operator",
 
285
                regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
 
286
            }, {
 
287
                token : "paren.lparen",
 
288
                regex : "[[({]"
 
289
            }, {
 
290
                token : "paren.rparen",
 
291
                regex : "[\\])}]"
 
292
            }, {
 
293
                token : "text",
 
294
                regex : "\\s+"
 
295
            }, {
 
296
                caseInsensitive: true
 
297
            }
 
298
        ],
 
299
        "comment" : [
 
300
            {
 
301
                token : "comment", // closing comment
 
302
                regex : ".*?\\*\\/",
 
303
                next : "start"
 
304
            }, {
 
305
                token : "comment", // comment spanning whole line
 
306
                regex : ".+"
 
307
            }
 
308
        ],
 
309
        "qqstring" : [
 
310
            {
 
311
                token : "string",
 
312
                regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
 
313
                next : "start"
 
314
            }, {
 
315
                token : "string",
 
316
                regex : '.+'
 
317
            }
 
318
        ],
 
319
        "qstring" : [
 
320
            {
 
321
                token : "string",
 
322
                regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
 
323
                next : "start"
 
324
            }, {
 
325
                token : "string",
 
326
                regex : '.+'
 
327
            }
 
328
        ]
 
329
    };
 
330
};
 
331
 
 
332
oop.inherits(ScssHighlightRules, TextHighlightRules);
 
333
 
 
334
exports.ScssHighlightRules = ScssHighlightRules;
 
335
 
 
336
});
 
337
 
 
338
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
 
339
 
 
340
 
 
341
var Range = require("../range").Range;
 
342
 
 
343
var MatchingBraceOutdent = function() {};
 
344
 
 
345
(function() {
 
346
 
 
347
    this.checkOutdent = function(line, input) {
 
348
        if (! /^\s+$/.test(line))
 
349
            return false;
 
350
 
 
351
        return /^\s*\}/.test(input);
 
352
    };
 
353
 
 
354
    this.autoOutdent = function(doc, row) {
 
355
        var line = doc.getLine(row);
 
356
        var match = line.match(/^(\s*\})/);
 
357
 
 
358
        if (!match) return 0;
 
359
 
 
360
        var column = match[1].length;
 
361
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
 
362
 
 
363
        if (!openBracePos || openBracePos.row == row) return 0;
 
364
 
 
365
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
 
366
        doc.replace(new Range(row, 0, row, column-1), indent);
 
367
    };
 
368
 
 
369
    this.$getIndent = function(line) {
 
370
        return line.match(/^\s*/)[0];
 
371
    };
 
372
 
 
373
}).call(MatchingBraceOutdent.prototype);
 
374
 
 
375
exports.MatchingBraceOutdent = MatchingBraceOutdent;
 
376
});
 
377
 
 
378
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) {
 
379
 
 
380
 
 
381
var oop = require("../../lib/oop");
 
382
var Behaviour = require("../behaviour").Behaviour;
 
383
var CstyleBehaviour = require("./cstyle").CstyleBehaviour;
 
384
var TokenIterator = require("../../token_iterator").TokenIterator;
 
385
 
 
386
var CssBehaviour = function () {
 
387
 
 
388
    this.inherit(CstyleBehaviour);
 
389
 
 
390
    this.add("colon", "insertion", function (state, action, editor, session, text) {
 
391
        if (text === ':') {
 
392
            var cursor = editor.getCursorPosition();
 
393
            var iterator = new TokenIterator(session, cursor.row, cursor.column);
 
394
            var token = iterator.getCurrentToken();
 
395
            if (token && token.value.match(/\s+/)) {
 
396
                token = iterator.stepBackward();
 
397
            }
 
398
            if (token && token.type === 'support.type') {
 
399
                var line = session.doc.getLine(cursor.row);
 
400
                var rightChar = line.substring(cursor.column, cursor.column + 1);
 
401
                if (rightChar === ':') {
 
402
                    return {
 
403
                       text: '',
 
404
                       selection: [1, 1]
 
405
                    }
 
406
                }
 
407
                if (!line.substring(cursor.column).match(/^\s*;/)) {
 
408
                    return {
 
409
                       text: ':;',
 
410
                       selection: [1, 1]
 
411
                    }
 
412
                }
 
413
            }
 
414
        }
 
415
    });
 
416
 
 
417
    this.add("colon", "deletion", function (state, action, editor, session, range) {
 
418
        var selected = session.doc.getTextRange(range);
 
419
        if (!range.isMultiLine() && selected === ':') {
 
420
            var cursor = editor.getCursorPosition();
 
421
            var iterator = new TokenIterator(session, cursor.row, cursor.column);
 
422
            var token = iterator.getCurrentToken();
 
423
            if (token && token.value.match(/\s+/)) {
 
424
                token = iterator.stepBackward();
 
425
            }
 
426
            if (token && token.type === 'support.type') {
 
427
                var line = session.doc.getLine(range.start.row);
 
428
                var rightChar = line.substring(range.end.column, range.end.column + 1);
 
429
                if (rightChar === ';') {
 
430
                    range.end.column ++;
 
431
                    return range;
 
432
                }
 
433
            }
 
434
        }
 
435
    });
 
436
 
 
437
    this.add("semicolon", "insertion", function (state, action, editor, session, text) {
 
438
        if (text === ';') {
 
439
            var cursor = editor.getCursorPosition();
 
440
            var line = session.doc.getLine(cursor.row);
 
441
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
442
            if (rightChar === ';') {
 
443
                return {
 
444
                   text: '',
 
445
                   selection: [1, 1]
 
446
                }
 
447
            }
 
448
        }
 
449
    });
 
450
 
 
451
}
 
452
oop.inherits(CssBehaviour, CstyleBehaviour);
 
453
 
 
454
exports.CssBehaviour = CssBehaviour;
 
455
});
 
456
 
 
457
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
 
458
 
 
459
 
 
460
var oop = require("../../lib/oop");
 
461
var Behaviour = require("../behaviour").Behaviour;
 
462
var TokenIterator = require("../../token_iterator").TokenIterator;
 
463
var lang = require("../../lib/lang");
 
464
 
 
465
var SAFE_INSERT_IN_TOKENS =
 
466
    ["text", "paren.rparen", "punctuation.operator"];
 
467
var SAFE_INSERT_BEFORE_TOKENS =
 
468
    ["text", "paren.rparen", "punctuation.operator", "comment"];
 
469
 
 
470
 
 
471
var autoInsertedBrackets = 0;
 
472
var autoInsertedRow = -1;
 
473
var autoInsertedLineEnd = "";
 
474
var maybeInsertedBrackets = 0;
 
475
var maybeInsertedRow = -1;
 
476
var maybeInsertedLineStart = "";
 
477
var maybeInsertedLineEnd = "";
 
478
 
 
479
var CstyleBehaviour = function () {
 
480
    
 
481
    CstyleBehaviour.isSaneInsertion = function(editor, session) {
 
482
        var cursor = editor.getCursorPosition();
 
483
        var iterator = new TokenIterator(session, cursor.row, cursor.column);
 
484
        if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
 
485
            var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
 
486
            if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
 
487
                return false;
 
488
        }
 
489
        iterator.stepForward();
 
490
        return iterator.getCurrentTokenRow() !== cursor.row ||
 
491
            this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
 
492
    };
 
493
    
 
494
    CstyleBehaviour.$matchTokenType = function(token, types) {
 
495
        return types.indexOf(token.type || token) > -1;
 
496
    };
 
497
    
 
498
    CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
 
499
        var cursor = editor.getCursorPosition();
 
500
        var line = session.doc.getLine(cursor.row);
 
501
        if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
 
502
            autoInsertedBrackets = 0;
 
503
        autoInsertedRow = cursor.row;
 
504
        autoInsertedLineEnd = bracket + line.substr(cursor.column);
 
505
        autoInsertedBrackets++;
 
506
    };
 
507
    
 
508
    CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
 
509
        var cursor = editor.getCursorPosition();
 
510
        var line = session.doc.getLine(cursor.row);
 
511
        if (!this.isMaybeInsertedClosing(cursor, line))
 
512
            maybeInsertedBrackets = 0;
 
513
        maybeInsertedRow = cursor.row;
 
514
        maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
 
515
        maybeInsertedLineEnd = line.substr(cursor.column);
 
516
        maybeInsertedBrackets++;
 
517
    };
 
518
    
 
519
    CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
 
520
        return autoInsertedBrackets > 0 &&
 
521
            cursor.row === autoInsertedRow &&
 
522
            bracket === autoInsertedLineEnd[0] &&
 
523
            line.substr(cursor.column) === autoInsertedLineEnd;
 
524
    };
 
525
    
 
526
    CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
 
527
        return maybeInsertedBrackets > 0 &&
 
528
            cursor.row === maybeInsertedRow &&
 
529
            line.substr(cursor.column) === maybeInsertedLineEnd &&
 
530
            line.substr(0, cursor.column) == maybeInsertedLineStart;
 
531
    };
 
532
    
 
533
    CstyleBehaviour.popAutoInsertedClosing = function() {
 
534
        autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
 
535
        autoInsertedBrackets--;
 
536
    };
 
537
    
 
538
    CstyleBehaviour.clearMaybeInsertedClosing = function() {
 
539
        maybeInsertedBrackets = 0;
 
540
        maybeInsertedRow = -1;
 
541
    };
 
542
 
 
543
    this.add("braces", "insertion", function (state, action, editor, session, text) {
 
544
        var cursor = editor.getCursorPosition();
 
545
        var line = session.doc.getLine(cursor.row);
 
546
        if (text == '{') {
 
547
            var selection = editor.getSelectionRange();
 
548
            var selected = session.doc.getTextRange(selection);
 
549
            if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
 
550
                return {
 
551
                    text: '{' + selected + '}',
 
552
                    selection: false
 
553
                };
 
554
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
555
                if (/[\]\}\)]/.test(line[cursor.column])) {
 
556
                    CstyleBehaviour.recordAutoInsert(editor, session, "}");
 
557
                    return {
 
558
                        text: '{}',
 
559
                        selection: [1, 1]
 
560
                    };
 
561
                } else {
 
562
                    CstyleBehaviour.recordMaybeInsert(editor, session, "{");
 
563
                    return {
 
564
                        text: '{',
 
565
                        selection: [1, 1]
 
566
                    };
 
567
                }
 
568
            }
 
569
        } else if (text == '}') {
 
570
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
571
            if (rightChar == '}') {
 
572
                var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
 
573
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
574
                    CstyleBehaviour.popAutoInsertedClosing();
 
575
                    return {
 
576
                        text: '',
 
577
                        selection: [1, 1]
 
578
                    };
 
579
                }
 
580
            }
 
581
        } else if (text == "\n" || text == "\r\n") {
 
582
            var closing = "";
 
583
            if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
 
584
                closing = lang.stringRepeat("}", maybeInsertedBrackets);
 
585
                CstyleBehaviour.clearMaybeInsertedClosing();
 
586
            }
 
587
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
588
            if (rightChar == '}' || closing !== "") {
 
589
                var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
 
590
                if (!openBracePos)
 
591
                     return null;
 
592
 
 
593
                var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
 
594
                var next_indent = this.$getIndent(line);
 
595
 
 
596
                return {
 
597
                    text: '\n' + indent + '\n' + next_indent + closing,
 
598
                    selection: [1, indent.length, 1, indent.length]
 
599
                };
 
600
            }
 
601
        }
 
602
    });
 
603
 
 
604
    this.add("braces", "deletion", function (state, action, editor, session, range) {
 
605
        var selected = session.doc.getTextRange(range);
 
606
        if (!range.isMultiLine() && selected == '{') {
 
607
            var line = session.doc.getLine(range.start.row);
 
608
            var rightChar = line.substring(range.end.column, range.end.column + 1);
 
609
            if (rightChar == '}') {
 
610
                range.end.column++;
 
611
                return range;
 
612
            } else {
 
613
                maybeInsertedBrackets--;
 
614
            }
 
615
        }
 
616
    });
 
617
 
 
618
    this.add("parens", "insertion", function (state, action, editor, session, text) {
 
619
        if (text == '(') {
 
620
            var selection = editor.getSelectionRange();
 
621
            var selected = session.doc.getTextRange(selection);
 
622
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
 
623
                return {
 
624
                    text: '(' + selected + ')',
 
625
                    selection: false
 
626
                };
 
627
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
628
                CstyleBehaviour.recordAutoInsert(editor, session, ")");
 
629
                return {
 
630
                    text: '()',
 
631
                    selection: [1, 1]
 
632
                };
 
633
            }
 
634
        } else if (text == ')') {
 
635
            var cursor = editor.getCursorPosition();
 
636
            var line = session.doc.getLine(cursor.row);
 
637
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
638
            if (rightChar == ')') {
 
639
                var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
 
640
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
641
                    CstyleBehaviour.popAutoInsertedClosing();
 
642
                    return {
 
643
                        text: '',
 
644
                        selection: [1, 1]
 
645
                    };
 
646
                }
 
647
            }
 
648
        }
 
649
    });
 
650
 
 
651
    this.add("parens", "deletion", function (state, action, editor, session, range) {
 
652
        var selected = session.doc.getTextRange(range);
 
653
        if (!range.isMultiLine() && selected == '(') {
 
654
            var line = session.doc.getLine(range.start.row);
 
655
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
656
            if (rightChar == ')') {
 
657
                range.end.column++;
 
658
                return range;
 
659
            }
 
660
        }
 
661
    });
 
662
 
 
663
    this.add("brackets", "insertion", function (state, action, editor, session, text) {
 
664
        if (text == '[') {
 
665
            var selection = editor.getSelectionRange();
 
666
            var selected = session.doc.getTextRange(selection);
 
667
            if (selected !== "" && editor.getWrapBehavioursEnabled()) {
 
668
                return {
 
669
                    text: '[' + selected + ']',
 
670
                    selection: false
 
671
                };
 
672
            } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
 
673
                CstyleBehaviour.recordAutoInsert(editor, session, "]");
 
674
                return {
 
675
                    text: '[]',
 
676
                    selection: [1, 1]
 
677
                };
 
678
            }
 
679
        } else if (text == ']') {
 
680
            var cursor = editor.getCursorPosition();
 
681
            var line = session.doc.getLine(cursor.row);
 
682
            var rightChar = line.substring(cursor.column, cursor.column + 1);
 
683
            if (rightChar == ']') {
 
684
                var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
 
685
                if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
 
686
                    CstyleBehaviour.popAutoInsertedClosing();
 
687
                    return {
 
688
                        text: '',
 
689
                        selection: [1, 1]
 
690
                    };
 
691
                }
 
692
            }
 
693
        }
 
694
    });
 
695
 
 
696
    this.add("brackets", "deletion", function (state, action, editor, session, range) {
 
697
        var selected = session.doc.getTextRange(range);
 
698
        if (!range.isMultiLine() && selected == '[') {
 
699
            var line = session.doc.getLine(range.start.row);
 
700
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
701
            if (rightChar == ']') {
 
702
                range.end.column++;
 
703
                return range;
 
704
            }
 
705
        }
 
706
    });
 
707
 
 
708
    this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
 
709
        if (text == '"' || text == "'") {
 
710
            var quote = text;
 
711
            var selection = editor.getSelectionRange();
 
712
            var selected = session.doc.getTextRange(selection);
 
713
            if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
 
714
                return {
 
715
                    text: quote + selected + quote,
 
716
                    selection: false
 
717
                };
 
718
            } else {
 
719
                var cursor = editor.getCursorPosition();
 
720
                var line = session.doc.getLine(cursor.row);
 
721
                var leftChar = line.substring(cursor.column-1, cursor.column);
 
722
                if (leftChar == '\\') {
 
723
                    return null;
 
724
                }
 
725
                var tokens = session.getTokens(selection.start.row);
 
726
                var col = 0, token;
 
727
                var quotepos = -1; // Track whether we're inside an open quote.
 
728
 
 
729
                for (var x = 0; x < tokens.length; x++) {
 
730
                    token = tokens[x];
 
731
                    if (token.type == "string") {
 
732
                      quotepos = -1;
 
733
                    } else if (quotepos < 0) {
 
734
                      quotepos = token.value.indexOf(quote);
 
735
                    }
 
736
                    if ((token.value.length + col) > selection.start.column) {
 
737
                        break;
 
738
                    }
 
739
                    col += tokens[x].value.length;
 
740
                }
 
741
                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)))) {
 
742
                    if (!CstyleBehaviour.isSaneInsertion(editor, session))
 
743
                        return;
 
744
                    return {
 
745
                        text: quote + quote,
 
746
                        selection: [1,1]
 
747
                    };
 
748
                } else if (token && token.type === "string") {
 
749
                    var rightChar = line.substring(cursor.column, cursor.column + 1);
 
750
                    if (rightChar == quote) {
 
751
                        return {
 
752
                            text: '',
 
753
                            selection: [1, 1]
 
754
                        };
 
755
                    }
 
756
                }
 
757
            }
 
758
        }
 
759
    });
 
760
 
 
761
    this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
 
762
        var selected = session.doc.getTextRange(range);
 
763
        if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
 
764
            var line = session.doc.getLine(range.start.row);
 
765
            var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
 
766
            if (rightChar == selected) {
 
767
                range.end.column++;
 
768
                return range;
 
769
            }
 
770
        }
 
771
    });
 
772
 
 
773
};
 
774
 
 
775
oop.inherits(CstyleBehaviour, Behaviour);
 
776
 
 
777
exports.CstyleBehaviour = CstyleBehaviour;
 
778
});
 
779
 
 
780
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
 
781
 
 
782
 
 
783
var oop = require("../../lib/oop");
 
784
var Range = require("../../range").Range;
 
785
var BaseFoldMode = require("./fold_mode").FoldMode;
 
786
 
 
787
var FoldMode = exports.FoldMode = function(commentRegex) {
 
788
    if (commentRegex) {
 
789
        this.foldingStartMarker = new RegExp(
 
790
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
 
791
        );
 
792
        this.foldingStopMarker = new RegExp(
 
793
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
 
794
        );
 
795
    }
 
796
};
 
797
oop.inherits(FoldMode, BaseFoldMode);
 
798
 
 
799
(function() {
 
800
 
 
801
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
 
802
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
 
803
 
 
804
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
805
        var line = session.getLine(row);
 
806
        var match = line.match(this.foldingStartMarker);
 
807
        if (match) {
 
808
            var i = match.index;
 
809
 
 
810
            if (match[1])
 
811
                return this.openingBracketBlock(session, match[1], row, i);
 
812
 
 
813
            return session.getCommentFoldRange(row, i + match[0].length, 1);
 
814
        }
 
815
 
 
816
        if (foldStyle !== "markbeginend")
 
817
            return;
 
818
 
 
819
        var match = line.match(this.foldingStopMarker);
 
820
        if (match) {
 
821
            var i = match.index + match[0].length;
 
822
 
 
823
            if (match[1])
 
824
                return this.closingBracketBlock(session, match[1], row, i);
 
825
 
 
826
            return session.getCommentFoldRange(row, i, -1);
 
827
        }
 
828
    };
 
829
 
 
830
}).call(FoldMode.prototype);
 
831
 
 
832
});