var ERRORCLASS="error";function wordRegexp(e){return new RegExp("^(("+e.join(")|(")+"))\\b")}var operators=/^(?:->|=>|\+[+=]?|-[\-=]?|\*[\*=]?|\/[\/=]?|[=!]=|<[><]?=?|>>?=?|%=?|&=?|\|=?|\^=?|\~|!|\?|(or|and|\|\||&&|\?)=)/,delimiters=/^(?:[()\[\]{},:`=;]|\.\.?\.?)/,identifiers=/^[_A-Za-z$][_A-Za-z$0-9]*/,atProp=/^@[_A-Za-z$][_A-Za-z$0-9]*/,wordOperators=wordRegexp(["and","or","not","is","isnt","in","instanceof","typeof"]),indentKeywords=["for","while","loop","if","unless","else","switch","try","catch","finally","class"],commonKeywords=["break","by","continue","debugger","delete","do","in","of","new","return","then","this","@","throw","when","until","extends"],keywords=wordRegexp(indentKeywords.concat(commonKeywords));indentKeywords=wordRegexp(indentKeywords);var stringPrefixes=/^('{3}|\"{3}|['\"])/,regexPrefixes=/^(\/{3}|\/)/,commonConstants=["Infinity","NaN","undefined","null","true","false","on","off","yes","no"],constants=wordRegexp(commonConstants);function tokenBase(e,n){if(e.sol()){null===n.scope.align&&(n.scope.align=!1);var t=n.scope.offset;if(e.eatSpace()){var o=e.indentation();return o>t&&"coffee"==n.scope.type?"indent":o<t?"dedent":null}t>0&&dedent(e,n);}if(e.eatSpace())return null;var r=e.peek();if(e.match("####"))return e.skipToEnd(),"comment";if(e.match("###"))return n.tokenize=longComment,n.tokenize(e,n);if("#"===r)return e.skipToEnd(),"comment";if(e.match(/^-?[0-9\.]/,!1)){var i=!1;if(e.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)&&(i=!0),e.match(/^-?\d+\.\d*/)&&(i=!0),e.match(/^-?\.\d+/)&&(i=!0),i)return "."==e.peek()&&e.backUp(1),"number";var c=!1;if(e.match(/^-?0x[0-9a-f]+/i)&&(c=!0),e.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)&&(c=!0),e.match(/^-?0(?![\dx])/i)&&(c=!0),c)return "number"}if(e.match(stringPrefixes))return n.tokenize=tokenFactory(e.current(),!1,"string"),n.tokenize(e,n);if(e.match(regexPrefixes)){if("/"!=e.current()||e.match(/^.*\//,!1))return n.tokenize=tokenFactory(e.current(),!0,"string.special"),n.tokenize(e,n);e.backUp(1);}return e.match(operators)||e.match(wordOperators)?"operator":e.match(delimiters)?"punctuation":e.match(constants)?"atom":e.match(atProp)||n.prop&&e.match(identifiers)?"property":e.match(keywords)?"keyword":e.match(identifiers)?"variable":(e.next(),ERRORCLASS)}function tokenFactory(e,n,t){return function(o,r){for(;!o.eol();)if(o.eatWhile(/[^'"\/\\]/),o.eat("\\")){if(o.next(),n&&o.eol())return t}else {if(o.match(e))return r.tokenize=tokenBase,t;o.eat(/['"\/]/);}return n&&(r.tokenize=tokenBase),t}}function longComment(e,n){for(;!e.eol();){if(e.eatWhile(/[^#]/),e.match("###")){n.tokenize=tokenBase;break}e.eatWhile("#");}return "comment"}function indent(e,n,t="coffee"){for(var o=0,r=!1,i=null,c=n.scope;c;c=c.prev)if("coffee"===c.type||"}"==c.type){o=c.offset+e.indentUnit;break}"coffee"!==t?(r=null,i=e.column()+e.current().length):n.scope.align&&(n.scope.align=!1),n.scope={offset:o,type:t,prev:n.scope,align:r,alignOffset:i};}function dedent(e,n){if(n.scope.prev){if("coffee"===n.scope.type){for(var t=e.indentation(),o=!1,r=n.scope;r;r=r.prev)if(t===r.offset){o=!0;break}if(!o)return !0;for(;n.scope.prev&&n.scope.offset!==t;)n.scope=n.scope.prev;return !1}return n.scope=n.scope.prev,!1}}function tokenLexer(e,n){var t=n.tokenize(e,n),o=e.current();"return"===o&&(n.dedent=!0),(("->"===o||"=>"===o)&&e.eol()||"indent"===t)&&indent(e,n);var r="[({".indexOf(o);if(-1!==r&&indent(e,n,"])}".slice(r,r+1)),indentKeywords.exec(o)&&indent(e,n),"then"==o&&dedent(e,n),"dedent"===t&&dedent(e,n))return ERRORCLASS;if(-1!==(r="])}".indexOf(o))){for(;"coffee"==n.scope.type&&n.scope.prev;)n.scope=n.scope.prev;n.scope.type==o&&(n.scope=n.scope.prev);}return n.dedent&&e.eol()&&("coffee"==n.scope.type&&n.scope.prev&&(n.scope=n.scope.prev),n.dedent=!1),"indent"==t||"dedent"==t?null:t}const coffeeScript={startState:function(){return {tokenize:tokenBase,scope:{offset:0,type:"coffee",prev:null,align:!1},prop:!1,dedent:0}},token:function(e,n){var t=null===n.scope.align&&n.scope;t&&e.sol()&&(t.align=!1);var o=tokenLexer(e,n);return o&&"comment"!=o&&(t&&(t.align=!0),n.prop="punctuation"==o&&"."==e.current()),o},indent:function(e,n){if(e.tokenize!=tokenBase)return 0;var t=e.scope,o=n&&"])}".indexOf(n.charAt(0))>-1;if(o)for(;"coffee"==t.type&&t.prev;)t=t.prev;var r=o&&t.type===n.charAt(0);return t.align?t.alignOffset-(r?1:0):(r?t.prev:t).offset},languageData:{commentTokens:{line:"#"}}};

export { coffeeScript };
