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

  • Committer: gustav.hartvigsson at gmail
  • Date: 2013-04-03 11:52:56 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130403115256-sz6zermzoom4lifc
Ignored .DS_Store files.

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) 2012, 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
 
 *
30
 
 * Contributor(s):
31
 
 * 
32
 
 * Garen J. Torikian < gjtorikian AT gmail DOT com >
33
 
 *
34
 
 * ***** END LICENSE BLOCK ***** */
35
 
 
36
 
define('ace/mode/haml', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/haml_highlight_rules', 'ace/mode/folding/coffee'], function(require, exports, module) {
37
 
 
38
 
 
39
 
var oop = require("../lib/oop");
40
 
var TextMode = require("./text").Mode;
41
 
var Tokenizer = require("../tokenizer").Tokenizer;
42
 
var HamlHighlightRules = require("./haml_highlight_rules").HamlHighlightRules;
43
 
var FoldMode = require("./folding/coffee").FoldMode;
44
 
 
45
 
var Mode = function() {
46
 
    var highlighter = new HamlHighlightRules();
47
 
    this.foldingRules = new FoldMode();    
48
 
    
49
 
    this.$tokenizer = new Tokenizer(highlighter.getRules());
50
 
};
51
 
oop.inherits(Mode, TextMode);
52
 
 
53
 
(function() {
54
 
    this.lineCommentStart = ["//", "#"];
55
 
    
56
 
}).call(Mode.prototype);
57
 
 
58
 
exports.Mode = Mode;
59
 
});define('ace/mode/haml_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules', 'ace/mode/ruby_highlight_rules'], function(require, exports, module) {
60
 
 
61
 
 
62
 
var oop = require("../lib/oop");
63
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
64
 
var RubyExports = require("./ruby_highlight_rules");
65
 
var RubyHighlightRules = RubyExports.RubyHighlightRules;
66
 
 
67
 
var HamlHighlightRules = function() {
68
 
 
69
 
    this.$rules = 
70
 
        {
71
 
    "start": [
72
 
        {
73
 
            token : "punctuation.section.comment",
74
 
            regex : /^\s*\/.*/
75
 
        },
76
 
        {
77
 
            token : "punctuation.section.comment",
78
 
            regex : /^\s*#.*/
79
 
        },
80
 
        {
81
 
            token: "string.quoted.double",
82
 
            regex: "==.+?=="
83
 
        },
84
 
        {
85
 
            token: "keyword.other.doctype",
86
 
            regex: "^!!!\\s*(?:[a-zA-Z0-9-_]+)?"
87
 
        },
88
 
        RubyExports.qString,
89
 
        RubyExports.qqString,
90
 
        RubyExports.tString,
91
 
        {
92
 
            token: ["entity.name.tag.haml"],
93
 
            regex: /^\s*%[\w:]+/,
94
 
            next: "tag_single"
95
 
        },
96
 
        {
97
 
            token: [ "meta.escape.haml" ],
98
 
            regex: "^\\s*\\\\."
99
 
        },
100
 
        RubyExports.constantNumericHex,
101
 
        RubyExports.constantNumericFloat,
102
 
        
103
 
        RubyExports.constantOtherSymbol,
104
 
        {
105
 
            token: "text",
106
 
            regex: "=|-|~",
107
 
            next: "embedded_ruby"
108
 
        }
109
 
    ],
110
 
    "tag_single": [
111
 
        {
112
 
            token: "entity.other.attribute-name.class.haml",
113
 
            regex: "\\.[\\w-]+"
114
 
        },
115
 
        {
116
 
            token: "entity.other.attribute-name.id.haml",
117
 
            regex: "#[\\w-]+"
118
 
        },
119
 
        {
120
 
            token: "punctuation.section",
121
 
            regex: "\\{",
122
 
            next: "section"
123
 
        },
124
 
        
125
 
        RubyExports.constantOtherSymbol,
126
 
        
127
 
        {
128
 
            token: "text",
129
 
            regex: /\s/,
130
 
            next: "start"
131
 
        },
132
 
        {
133
 
            token: "empty",
134
 
            regex: "$|(?!\\.|#|\\{|\\[|=|-|~|\\/)",
135
 
            next: "start"
136
 
        }
137
 
    ],
138
 
    "section": [
139
 
        RubyExports.constantOtherSymbol,
140
 
        
141
 
        RubyExports.qString,
142
 
        RubyExports.qqString,
143
 
        RubyExports.tString,
144
 
        
145
 
        RubyExports.constantNumericHex,
146
 
        RubyExports.constantNumericFloat,
147
 
        {
148
 
            token: "punctuation.section",
149
 
            regex: "\\}",
150
 
            next: "start"
151
 
        } 
152
 
    ],
153
 
    "embedded_ruby": [ 
154
 
        RubyExports.constantNumericHex,
155
 
        RubyExports.constantNumericFloat,
156
 
        {
157
 
                token : "support.class", // class name
158
 
                regex : "[A-Z][a-zA-Z_\\d]+"
159
 
        },    
160
 
        {
161
 
            token : new RubyHighlightRules().getKeywords(),
162
 
            regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
163
 
        },
164
 
        {
165
 
            token : ["keyword", "text", "text"],
166
 
            regex : "(?:do|\\{)(?: \\|[^|]+\\|)?$",
167
 
            next  : "start"
168
 
        }, 
169
 
        {
170
 
            token : ["text"],
171
 
            regex : "^$",
172
 
            next  : "start"
173
 
        }, 
174
 
        {
175
 
            token : ["text"],
176
 
            regex : "^(?!.*\\|\\s*$)",
177
 
            next  : "start"
178
 
        }
179
 
    ]
180
 
}
181
 
 
182
 
};
183
 
 
184
 
oop.inherits(HamlHighlightRules, TextHighlightRules);
185
 
 
186
 
exports.HamlHighlightRules = HamlHighlightRules;
187
 
});
188
 
 
189
 
