: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
})(function(CodeMirror) {
CodeMirror.defineMode("ruby", function(config) {
function wordObj(words) {
for (var i = 0, e = words.length; i < e; ++i) o[words[i]] = true;
"alias", "and", "BEGIN", "begin", "break", "case", "class", "def", "defined?", "do", "else",
"elsif", "END", "end", "ensure", "false", "for", "if", "in", "module", "next", "not", "or",
"redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless",
"until", "when", "while", "yield", "nil", "raise", "throw", "catch", "fail", "loop", "callcc",
"caller", "lambda", "proc", "public", "protected", "private", "require", "load",
"require_relative", "extend", "autoload", "__END__", "__FILE__", "__LINE__", "__dir__"
var indentWords = wordObj(["def", "class", "case", "for", "while", "until", "module", "then",
"catch", "loop", "proc", "begin"]);
var dedentWords = wordObj(["end", "until"]);
var matching = {"[": "]", "{": "}", "(": ")"};
function chain(newtok, stream, state) {
state.tokenize.push(newtok);
return newtok(stream, state);
function tokenBase(stream, state) {
if (stream.sol() && stream.match("=begin") && stream.eol()) {
state.tokenize.push(readBlockComment);
if (stream.eatSpace()) return null;
var ch = stream.next(), m;
if (ch == "`" || ch == "'" || ch == '"') {
return chain(readQuoted(ch, "string", ch == '"' || ch == "`"), stream, state);
var currentIndex = stream.current().length;
if (stream.skipTo("/")) {
var search_till = stream.current().length;
stream.backUp(stream.current().length - currentIndex);
var balance = 0; // balance brackets
while (stream.current().length < search_till) {
var chchr = stream.next();
if (chchr == "(") balance += 1;
else if (chchr == ")") balance -= 1;
stream.backUp(stream.current().length - currentIndex);
return chain(readQuoted(ch, "string-2", true), stream, state);
var style = "string", embed = true;
if (stream.eat("s")) style = "atom";
else if (stream.eat(/[WQ]/)) style = "string";
else if (stream.eat(/[r]/)) style = "string-2";
else if (stream.eat(/[wxq]/)) { style = "string"; embed = false; }
var delim = stream.eat(/[^\w\s=]/);
if (!delim) return "operator";
if (matching.propertyIsEnumerable(delim)) delim = matching[delim];
return chain(readQuoted(delim, style, embed, true), stream, state);
} else if (ch == "<" && (m = stream.match(/^<-?[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/))) {
return chain(readHereDoc(m[1]), stream, state);
if (stream.eat("x")) stream.eatWhile(/[\da-fA-F]/);
else if (stream.eat("b")) stream.eatWhile(/[01]/);
else stream.eatWhile(/[0-7]/);
} else if (/\d/.test(ch)) {
stream.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/);
while (stream.match(/^\\[CM]-/)) {}
if (stream.eat("\\")) stream.eatWhile(/\w/);
if (stream.eat("'")) return chain(readQuoted("'", "atom", false), stream, state);
if (stream.eat('"')) return chain(readQuoted('"', "atom", true), stream, state);
// :> :>> :< :<< are valid symbols
if (stream.eat(/[\<\>]/)) {
// :+ :- :/ :* :| :& :! are valid symbols
if (stream.eat(/[\+\-\*\/\&\|\:\!]/)) {
// Symbols can't start by a digit
if (stream.eat(/[a-zA-Z$@_\xa1-\uffff]/)) {
stream.eatWhile(/[\w$\xa1-\uffff]/);
// Only one ? ! = is allowed and only as the last character
} else if (ch == "@" && stream.match(/^@?[a-zA-Z_\xa1-\uffff]/)) {
stream.eatWhile(/[\w\xa1-\uffff]/);
if (stream.eat(/[a-zA-Z_]/)) {
} else if (stream.eat(/\d/)) {
stream.next(); // Must be a special global like $: or $!
} else if (/[a-zA-Z_\xa1-\uffff]/.test(ch)) {
stream.eatWhile(/[\w\xa1-\uffff]/);
if (stream.eat(":")) return "atom";
} else if (ch == "|" && (state.varList || state.lastTok == "{" || state.lastTok == "do")) {
} else if (/[\(\)\[\]{}\\;]/.test(ch)) {
} else if (ch == "-" && stream.eat(">")) {
} else if (/[=+\-\/*:\.^%<>~|]/.test(ch)) {
var more = stream.eatWhile(/[=+\-\/*:\.^%<>~|]/);
if (ch == "." && !more) curPunc = ".";
function tokenBaseUntilBrace(depth) {
return function(stream, state) {
if (stream.peek() == "}") {
return state.tokenize[state.tokenize.length-1](stream, state);
state.tokenize[state.tokenize.length - 1] = tokenBaseUntilBrace(depth - 1);
} else if (stream.peek() == "{") {
state.tokenize[state.tokenize.length - 1] = tokenBaseUntilBrace(depth + 1);
return tokenBase(stream, state);
function tokenBaseOnce() {
var alreadyCalled = false;
return function(stream, state) {
return state.tokenize[state.tokenize.length-1](stream, state);
return tokenBase(stream, state);
function readQuoted(quote, style, embed, unescaped) {
return function(stream, state) {
if (state.context.type === 'read-quoted-paused') {
state.context = state.context.prev;
while ((ch = stream.next()) != null) {
if (ch == quote && (unescaped || !escaped)) {
if (embed && ch == "#" && !escaped) {
state.context = {prev: state.context, type: 'read-quoted-paused'};
state.tokenize.push(tokenBaseUntilBrace());
} else if (/[@\$]/.test(stream.peek())) {
state.tokenize.push(tokenBaseOnce());
escaped = !escaped && ch == "\\";
function readHereDoc(phrase) {
return function(stream, state) {
if (stream.match(phrase)) state.tokenize.pop();
function readBlockComment(stream, state) {
if (stream.sol() && stream.match("=end") && stream.eol())
return {tokenize: [tokenBase],
context: {type: "top", indented: -config.indentUnit},
token: function(stream, state) {
if (stream.sol()) state.indented = stream.indentation();
var style = state.tokenize[state.tokenize.length-1](stream, state), kwtype;
var word = stream.current();
style = state.lastTok == "." ? "property"
: keywords.propertyIsEnumerable(stream.current()) ? "keyword"
: /^[A-Z]/.test(word) ? "tag"
: (state.lastTok == "def" || state.lastTok == "class" || state.varList) ? "def"
if (style == "keyword") {
if (indentWords.propertyIsEnumerable(word)) kwtype = "indent";
else if (dedentWords.propertyIsEnumerable(word)) kwtype = "dedent";
else if ((word == "if" || word == "unless") && stream.column() == stream.indentation())
else if (word == "do" && state.context.indented < state.indented)
if (curPunc || (style && style != "comment")) state.lastTok = thisTok;
if (curPunc == "|") state.varList = !state.varList;
if (kwtype == "indent" || /[\(\[\{]/.test(curPunc))
state.context = {prev: state.context, type: curPunc || style, indented: state.indented};
else if ((kwtype == "dedent" || /[\)\]\}]/.test(curPunc)) && state.context.prev)
state.context = state.context.prev;
state.continuedLine = (curPunc == "\\" || style == "operator");
indent: function(state, textAfter) {
if (state.tokenize[state.tokenize.length-1] != tokenBase) return 0;
var firstChar = textAfter && textAfter.charAt(0);
var closing = ct.type == matching[firstChar] ||
ct.type == "keyword" && /^(?:end|until|else|elsif|when|rescue)\b/.test(textAfter);
return ct.indented + (closing ? 0 : config.indentUnit) +
(state.continuedLine ? config.indentUnit : 0);
electricInput: /^\s*(?:end|rescue|\})$/,
CodeMirror.defineMIME("text/x-ruby", "ruby");