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