define('ace/mode/ruby_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
190
 
 
191
 
 
192
 
var oop = require("../lib/oop");
193
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
194
 
var constantOtherSymbol = exports.constantOtherSymbol = {
195
 
    token : "constant.other.symbol.ruby", // symbol
196
 
    regex : "[:](?:[A-Za-z_]|[@$](?=[a-zA-Z0-9_]))[a-zA-Z0-9_]*[!=?]?"
197
 
};
198
 
 
199
 
var qString = exports.qString = {
200
 
    token : "string", // single line
201
 
    regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
202
 
};
203
 
 
204
 
var qqString = exports.qqString = {
205
 
    token : "string", // single line
206
 
    regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
207
 
};
208
 
 
209
 
var tString = exports.tString = {
210
 
    token : "string", // backtick string
211
 
    regex : "[`](?:(?:\\\\.)|(?:[^'\\\\]))*?[`]"
212
 
};
213
 
 
214
 
var constantNumericHex = exports.constantNumericHex = {
215
 
    token : "constant.numeric", // hex
216
 
    regex : "0[xX][0-9a-fA-F](?:[0-9a-fA-F]|_(?=[0-9a-fA-F]))*\\b"
217
 
};
218
 
 
219
 
var constantNumericFloat = exports.constantNumericFloat = {
220
 
    token : "constant.numeric", // float
221
 
    regex : "[+-]?\\d(?:\\d|_(?=\\d))*(?:(?:\\.\\d(?:\\d|_(?=\\d))*)?(?:[eE][+-]?\\d+)?)?\\b"
222
 
};
223
 
 
224
 
var RubyHighlightRules = function() {
225
 
 
226
 
    var builtinFunctions = (
227
 
        "abort|Array|assert|assert_equal|assert_not_equal|assert_same|assert_not_same|" +
228
 
        "assert_nil|assert_not_nil|assert_match|assert_no_match|assert_in_delta|assert_throws|" +
229
 
        "assert_raise|assert_nothing_raised|assert_instance_of|assert_kind_of|assert_respond_to|" +
230
 
        "assert_operator|assert_send|assert_difference|assert_no_difference|assert_recognizes|" +
231
 
        "assert_generates|assert_response|assert_redirected_to|assert_template|assert_select|" +
232
 
        "assert_select_email|assert_select_rjs|assert_select_encoded|css_select|at_exit|" +
233
 
        "attr|attr_writer|attr_reader|attr_accessor|attr_accessible|autoload|binding|block_given?|callcc|" +
234
 
        "caller|catch|chomp|chomp!|chop|chop!|defined?|delete_via_redirect|eval|exec|exit|" +
235
 
        "exit!|fail|Float|flunk|follow_redirect!|fork|form_for|form_tag|format|gets|global_variables|gsub|" +
236
 
        "gsub!|get_via_redirect|h|host!|https?|https!|include|Integer|lambda|link_to|" +
237
 
        "link_to_unless_current|link_to_function|link_to_remote|load|local_variables|loop|open|open_session|" +
238
 
        "p|print|printf|proc|putc|puts|post_via_redirect|put_via_redirect|raise|rand|" +
239
 
        "raw|readline|readlines|redirect?|request_via_redirect|require|scan|select|" +
240
 
        "set_trace_func|sleep|split|sprintf|srand|String|stylesheet_link_tag|syscall|system|sub|sub!|test|" +
241
 
        "throw|trace_var|trap|untrace_var|atan2|cos|exp|frexp|ldexp|log|log10|sin|sqrt|tan|" +
242
 
        "render|javascript_include_tag|csrf_meta_tag|label_tag|text_field_tag|submit_tag|check_box_tag|" +
243
 
        "content_tag|radio_button_tag|text_area_tag|password_field_tag|hidden_field_tag|" +
244
 
        "fields_for|select_tag|options_for_select|options_from_collection_for_select|collection_select|" +
245
 
        "time_zone_select|select_date|select_time|select_datetime|date_select|time_select|datetime_select|" +
246
 
        "select_year|select_month|select_day|select_hour|select_minute|select_second|file_field_tag|" +
247
 
        "file_field|respond_to|skip_before_filter|around_filter|after_filter|verify|" +
248
 
        "protect_from_forgery|rescue_from|helper_method|redirect_to|before_filter|" +
249
 
        "send_data|send_file|validates_presence_of|validates_uniqueness_of|validates_length_of|" +
250
 
        "validates_format_of|validates_acceptance_of|validates_associated|validates_exclusion_of|" +
251
 
        "validates_inclusion_of|validates_numericality_of|validates_with|validates_each|" +
252
 
        "authenticate_or_request_with_http_basic|authenticate_or_request_with_http_digest|" +
253
 
        "filter_parameter_logging|match|get|post|resources|redirect|scope|assert_routing|" +
254
 
        "translate|localize|extract_locale_from_tld|t|l|caches_page|expire_page|caches_action|expire_action|" +
255
 
        "cache|expire_fragment|expire_cache_for|observe|cache_sweeper|" +
256
 
        "has_many|has_one|belongs_to|has_and_belongs_to_many"
257
 
    );
258
 
 
259
 
    var keywords = (
260
 
        "alias|and|BEGIN|begin|break|case|class|def|defined|do|else|elsif|END|end|ensure|" +
261
 
        "__FILE__|finally|for|gem|if|in|__LINE__|module|next|not|or|private|protected|public|" +
262
 
        "redo|rescue|retry|return|super|then|undef|unless|until|when|while|yield"
263
 
    );
264
 
 
265
 
    var buildinConstants = (
266
 
        "true|TRUE|false|FALSE|nil|NIL|ARGF|ARGV|DATA|ENV|RUBY_PLATFORM|RUBY_RELEASE_DATE|" +
267
 
        "RUBY_VERSION|STDERR|STDIN|STDOUT|TOPLEVEL_BINDING"
268
 
    );
269
 
 
270
 
    var builtinVariables = (
271
 
        "\$DEBUG|\$defout|\$FILENAME|\$LOAD_PATH|\$SAFE|\$stdin|\$stdout|\$stderr|\$VERBOSE|" +
272
 
        "$!|root_url|flash|session|cookies|params|request|response|logger|self"
273
 
    );
274
 
 
275
 
    var keywordMapper = this.$keywords = this.createKeywordMapper({
276
 
        "keyword": keywords,
277
 
        "constant.language": buildinConstants,
278
 
        "variable.language": builtinVariables,
279
 
        "support.function": builtinFunctions,
280
 
        "invalid.deprecated": "debugger" // TODO is this a remnant from js mode?
281
 
    }, "identifier");
282
 
 
283
 
    this.$rules = {
284
 
        "start" : [
285
 
            {
286
 
                token : "comment",
287
 
                regex : "#.*$"
288
 
            }, {
289
 
                token : "comment", // multi line comment
290
 
                regex : "^=begin(?:$|\\s.*$)",
291
 
                next : "comment"
292
 
            }, {
293
 
                token : "string.regexp",
294
 
                regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
295
 
            },
296
 
 
297
 
            qString,
298
 
            qqString,
299
 
            tString,
300
 
 
301
 
            {
302
 
                token : "text", // namespaces aren't symbols
303
 
                regex : "::"
304
 
            }, {
305
 
                token : "variable.instance", // instance variable
306
 
                regex : "@{1,2}[a-zA-Z_\\d]+"
307
 
            }, {
308
 
                token : "support.class", // class name
309
 
                regex : "[A-Z][a-zA-Z_\\d]+"
310
 
            },
311
 
 
312
 
            constantOtherSymbol,
313
 
            constantNumericHex,
314
 
            constantNumericFloat,
315
 
 
316
 
            {
317
 
                token : "constant.language.boolean",
318
 
                regex : "(?:true|false)\\b"
319
 
            }, {
320
 
                token : keywordMapper,
321
 
                regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
322
 
            }, {
323
 
                token : "punctuation.separator.key-value",
324
 
                regex : "=>"
325
 
            }, {
326
 
                stateName: "heredoc",
327
 
                onMatch : function(value, currentState, stack) {
328
 
                    var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
329
 
                    var tokens = value.split(this.splitRegex);
330
 
                    stack.push(next, tokens[3]);
331
 
                    return [
332
 
                        {type:"constant", value: tokens[1]},
333
 
                        {type:"string", value: tokens[2]},
334
 
                        {type:"support.class", value: tokens[3]},
335
 
                        {type:"string", value: tokens[4]}
336
 
                    ];
337
 
                },
338
 
                regex : "(<<-?)(['\"`]?)([\\w]+)(['\"`]?)",
339
 
                rules: {
340
 
                    heredoc: [{
341
 
                        onMatch:  function(value, currentState, stack) {
342
 
                            if (value == stack[1]) {
343
 
                                stack.shift();
344
 
                                stack.shift();
345
 
                                return "support.class";
346
 
                            }
347
 
                            return "string";
348
 
                        },
349
 
                        regex: ".*$",
350
 
                        next: "start"
351
 
                    }],
352
 
                    indentedHeredoc: [{
353
 
                        token: "string",
354
 
                        regex: "^ +"
355
 
                    }, {
356
 
                        onMatch:  function(value, currentState, stack) {
357
 
                            if (value == stack[1]) {
358
 
                                stack.shift();
359
 
                                stack.shift();
360
 
                                return "support.class";
361
 
                            }
362
 
                            return "string";
363
 
                        },
364
 
                        regex: ".*$",
365
 
                        next: "start"
366
 
                    }]
367
 
                }
368
 
            }, {
369
 
                token : "keyword.operator",
370
 
                regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
371
 
            }, {
372
 
                token : "paren.lparen",
373
 
                regex : "[[({]"
374
 
            }, {
375
 
                token : "paren.rparen",
376
 
                regex : "[\\])}]"
377
 
            }, {
378
 
                token : "text",
379
 
                regex : "\\s+"
380
 
            }
381
 
        ],
382
 
        "comment" : [
383
 
            {
384
 
                token : "comment", // closing comment
385
 
                regex : "^=end(?:$|\\s.*$)",
386
 
                next : "start"
387
 
            }, {
388
 
                token : "comment", // comment spanning whole line
389
 
                regex : ".+"
390
 
            }
391
 
        ]
392
 
    };
393
 
 
394
 
    this.normalizeRules();
395
 
};
396
 
 
397
 
oop.inherits(RubyHighlightRules, TextHighlightRules);
398
 
 
399
 
exports.RubyHighlightRules = RubyHighlightRules;
400
 
});
401
 
 
402
 
