1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
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.
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.
29
* ***** END LICENSE BLOCK ***** */
31
define('ace/mode/ruby', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/ruby_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range', 'ace/mode/folding/coffee'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var TextMode = require("./text").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var RubyHighlightRules = require("./ruby_highlight_rules").RubyHighlightRules;
38
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39
var Range = require("../range").Range;
40
var FoldMode = require("./folding/coffee").FoldMode;
42
var Mode = function() {
43
this.$tokenizer = new Tokenizer(new RubyHighlightRules().getRules());
44
this.$outdent = new MatchingBraceOutdent();
45
this.foldingRules = new FoldMode();
47
oop.inherits(Mode, TextMode);
52
this.lineCommentStart = "#";
54
this.getNextLineIndent = function(state, line, tab) {
55
var indent = this.$getIndent(line);
57
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
58
var tokens = tokenizedLine.tokens;
60
if (tokens.length && tokens[tokens.length-1].type == "comment") {
64
if (state == "start") {
65
var match = line.match(/^.*[\{\(\[]\s*$/);
74
this.checkOutdent = function(state, line, input) {
75
return this.$outdent.checkOutdent(line, input);
78
this.autoOutdent = function(state, doc, row) {
79
this.$outdent.autoOutdent(doc, row);
82
}).call(Mode.prototype);
87
define('ace/mode/ruby_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
90
var oop = require("../lib/oop");
91
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
92
var constantOtherSymbol = exports.constantOtherSymbol = {
93
token : "constant.other.symbol.ruby", // symbol
94
regex : "[:](?:[A-Za-z_]|[@$](?=[a-zA-Z0-9_]))[a-zA-Z0-9_]*[!=?]?"
97
var qString = exports.qString = {
98
token : "string", // single line
99
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
102
var qqString = exports.qqString = {
103
token : "string", // single line
104
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
107
var tString = exports.tString = {
108
token : "string", // backtick string
109
regex : "[`](?:(?:\\\\.)|(?:[^'\\\\]))*?[`]"
112
var constantNumericHex = exports.constantNumericHex = {
113
token : "constant.numeric", // hex
114
regex : "0[xX][0-9a-fA-F](?:[0-9a-fA-F]|_(?=[0-9a-fA-F]))*\\b"
117
var constantNumericFloat = exports.constantNumericFloat = {
118
token : "constant.numeric", // float
119
regex : "[+-]?\\d(?:\\d|_(?=\\d))*(?:(?:\\.\\d(?:\\d|_(?=\\d))*)?(?:[eE][+-]?\\d+)?)?\\b"
122
var RubyHighlightRules = function() {
124
var builtinFunctions = (
125
"abort|Array|assert|assert_equal|assert_not_equal|assert_same|assert_not_same|" +
126
"assert_nil|assert_not_nil|assert_match|assert_no_match|assert_in_delta|assert_throws|" +
127
"assert_raise|assert_nothing_raised|assert_instance_of|assert_kind_of|assert_respond_to|" +
128
"assert_operator|assert_send|assert_difference|assert_no_difference|assert_recognizes|" +
129
"assert_generates|assert_response|assert_redirected_to|assert_template|assert_select|" +
130
"assert_select_email|assert_select_rjs|assert_select_encoded|css_select|at_exit|" +
131
"attr|attr_writer|attr_reader|attr_accessor|attr_accessible|autoload|binding|block_given?|callcc|" +
132
"caller|catch|chomp|chomp!|chop|chop!|defined?|delete_via_redirect|eval|exec|exit|" +
133
"exit!|fail|Float|flunk|follow_redirect!|fork|form_for|form_tag|format|gets|global_variables|gsub|" +
134
"gsub!|get_via_redirect|h|host!|https?|https!|include|Integer|lambda|link_to|" +
135
"link_to_unless_current|link_to_function|link_to_remote|load|local_variables|loop|open|open_session|" +
136
"p|print|printf|proc|putc|puts|post_via_redirect|put_via_redirect|raise|rand|" +
137
"raw|readline|readlines|redirect?|request_via_redirect|require|scan|select|" +
138
"set_trace_func|sleep|split|sprintf|srand|String|stylesheet_link_tag|syscall|system|sub|sub!|test|" +
139
"throw|trace_var|trap|untrace_var|atan2|cos|exp|frexp|ldexp|log|log10|sin|sqrt|tan|" +
140
"render|javascript_include_tag|csrf_meta_tag|label_tag|text_field_tag|submit_tag|check_box_tag|" +
141
"content_tag|radio_button_tag|text_area_tag|password_field_tag|hidden_field_tag|" +
142
"fields_for|select_tag|options_for_select|options_from_collection_for_select|collection_select|" +
143
"time_zone_select|select_date|select_time|select_datetime|date_select|time_select|datetime_select|" +
144
"select_year|select_month|select_day|select_hour|select_minute|select_second|file_field_tag|" +
145
"file_field|respond_to|skip_before_filter|around_filter|after_filter|verify|" +
146
"protect_from_forgery|rescue_from|helper_method|redirect_to|before_filter|" +
147
"send_data|send_file|validates_presence_of|validates_uniqueness_of|validates_length_of|" +
148
"validates_format_of|validates_acceptance_of|validates_associated|validates_exclusion_of|" +
149
"validates_inclusion_of|validates_numericality_of|validates_with|validates_each|" +
150
"authenticate_or_request_with_http_basic|authenticate_or_request_with_http_digest|" +
151
"filter_parameter_logging|match|get|post|resources|redirect|scope|assert_routing|" +
152
"translate|localize|extract_locale_from_tld|t|l|caches_page|expire_page|caches_action|expire_action|" +
153
"cache|expire_fragment|expire_cache_for|observe|cache_sweeper|" +
154
"has_many|has_one|belongs_to|has_and_belongs_to_many"
158
"alias|and|BEGIN|begin|break|case|class|def|defined|do|else|elsif|END|end|ensure|" +
159
"__FILE__|finally|for|gem|if|in|__LINE__|module|next|not|or|private|protected|public|" +
160
"redo|rescue|retry|return|super|then|undef|unless|until|when|while|yield"
163
var buildinConstants = (
164
"true|TRUE|false|FALSE|nil|NIL|ARGF|ARGV|DATA|ENV|RUBY_PLATFORM|RUBY_RELEASE_DATE|" +
165
"RUBY_VERSION|STDERR|STDIN|STDOUT|TOPLEVEL_BINDING"
168
var builtinVariables = (
169
"\$DEBUG|\$defout|\$FILENAME|\$LOAD_PATH|\$SAFE|\$stdin|\$stdout|\$stderr|\$VERBOSE|" +
170
"$!|root_url|flash|session|cookies|params|request|response|logger|self"
173
var keywordMapper = this.$keywords = this.createKeywordMapper({
175
"constant.language": buildinConstants,
176
"variable.language": builtinVariables,
177
"support.function": builtinFunctions,
178
"invalid.deprecated": "debugger" // TODO is this a remnant from js mode?
187
token : "comment", // multi line comment
188
regex : "^=begin(?:$|\\s.*$)",
191
token : "string.regexp",
192
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
200
token : "text", // namespaces aren't symbols
203
token : "variable.instance", // instance variable
204
regex : "@{1,2}[a-zA-Z_\\d]+"
206
token : "support.class", // class name
207
regex : "[A-Z][a-zA-Z_\\d]+"
212
constantNumericFloat,
215
token : "constant.language.boolean",
216
regex : "(?:true|false)\\b"
218
token : keywordMapper,
219
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
221
token : "punctuation.separator.key-value",
224
stateName: "heredoc",
225
onMatch : function(value, currentState, stack) {
226
var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
227
var tokens = value.split(this.splitRegex);
228
stack.push(next, tokens[3]);
230
{type:"constant", value: tokens[1]},
231
{type:"string", value: tokens[2]},
232
{type:"support.class", value: tokens[3]},
233
{type:"string", value: tokens[4]}
236
regex : "(<<-?)(['\"`]?)([\\w]+)(['\"`]?)",
239
onMatch: function(value, currentState, stack) {
240
if (value == stack[1]) {
243
return "support.class";
254
onMatch: function(value, currentState, stack) {
255
if (value == stack[1]) {
258
return "support.class";
267
token : "keyword.operator",
268
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
270
token : "paren.lparen",
273
token : "paren.rparen",
282
token : "comment", // closing comment
283
regex : "^=end(?:$|\\s.*$)",
286
token : "comment", // comment spanning whole line
292
this.normalizeRules();
295
oop.inherits(RubyHighlightRules, TextHighlightRules);
297
exports.RubyHighlightRules = RubyHighlightRules;
300
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
303
var Range = require("../range").Range;
305
var MatchingBraceOutdent = function() {};
309
this.checkOutdent = function(line, input) {
310
if (! /^\s+$/.test(line))
313
return /^\s*\}/.test(input);
316
this.autoOutdent = function(doc, row) {
317
var line = doc.getLine(row);
318
var match = line.match(/^(\s*\})/);
320
if (!match) return 0;
322
var column = match[1].length;
323
var openBracePos = doc.findMatchingBracket({row: row, column: column});
325
if (!openBracePos || openBracePos.row == row) return 0;
327
var indent = this.$getIndent(doc.getLine(openBracePos.row));
328
doc.replace(new Range(row, 0, row, column-1), indent);
331
this.$getIndent = function(line) {
332
return line.match(/^\s*/)[0];
335
}).call(MatchingBraceOutdent.prototype);
337
exports.MatchingBraceOutdent = MatchingBraceOutdent;
340
define('ace/mode/folding/coffee', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
343
var oop = require("../../lib/oop");
344
var BaseFoldMode = require("./fold_mode").FoldMode;
345
var Range = require("../../range").Range;
347
var FoldMode = exports.FoldMode = function() {};
348
oop.inherits(FoldMode, BaseFoldMode);
352
this.getFoldWidgetRange = function(session, foldStyle, row) {
353
var range = this.indentationBlock(session, row);
358
var line = session.getLine(row);
359
var startLevel = line.search(re);
360
if (startLevel == -1 || line[startLevel] != "#")
363
var startColumn = line.length;
364
var maxRow = session.getLength();
368
while (++row < maxRow) {
369
line = session.getLine(row);
370
var level = line.search(re);
375
if (line[level] != "#")
381
if (endRow > startRow) {
382
var endColumn = session.getLine(endRow).length;
383
return new Range(startRow, startColumn, endRow, endColumn);
386
this.getFoldWidget = function(session, foldStyle, row) {
387
var line = session.getLine(row);
388
var indent = line.search(/\S/);
389
var next = session.getLine(row + 1);
390
var prev = session.getLine(row - 1);
391
var prevIndent = prev.search(/\S/);
392
var nextIndent = next.search(/\S/);
395
session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
398
if (prevIndent == -1) {
399
if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
400
session.foldWidgets[row - 1] = "";
401
session.foldWidgets[row + 1] = "";
404
} else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
405
if (session.getLine(row - 2).search(/\S/) == -1) {
406
session.foldWidgets[row - 1] = "start";
407
session.foldWidgets[row + 1] = "";
412
if (prevIndent!= -1 && prevIndent < indent)
413
session.foldWidgets[row - 1] = "start";
415
session.foldWidgets[row - 1] = "";
417
if (indent < nextIndent)
423
}).call(FoldMode.prototype);