CodeMirror.defineMode("ruby",function(e){function t(e){for(var t={},n=0,r=e.length;r>n;++n)t[e[n]]=!0;return t}function n(e,t,n){return n.tokenize.push(e),e(t,n)}function r(e,t){if(u=null,e.sol()&&e.match("=begin")&&e.eol())return t.tokenize.push(l),"comment";if(e.eatSpace())return null;var r,i=e.next();if("`"==i||"'"==i||'"'==i||"/"==i&&!e.eol()&&" "!=e.peek())return n(o(i,"string",'"'==i||"`"==i),e,t);if("%"==i){var d,s=!1;e.eat("s")?d="atom":e.eat(/[WQ]/)?(d="string",s=!0):e.eat(/[wxqr]/)&&(d="string");var c=e.eat(/[^\w\s]/);return c?(f.propertyIsEnumerable(c)&&(c=f[c]),n(o(c,d,s,!0),e,t)):"operator"}if("#"==i)return e.skipToEnd(),"comment";if("<"==i&&(r=e.match(/^<-?[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/)))return n(a(r[1]),e,t);if("0"==i)return e.eat("x")?e.eatWhile(/[\da-fA-F]/):e.eat("b")?e.eatWhile(/[01]/):e.eatWhile(/[0-7]/),"number";if(/\d/.test(i))return e.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/),"number";if("?"==i){for(;e.match(/^\\[CM]-/););return e.eat("\\")?e.eatWhile(/\w/):e.next(),"string"}return":"==i?e.eat("'")?n(o("'","atom",!1),e,t):e.eat('"')?n(o('"',"atom",!0),e,t):(e.eatWhile(/[\w\?]/),"atom"):"@"==i?(e.eat("@"),e.eatWhile(/[\w\?]/),"variable-2"):"$"==i?(e.next(),e.eatWhile(/[\w\?]/),"variable-3"):/\w/.test(i)?(e.eatWhile(/[\w\?]/),e.eat(":")?"atom":"ident"):"|"!=i||!t.varList&&"{"!=t.lastTok&&"do"!=t.lastTok?/[\(\)\[\]{}\\;]/.test(i)?(u=i,null):"-"==i&&e.eat(">")?"arrow":/[=+\-\/*:\.^%<>~|]/.test(i)?(e.eatWhile(/[=+\-\/*:\.^%<>~|]/),"operator"):null:(u="|",null)}function i(){var e=1;return function(t,n){if("}"==t.peek()){if(e--,0==e)return n.tokenize.pop(),n.tokenize[n.tokenize.length-1](t,n)}else"{"==t.peek()&&e++;return r(t,n)}}function o(e,t,n,r){return function(o,a){for(var l,u=!1;null!=(l=o.next());){if(l==e&&(r||!u)){a.tokenize.pop();break}if(n&&"#"==l&&!u&&o.eat("{")){a.tokenize.push(i(arguments.callee));break}u=!u&&"\\"==l}return t}}function a(e){return function(t,n){return t.match(e)?n.tokenize.pop():t.skipToEnd(),"string"}}function l(e,t){return e.sol()&&e.match("=end")&&e.eol()&&t.tokenize.pop(),e.skipToEnd(),"comment"}var u,d=t(["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"]),s=t(["def","class","case","for","while","do","module","then","catch","loop","proc","begin"]),c=t(["end","until"]),f={"[":"]","{":"}","(":")"};return{startState:function(){return{tokenize:[r],indented:0,context:{type:"top",indented:-e.indentUnit},continuedLine:!1,lastTok:null,varList:!1}},token:function(e,t){e.sol()&&(t.indented=e.indentation());var n,r=t.tokenize[t.tokenize.length-1](e,t);if("ident"==r){var i=e.current();r=d.propertyIsEnumerable(e.current())?"keyword":/^[A-Z]/.test(i)?"tag":"def"==t.lastTok||"class"==t.lastTok||t.varList?"def":"variable",s.propertyIsEnumerable(i)?n="indent":c.propertyIsEnumerable(i)?n="dedent":"if"!=i&&"unless"!=i||e.column()!=e.indentation()||(n="indent")}return(u||r&&"comment"!=r)&&(t.lastTok=i||u||r),"|"==u&&(t.varList=!t.varList),"indent"==n||/[\(\[\{]/.test(u)?t.context={prev:t.context,type:u||r,indented:t.indented}:("dedent"==n||/[\)\]\}]/.test(u))&&t.context.prev&&(t.context=t.context.prev),e.eol()&&(t.continuedLine="\\"==u||"operator"==r),r},indent:function(t,n){if(t.tokenize[t.tokenize.length-1]!=r)return 0;var i=n&&n.charAt(0),o=t.context,a=o.type==f[i]||"keyword"==o.type&&/^(?:end|until|else|elsif|when|rescue)\b/.test(n);return o.indented+(a?0:e.indentUnit)+(t.continuedLine?e.indentUnit:0)},electricChars:"}de"}}),CodeMirror.defineMIME("text/x-ruby","ruby");