"use strict";module.exports=tokenize;var delimRe=/[\s{}=;:[\],'"()<>]/g,stringDoubleRe=/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,stringSingleRe=/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,setCommentRe=/^ *[*/]+ */,setCommentAltRe=/^\s*\*?\/*/,setCommentSplitRe=/\n/g,whitespaceRe=/\s/,unescapeRe=/\\(.?)/g,unescapeMap={0:"\0",r:"\r",n:"\n",t:"	"};function unescape(e){return e.replace(unescapeRe,function(e,t){switch(t){case"\\":case"":return t;default:return unescapeMap[t]||""}})}function tokenize(e,t){e=e.toString();var n=0,r=e.length,i=1,l=0,u={},s=[],o=null;function a(e){return Error("illegal "+e+" (line "+i+")")}function f(t){return e.charAt(t)}function c(n,r,s){var o,a={type:e.charAt(n++),lineEmpty:!1,leading:s},f=n-(t?2:3);do if(--f<0||"\n"===(o=e.charAt(f))){a.lineEmpty=!0;break}while(" "===o||"	"===o);for(var c=e.substring(n,r).split(setCommentSplitRe),p=0;p<c.length;++p)c[p]=c[p].replace(t?setCommentAltRe:setCommentRe,"").trim();a.text=c.join("\n").trim(),u[i]=a,l=i}function p(t){var n=m(t),r=e.substring(t,n);return/^\s*\/\//.test(r)}function m(e){for(var t=e;t<r&&"\n"!==f(t);)t++;return t}function g(){if(s.length>0)return s.shift();if(o){var l="'"===o?stringSingleRe:stringDoubleRe;l.lastIndex=n-1;var u=l.exec(e);if(!u)throw a("string");return n=l.lastIndex,h(o),o=null,unescape(u[1])}var g,d,R,v,w,x=0===n;do{if(n===r)return null;for(g=!1;whitespaceRe.test(R=f(n));)if("\n"===R&&(x=!0,++i),++n===r)return null;if("/"===f(n)){if(++n===r)throw a("comment");if("/"===f(n))if(t){if(v=n,w=!1,p(n-1)){w=!0;do if((n=m(n))===r||(n++,!x))break;while(p(n))}else n=Math.min(r,m(n)+1);w&&(c(v,n,x),x=!0),i++,g=!0}else{for(w="/"===f(v=n+1);"\n"!==f(++n);)if(n===r)return null;++n,w&&(c(v,n-1,x),x=!0),++i,g=!0}else{if("*"!==(R=f(n)))return"/";v=n+1,w=t||"*"===f(v);do{if("\n"===R&&++i,++n===r)throw a("comment");d=R,R=f(n)}while("*"!==d||"/"!==R);++n,w&&(c(v,n-2,x),x=!0),g=!0}}}while(g);var b=n;if(delimRe.lastIndex=0,!delimRe.test(f(b++)))for(;b<r&&!delimRe.test(f(b));)++b;var k=e.substring(n,n=b);return('"'===k||"'"===k)&&(o=k),k}function h(e){s.push(e)}function d(){if(!s.length){var e=g();if(null===e)return null;h(e)}return s[0]}return Object.defineProperty({next:g,peek:d,push:h,skip:function(e,t){var n=d();if(n===e)return g(),!0;if(!t)throw a("token '"+n+"', '"+e+"' expected");return!1},cmnt:function(e){var n,r=null;return void 0===e?(n=u[i-1],delete u[i-1],n&&(t||"*"===n.type||n.lineEmpty)&&(r=n.leading?n.text:null)):(l<e&&d(),n=u[e],delete u[e],n&&!n.lineEmpty&&(t||"/"===n.type)&&(r=n.leading?null:n.text)),r}},"line",{get:function(){return i}})}tokenize.unescape=unescape;