Files
cdnjs/ajax/libs/codemirror/2.36.0/ruby.min.js
T
2013-04-14 11:51:00 +10:00

1 line
3.8 KiB
JavaScript

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