define('ace/mode/folding/coffee', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
403
 
 
404
 
 
405
 
var oop = require("../../lib/oop");
406
 
var BaseFoldMode = require("./fold_mode").FoldMode;
407
 
var Range = require("../../range").Range;
408
 
 
409
 
var FoldMode = exports.FoldMode = function() {};
410
 
oop.inherits(FoldMode, BaseFoldMode);
411
 
 
412
 
(function() {
413
 
 
414
 
    this.getFoldWidgetRange = function(session, foldStyle, row) {
415
 
        var range = this.indentationBlock(session, row);
416
 
        if (range)
417
 
            return range;
418
 
 
419
 
        var re = /\S/;
420
 
        var line = session.getLine(row);
421
 
        var startLevel = line.search(re);
422
 
        if (startLevel == -1 || line[startLevel] != "#")
423
 
            return;
424
 
 
425
 
        var startColumn = line.length;
426
 
        var maxRow = session.getLength();
427
 
        var startRow = row;
428
 
        var endRow = row;
429
 
 
430
 
        while (++row < maxRow) {
431
 
            line = session.getLine(row);
432
 
            var level = line.search(re);
433
 
 
434
 
            if (level == -1)
435
 
                continue;
436
 
 
437
 
            if (line[level] != "#")
438
 
                break;
439
 
 
440
 
            endRow = row;
441
 
        }
442
 
 
443
 
        if (endRow > startRow) {
444
 
            var endColumn = session.getLine(endRow).length;
445
 
            return new Range(startRow, startColumn, endRow, endColumn);
446
 
        }
447
 
    };
448
 
    this.getFoldWidget = function(session, foldStyle, row) {
449
 
        var line = session.getLine(row);
450
 
        var indent = line.search(/\S/);
451
 
        var next = session.getLine(row + 1);
452
 
        var prev = session.getLine(row - 1);
453
 
        var prevIndent = prev.search(/\S/);
454
 
        var nextIndent = next.search(/\S/);
455
 
 
456
 
        if (indent == -1) {
457
 
            session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
458
 
            return "";
459
 
        }
460
 
        if (prevIndent == -1) {
461
 
            if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
462
 
                session.foldWidgets[row - 1] = "";
463
 
                session.foldWidgets[row + 1] = "";
464
 
                return "start";
465
 
            }
466
 
        } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
467
 
            if (session.getLine(row - 2).search(/\S/) == -1) {
468
 
                session.foldWidgets[row - 1] = "start";
469
 
                session.foldWidgets[row + 1] = "";
470
 
                return "";
471
 
            }
472
 
        }
473
 
 
474
 
        if (prevIndent!= -1 && prevIndent < indent)
475
 
            session.foldWidgets[row - 1] = "start";
476
 
        else
477
 
            session.foldWidgets[row - 1] = "";
478
 
 
479
 
        if (indent < nextIndent)
480
 
            return "start";
481
 
        else
482
 
            return "";
483
 
    };
484
 
 
485
 
}).call(FoldMode.prototype);
486
 
 
487
 
});