var h="error";function p(e){return new RegExp("^(("+e.join(")|(")+"))\\b")}var m=/^(?:->|=>|\+[+=]?|-[\-=]?|\*[\*=]?|\/[\/=]?|[=!]=|<[><]?=?|>>?=?|%=?|&=?|\|=?|\^=?|\~|!|\?|(or|and|\|\||&&|\?)=)/,v=/^(?:[()\[\]{},:`=;]|\.\.?\.?)/,l=/^[_A-Za-z$][_A-Za-z$0-9]*/,k=/^@[_A-Za-z$][_A-Za-z$0-9]*/,g=p(["and","or","not","is","isnt","in","instanceof","typeof"]),f=["for","while","loop","if","unless","else","switch","try","catch","finally","class"],y=["break","by","continue","debugger","delete","do","in","of","new","return","then","this","@","throw","when","until","extends"],z=p(f.concat(y));f=p(f);var b=/^('{3}|\"{3}|['\"])/,x=/^(\/{3}|\/)/,w=["Infinity","NaN","undefined","null","true","false","on","off","yes","no"],A=p(w);function a(e,t){if(e.sol()){t.scope.align===null&&(t.scope.align=!1);var r=t.scope.offset;if(e.eatSpace()){var o=e.indentation();return o>r&&t.scope.type=="coffee"?"indent":o0&&u(e,t)}if(e.eatSpace())return null;var n=e.peek();if(e.match("####"))return e.skipToEnd(),"comment";if(e.match("###"))return t.tokenize=O,t.tokenize(e,t);if(n==="#")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(b))return t.tokenize=d(e.current(),!1,"string"),t.tokenize(e,t);if(e.match(x)){if(e.current()!="/"||e.match(/^.*\//,!1))return t.tokenize=d(e.current(),!0,"string.special"),t.tokenize(e,t);e.backUp(1)}return e.match(m)||e.match(g)?"operator":e.match(v)?"punctuation":e.match(A)?"atom":e.match(k)||t.prop&&e.match(l)?"property":e.match(z)?"keyword":e.match(l)?"variable":(e.next(),h)}function d(e,t,r){return function(o,n){for(;!o.eol();)if(o.eatWhile(/[^'"\/\\]/),o.eat("\\")){if(o.next(),t&&o.eol())return r}else{if(o.match(e))return n.tokenize=a,r;o.eat(/['"\/]/)}return t&&(n.tokenize=a),r}}function O(e,t){for(;!e.eol();){if(e.eatWhile(/[^#]/),e.match("###")){t.tokenize=a;break}e.eatWhile("#")}return"comment"}function s(e,t,r="coffee"){for(var o=0,n=!1,i=null,c=t.scope;c;c=c.prev)if(c.type==="coffee"||c.type=="}"){o=c.offset+e.indentUnit;break}r!=="coffee"?(n=null,i=e.column()+e.current().length):t.scope.align&&(t.scope.align=!1),t.scope={offset:o,type:r,prev:t.scope,align:n,alignOffset:i}}function u(e,t){if(t.scope.prev)if(t.scope.type==="coffee"){for(var r=e.indentation(),o=!1,n=t.scope;n;n=n.prev)if(r===n.offset){o=!0;break}if(!o)return!0;for(;t.scope.prev&&t.scope.offset!==r;)t.scope=t.scope.prev;return!1}else return t.scope=t.scope.prev,!1}function S(e,t){var r=t.tokenize(e,t),o=e.current();o==="return"&&(t.dedent=!0),((o==="->"||o==="=>")&&e.eol()||r==="indent")&&s(e,t);var n="[({".indexOf(o);if(n!==-1&&s(e,t,"])}".slice(n,n+1)),f.exec(o)&&s(e,t),o=="then"&&u(e,t),r==="dedent"&&u(e,t))return h;if(n="])}".indexOf(o),n!==-1){for(;t.scope.type=="coffee"&&t.scope.prev;)t.scope=t.scope.prev;t.scope.type==o&&(t.scope=t.scope.prev)}return t.dedent&&e.eol()&&(t.scope.type=="coffee"&&t.scope.prev&&(t.scope=t.scope.prev),t.dedent=!1),r=="indent"||r=="dedent"?null:r}const Z={name:"coffeescript",startState:function(){return{tokenize:a,scope:{offset:0,type:"coffee",prev:null,align:!1},prop:!1,dedent:0}},token:function(e,t){var r=t.scope.align===null&&t.scope;r&&e.sol()&&(r.align=!1);var o=S(e,t);return o&&o!="comment"&&(r&&(r.align=!0),t.prop=o=="punctuation"&&e.current()=="."),o},indent:function(e,t){if(e.tokenize!=a)return 0;var r=e.scope,o=t&&"])}".indexOf(t.charAt(0))>-1;if(o)for(;r.type=="coffee"&&r.prev;)r=r.prev;var n=o&&r.type===t.charAt(0);return r.align?r.alignOffset-(n?1:0):(n?r.prev:r).offset},languageData:{commentTokens:{line:"#"}}};export{Z as coffeeScript};