import{LeftParenthesis as t,RightParenthesis as e,Function as i,Ident as n,WhiteSpace as o,Comment as s,Colon as r,EOF as a}from"../../tokenizer/types.mjs";import"../../tokenizer/char-code-definitions.mjs";import"../../tokenizer/TokenStream.mjs";const h=new Set([r,e,a]),c="Condition",l={kind:String,children:[["Identifier","Feature","FeatureFunction","FeatureRange","SupportsDeclaration"]]};function u(t){return this.lookupTypeNonSC(1)===n&&h.has(this.lookupTypeNonSC(2))?this.Feature(t):this.FeatureRange(t)}const p={media:u,container:u,supports(){return this.SupportsDeclaration()}};function d(r="media"){const a=this.createList();t:for(;!this.eof;)switch(this.tokenType){case s:case o:this.next();continue;case n:a.push(this.Identifier());break;case t:{let i=this.parseWithFallback(()=>p[r].call(this,r),()=>null);i||(i=this.parseWithFallback(()=>{this.eat(t);const i=this.Condition(r);return this.eat(e),i},()=>this.GeneralEnclosed(r))),a.push(i);break}case i:{let t=this.parseWithFallback(()=>this.FeatureFunction(r),()=>null);t||(t=this.GeneralEnclosed(r)),a.push(t);break}default:break t}return a.isEmpty&&this.error("Condition is expected"),{type:"Condition",loc:this.getLocationFromList(a),kind:r,children:a}}function k(i){i.children.forEach(i=>{"Condition"===i.type?(this.token(t,"("),this.node(i),this.token(e,")")):this.node(i)})}export{k as generate,c as name,d as parse,l as structure};