import{Delim as t,Ident as e,LeftSquareBracket as i,RightSquareBracket as s,String as n}from"../../tokenizer/types.mjs";import"../../tokenizer/char-code-definitions.mjs";import"../../tokenizer/TokenStream.mjs";function r(){this.eof&&this.error("Unexpected end of input");const t=this.tokenStart;let i=!1;return this.isDelim(42)?(i=!0,this.next()):this.isDelim(124)||this.eat(e),this.isDelim(124)?61!==this.charCodeAt(this.tokenStart+1)?(this.next(),this.eat(e)):i&&this.error("Identifier is expected",this.tokenEnd):i&&this.error("Vertical line is expected"),{type:"Identifier",loc:this.getLocation(t,this.tokenStart),name:this.substrToCursor(t)}}function o(){const t=this.tokenStart,e=this.charCodeAt(t);return 61!==e&&126!==e&&94!==e&&36!==e&&42!==e&&124!==e&&this.error("Attribute selector (=, ~=, ^=, $=, *=, |=) is expected"),this.next(),61!==e&&(this.isDelim(61)||this.error("Equal sign is expected"),this.next()),this.substrToCursor(t)}const h="AttributeSelector",l={name:"Identifier",matcher:[String,null],value:["String","Identifier",null],flags:[String,null]};function a(){const t=this.tokenStart;let h,l=null,a=null,c=null;return this.eat(i),this.skipSC(),h=r.call(this),this.skipSC(),this.tokenType!==s&&(this.tokenType!==e&&(l=o.call(this),this.skipSC(),a=this.tokenType===n?this.String():this.Identifier(),this.skipSC()),this.tokenType===e&&(c=this.consume(e),this.skipSC())),this.eat(s),{type:"AttributeSelector",loc:this.getLocation(t,this.tokenStart),name:h,matcher:l,value:a,flags:c}}function c(i){this.token(t,"["),this.node(i.name),null!==i.matcher&&(this.tokenize(i.matcher),this.node(i.value)),null!==i.flags&&this.token(e,i.flags),this.token(t,"]")}export{c as generate,h as name,a as parse,l as structure};