const e=require("./Enum.js"),t=require("./Utility.js"),n=require("./Tokenizer.js");function r(e){return n.dealloc(i(``,null,null,null,[``],e=n.alloc(e),0,[0],e))}function i(e,r,c,l,u,d,f,p,m){for(var h=0,g=0,_=f,v=0,y=0,b=0,x=1,S=1,C=1,w=0,T=``,E=u,D=d,O=l,k=T;S;)switch(b=w,w=n.next()){case 40:if(b!=108&&t.charat(k,_-1)==58){t.indexof(k+=t.replace(n.delimit(w),`&`,`&\f`),`&\f`,t.abs(h?p[h-1]:0))!=-1&&(C=-1);break}case 34:case 39:case 91:k+=n.delimit(w);break;case 9:case 10:case 13:case 32:k+=n.whitespace(b);break;case 92:k+=n.escaping(n.caret()-1,7);continue;case 47:switch(n.peek()){case 42:case 47:t.append(o(n.commenter(n.next(),n.caret()),r,c,m),m),(n.token(b||1)==5||n.token(n.peek()||1)==5)&&t.strlen(k)&&t.substr(k,-1,void 0)!==` `&&(k+=` `);break;default:k+=`/`}break;case 123*x:p[h++]=t.strlen(k)*C;case 125*x:case 59:case 0:switch(w){case 0:case 125:S=0;case 59+g:C==-1&&(k=t.replace(k,/\f/g,``)),y>0&&(t.strlen(k)-_||x===0&&b===47)&&t.append(y>32?s(k+`;`,l,c,_-1,m):s(t.replace(k,` `,``)+`;`,l,c,_-2,m),m);break;case 59:k+=`;`;default:if(t.append(O=a(k,r,c,h,g,u,p,T,E=[],D=[],_,d),d),w===123)if(g===0)i(k,r,O,O,E,d,_,p,D);else{switch(v){case 99:if(t.charat(k,3)===110)break;case 108:if(t.charat(k,2)===97)break;default:g=0;case 100:case 109:case 115:}g?i(e,O,O,l&&t.append(a(e,O,O,0,0,u,p,T,u,E=[],_,D),D),u,D,_,p,l?E:D):i(k,O,O,O,[``],D,0,p,D)}}h=g=y=0,x=C=1,T=k=``,_=f;break;case 58:_=1+t.strlen(k),y=b;default:if(x<1){if(w==123)--x;else if(w==125&&x++==0&&n.prev()==125)continue}switch(k+=t.from(w),w*x){case 38:C=g>0?1:(k+=`\f`,-1);break;case 44:p[h++]=(t.strlen(k)-1)*C,C=1;break;case 64:n.peek()===45&&(k+=n.delimit(n.next())),v=n.peek(),g=_=t.strlen(T=k+=n.identifier(n.caret())),w++;break;case 45:b===45&&t.strlen(k)==2&&(x=0)}}return d}function a(r,i,a,o,s,c,l,u,d,f,p,m){for(var h=s-1,g=s===0?c:[``],_=t.sizeof(g),v=0,y=0,b=0;v<o;++v)for(var x=0,S=t.substr(r,h+1,h=t.abs(y=l[v])),C=r;x<_;++x)(C=t.trim(y>0?g[x]+` `+S:t.replace(S,/&\f/g,g[x])))&&(d[b++]=C);return n.node(r,i,a,s===0?e.RULESET:u,d,f,p,m)}function o(r,i,a,o){return n.node(r,i,a,e.COMMENT,t.from(n.char()),t.substr(r,2,-2),0,o)}function s(r,i,a,o,s){return n.node(r,i,a,e.DECLARATION,t.substr(r,0,o),t.substr(r,o+1,-1),o,s)}exports.comment=o,exports.compile=r,exports.declaration=s,exports.parse=i,exports.ruleset=a;