You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
5.0 KiB
1 lines
5.0 KiB
function p(e){for(var n={},t=0,a=e.length;t<a;++t)n[e[t]]=!0;return n}var m=["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__"],h=p(m),x=p(["def","class","case","for","while","until","module","catch","loop","proc","begin"]),v=p(["end","until"]),k={"[":"]","{":"}","(":")"},z={"]":"[","}":"{",")":"("},i;function f(e,n,t){return t.tokenize.push(e),e(n,t)}function d(e,n){if(e.sol()&&e.match("=begin")&&e.eol())return n.tokenize.push(y),"comment";if(e.eatSpace())return null;var t=e.next(),a;if(t=="`"||t=="'"||t=='"')return f(s(t,"string",t=='"'||t=="`"),e,n);if(t=="/")return b(e)?f(s(t,"string.special",!0),e,n):"operator";if(t=="%"){var o="string",r=!0;e.eat("s")?o="atom":e.eat(/[WQ]/)?o="string":e.eat(/[r]/)?o="string.special":e.eat(/[wxq]/)&&(o="string",r=!1);var u=e.eat(/[^\w\s=]/);return u?(k.propertyIsEnumerable(u)&&(u=k[u]),f(s(u,o,r,!0),e,n)):"operator"}else{if(t=="#")return e.skipToEnd(),"comment";if(t=="<"&&(a=e.match(/^<([-~])[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/)))return f(g(a[2],a[1]),e,n);if(t=="0")return e.eat("x")?e.eatWhile(/[\da-fA-F]/):e.eat("b")?e.eatWhile(/[01]/):e.eatWhile(/[0-7]/),"number";if(/\d/.test(t))return e.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/),"number";if(t=="?"){for(;e.match(/^\\[CM]-/););return e.eat("\\")?e.eatWhile(/\w/):e.next(),"string"}else{if(t==":")return e.eat("'")?f(s("'","atom",!1),e,n):e.eat('"')?f(s('"',"atom",!0),e,n):e.eat(/[\<\>]/)?(e.eat(/[\<\>]/),"atom"):e.eat(/[\+\-\*\/\&\|\:\!]/)?"atom":e.eat(/[a-zA-Z$@_\xa1-\uffff]/)?(e.eatWhile(/[\w$\xa1-\uffff]/),e.eat(/[\?\!\=]/),"atom"):"operator";if(t=="@"&&e.match(/^@?[a-zA-Z_\xa1-\uffff]/))return e.eat("@"),e.eatWhile(/[\w\xa1-\uffff]/),"propertyName";if(t=="$")return e.eat(/[a-zA-Z_]/)?e.eatWhile(/[\w]/):e.eat(/\d/)?e.eat(/\d/):e.next(),"variableName.special";if(/[a-zA-Z_\xa1-\uffff]/.test(t))return e.eatWhile(/[\w\xa1-\uffff]/),e.eat(/[\?\!]/),e.eat(":")?"atom":"variable";if(t=="|"&&(n.varList||n.lastTok=="{"||n.lastTok=="do"))return i="|",null;if(/[\(\)\[\]{}\\;]/.test(t))return i=t,null;if(t=="-"&&e.eat(">"))return"operator";if(/[=+\-\/*:\.^%<>~|]/.test(t)){var l=e.eatWhile(/[=+\-\/*:\.^%<>~|]/);return t=="."&&!l&&(i="."),"operator"}else return null}}}function b(e){for(var n=e.pos,t=0,a,o=!1,r=!1;(a=e.next())!=null;)if(r)r=!1;else{if("[{(".indexOf(a)>-1)t++;else if("]})".indexOf(a)>-1){if(t--,t<0)break}else if(a=="/"&&t==0){o=!0;break}r=a=="\\"}return e.backUp(e.pos-n),o}function c(e){return e||(e=1),function(n,t){if(n.peek()=="}"){if(e==1)return t.tokenize.pop(),t.tokenize[t.tokenize.length-1](n,t);t.tokenize[t.tokenize.length-1]=c(e-1)}else n.peek()=="{"&&(t.tokenize[t.tokenize.length-1]=c(e+1));return d(n,t)}}function _(){var e=!1;return function(n,t){return e?(t.tokenize.pop(),t.tokenize[t.tokenize.length-1](n,t)):(e=!0,d(n,t))}}function s(e,n,t,a){return function(o,r){var u=!1,l;for(r.context.type==="read-quoted-paused"&&(r.context=r.context.prev,o.eat("}"));(l=o.next())!=null;){if(l==e&&(a||!u)){r.tokenize.pop();break}if(t&&l=="#"&&!u){if(o.eat("{")){e=="}"&&(r.context={prev:r.context,type:"read-quoted-paused"}),r.tokenize.push(c());break}else if(/[@\$]/.test(o.peek())){r.tokenize.push(_());break}}u=!u&&l=="\\"}return n}}function g(e,n){return function(t,a){return n&&t.eatSpace(),t.match(e)?a.tokenize.pop():t.skipToEnd(),"string"}}function y(e,n){return e.sol()&&e.match("=end")&&e.eol()&&n.tokenize.pop(),e.skipToEnd(),"comment"}const w={name:"ruby",startState:function(e){return{tokenize:[d],indented:0,context:{type:"top",indented:-e},continuedLine:!1,lastTok:null,varList:!1}},token:function(e,n){i=null,e.sol()&&(n.indented=e.indentation());var t=n.tokenize[n.tokenize.length-1](e,n),a,o=i;if(t=="variable"){var r=e.current();t=n.lastTok=="."?"property":h.propertyIsEnumerable(e.current())?"keyword":/^[A-Z]/.test(r)?"tag":n.lastTok=="def"||n.lastTok=="class"||n.varList?"def":"variable",t=="keyword"&&(o=r,x.propertyIsEnumerable(r)?a="indent":v.propertyIsEnumerable(r)?a="dedent":((r=="if"||r=="unless")&&e.column()==e.indentation()||r=="do"&&n.context.indented<n.indented)&&(a="indent"))}return(i||t&&t!="comment")&&(n.lastTok=o),i=="|"&&(n.varList=!n.varList),a=="indent"||/[\(\[\{]/.test(i)?n.context={prev:n.context,type:i||t,indented:n.indented}:(a=="dedent"||/[\)\]\}]/.test(i))&&n.context.prev&&(n.context=n.context.prev),e.eol()&&(n.continuedLine=i=="\\"||t=="operator"),t},indent:function(e,n,t){if(e.tokenize[e.tokenize.length-1]!=d)return null;var a=n&&n.charAt(0),o=e.context,r=o.type==z[a]||o.type=="keyword"&&/^(?:end|until|else|elsif|when|rescue)\b/.test(n);return o.indented+(r?0:t.unit)+(e.continuedLine?t.unit:0)},languageData:{indentOnInput:/^\s*(?:end|rescue|elsif|else|\})$/,commentTokens:{line:"#"},autocomplete:m}};export{w as ruby};
|