物管理前端
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
2.9 KiB

function o(t){for(var e={},r=0;r<t.length;++r)e[t[r]]=!0;return e}var k=["NULL","NA","Inf","NaN","NA_integer_","NA_real_","NA_complex_","NA_character_","TRUE","FALSE"],b=["list","quote","bquote","eval","return","call","parse","deparse"],g=["if","else","repeat","while","function","for","in","next","break"],h=["if","else","repeat","while","function","for"],v=o(k),y=o(b),N=o(g),A=o(h),m=/[+\-*\/^<>=!&|~$:]/,c;function s(t,e){c=null;var r=t.next();if(r=="#")return t.skipToEnd(),"comment";if(r=="0"&&t.eat("x"))return t.eatWhile(/[\da-f]/i),"number";if(r=="."&&t.eat(/\d/))return t.match(/\d*(?:e[+\-]?\d+)?/),"number";if(/\d/.test(r))return t.match(/\d*(?:\.\d+)?(?:e[+\-]\d+)?L?/),"number";if(r=="'"||r=='"')return e.tokenize=I(r),"string";if(r=="`")return t.match(/[^`]+`/),"string.special";if(r=="."&&t.match(/.(?:[.]|\d+)/))return"keyword";if(/[a-zA-Z\.]/.test(r)){t.eatWhile(/[\w\.]/);var a=t.current();return v.propertyIsEnumerable(a)?"atom":N.propertyIsEnumerable(a)?(A.propertyIsEnumerable(a)&&!t.match(/\s*if(\s+|$)/,!1)&&(c="block"),"keyword"):y.propertyIsEnumerable(a)?"builtin":"variable"}else return r=="%"?(t.skipTo("%")&&t.next(),"variableName.special"):r=="<"&&t.eat("-")||r=="<"&&t.match("<-")||r=="-"&&t.match(/>>?/)||r=="="&&e.ctx.argList?"operator":m.test(r)?(r=="$"||t.eatWhile(m),"operator"):/[\(\){}\[\];]/.test(r)?(c=r,r==";"?"punctuation":null):null}function I(t){return function(e,r){if(e.eat("\\")){var a=e.next();return a=="x"?e.match(/^[a-f0-9]{2}/i):(a=="u"||a=="U")&&e.eat("{")&&e.skipTo("}")?e.next():a=="u"?e.match(/^[a-f0-9]{4}/i):a=="U"?e.match(/^[a-f0-9]{8}/i):/[0-7]/.test(a)&&e.match(/^[0-7]{1,2}/),"string.special"}else{for(var n;(n=e.next())!=null;){if(n==t){r.tokenize=s;break}if(n=="\\"){e.backUp(1);break}}return"string"}}}var d=1,l=2,u=4;function i(t,e,r){t.ctx={type:e,indent:t.indent,flags:0,column:r.column(),prev:t.ctx}}function x(t,e){var r=t.ctx;t.ctx={type:r.type,indent:r.indent,flags:r.flags|e,column:r.column,prev:r.prev}}function f(t){t.indent=t.ctx.indent,t.ctx=t.ctx.prev}const E={name:"r",startState:function(t){return{tokenize:s,ctx:{type:"top",indent:-t,flags:l},indent:0,afterIdent:!1}},token:function(t,e){if(t.sol()&&(e.ctx.flags&3||(e.ctx.flags|=l),e.ctx.flags&u&&f(e),e.indent=t.indentation()),t.eatSpace())return null;var r=e.tokenize(t,e);return r!="comment"&&!(e.ctx.flags&l)&&x(e,d),(c==";"||c=="{"||c=="}")&&e.ctx.type=="block"&&f(e),c=="{"?i(e,"}",t):c=="("?(i(e,")",t),e.afterIdent&&(e.ctx.argList=!0)):c=="["?i(e,"]",t):c=="block"?i(e,"block",t):c==e.ctx.type?f(e):e.ctx.type=="block"&&r!="comment"&&x(e,u),e.afterIdent=r=="variable"||r=="keyword",r},indent:function(t,e,r){if(t.tokenize!=s)return 0;var a=e&&e.charAt(0),n=t.ctx,p=a==n.type;return n.flags&u&&(n=n.prev),n.type=="block"?n.indent+(a=="{"?0:r.unit):n.flags&d?n.column+(p?0:1):n.indent+(p?0:r.unit)},languageData:{wordChars:".",commentTokens:{line:"#"},autocomplete:k.concat(b,g)}};export{E as r};