function wordObj(t){for(var e={},n=0;n<t.length;++n)e[t[n]]=!0;return e}var curPunc,commonAtoms=["NULL","NA","Inf","NaN","NA_integer_","NA_real_","NA_complex_","NA_character_","TRUE","FALSE"],commonBuiltins=["list","quote","bquote","eval","return","call","parse","deparse"],commonKeywords=["if","else","repeat","while","function","for","in","next","break"],commonBlockKeywords=["if","else","repeat","while","function","for"],atoms=wordObj(commonAtoms),builtins=wordObj(commonBuiltins),keywords=wordObj(commonKeywords),blockkeywords=wordObj(commonBlockKeywords),opChars=/[+\-*\/^<>=!&|~$:]/;function tokenBase(t,e){curPunc=null;var n=t.next();if("#"==n)return t.skipToEnd(),"comment";if("0"==n&&t.eat("x"))return t.eatWhile(/[\da-f]/i),"number";if("."==n&&t.eat(/\d/))return t.match(/\d*(?:e[+\-]?\d+)?/),"number";if(/\d/.test(n))return t.match(/\d*(?:\.\d+)?(?:e[+\-]\d+)?L?/),"number";if("'"==n||'"'==n)return e.tokenize=tokenString(n),"string";if("`"==n)return t.match(/[^`]+`/),"string.special";if("."==n&&t.match(/.[.\d]+/))return "keyword";if(/[\w\.]/.test(n)&&"_"!=n){t.eatWhile(/[\w\.]/);var r=t.current();return atoms.propertyIsEnumerable(r)?"atom":keywords.propertyIsEnumerable(r)?(blockkeywords.propertyIsEnumerable(r)&&!t.match(/\s*if(\s+|$)/,!1)&&(curPunc="block"),"keyword"):builtins.propertyIsEnumerable(r)?"builtin":"variable"}return "%"==n?(t.skipTo("%")&&t.next(),"variableName.special"):"<"==n&&t.eat("-")||"<"==n&&t.match("<-")||"-"==n&&t.match(/>>?/)||"="==n&&e.ctx.argList?"operator":opChars.test(n)?("$"==n||t.eatWhile(opChars),"operator"):/[\(\){}\[\];]/.test(n)?(curPunc=n,";"==n?"punctuation":null):null}function tokenString(t){return function(e,n){if(e.eat("\\")){var r=e.next();return "x"==r?e.match(/^[a-f0-9]{2}/i):("u"==r||"U"==r)&&e.eat("{")&&e.skipTo("}")?e.next():"u"==r?e.match(/^[a-f0-9]{4}/i):"U"==r?e.match(/^[a-f0-9]{8}/i):/[0-7]/.test(r)&&e.match(/^[0-7]{1,2}/),"string.special"}for(var o;null!=(o=e.next());){if(o==t){n.tokenize=tokenBase;break}if("\\"==o){e.backUp(1);break}}return "string"}}var ALIGN_YES=1,ALIGN_NO=2,BRACELESS=4;function push(t,e,n){t.ctx={type:e,indent:t.indent,flags:0,column:n.column(),prev:t.ctx};}function setFlag(t,e){var n=t.ctx;t.ctx={type:n.type,indent:n.indent,flags:n.flags|e,column:n.column,prev:n.prev};}function pop(t){t.indent=t.ctx.indent,t.ctx=t.ctx.prev;}const r={startState:function(t){return {tokenize:tokenBase,ctx:{type:"top",indent:-t,flags:ALIGN_NO},indent:0,afterIdent:!1}},token:function(t,e){if(t.sol()&&(0==(3&e.ctx.flags)&&(e.ctx.flags|=ALIGN_NO),e.ctx.flags&BRACELESS&&pop(e),e.indent=t.indentation()),t.eatSpace())return null;var n=e.tokenize(t,e);return "comment"!=n&&0==(e.ctx.flags&ALIGN_NO)&&setFlag(e,ALIGN_YES),";"!=curPunc&&"{"!=curPunc&&"}"!=curPunc||"block"!=e.ctx.type||pop(e),"{"==curPunc?push(e,"}",t):"("==curPunc?(push(e,")",t),e.afterIdent&&(e.ctx.argList=!0)):"["==curPunc?push(e,"]",t):"block"==curPunc?push(e,"block",t):curPunc==e.ctx.type?pop(e):"block"==e.ctx.type&&"comment"!=n&&setFlag(e,BRACELESS),e.afterIdent="variable"==n||"keyword"==n,n},indent:function(t,e,n){if(t.tokenize!=tokenBase)return 0;var r=e&&e.charAt(0),o=t.ctx,c=r==o.type;return o.flags&BRACELESS&&(o=o.prev),"block"==o.type?o.indent+("{"==r?0:n.unit):o.flags&ALIGN_YES?o.column+(c?0:1):o.indent+(c?0:n.unit)},languageData:{wordChars:".",commentTokens:{line:"#"},autocomplete:commonAtoms.concat(commonBuiltins,commonKeywords)}};

export { r };
