import{SyntaxError as t}from"./SyntaxError.mjs";const s=new Uint8Array(128).map((t,s)=>/[a-zA-Z0-9\-]/.test(String.fromCharCode(s))?1:0);class r{constructor(t){this.str=t,this.pos=0}charCodeAt(t){return t<this.str.length?this.str.charCodeAt(t):0}charCode(){return this.charCodeAt(this.pos)}isNameCharCode(t=this.charCode()){return t<128&&1===s[t]}nextCharCode(){return this.charCodeAt(this.pos+1)}nextNonWsCode(t){return this.charCodeAt(this.findWsEnd(t))}skipWs(){this.pos=this.findWsEnd(this.pos)}findWsEnd(t){for(;t<this.str.length;t++){const s=this.str.charCodeAt(t);if(13!==s&&10!==s&&12!==s&&32!==s&&9!==s)break}return t}substringToPos(t){return this.str.substring(this.pos,this.pos=t)}eat(t){this.charCode()!==t&&this.error("Expect `"+String.fromCharCode(t)+"`"),this.pos++}peek(){return this.pos<this.str.length?this.str.charAt(this.pos++):""}error(s){throw new t(s,this.str,this.pos)}scanSpaces(){return this.substringToPos(this.findWsEnd(this.pos))}scanWord(){let t=this.pos;for(;t<this.str.length;t++){const r=this.str.charCodeAt(t);if(r>=128||0===s[r])break}return this.pos===t&&this.error("Expect a keyword"),this.substringToPos(t)}scanNumber(){let t=this.pos;for(;t<this.str.length;t++){const s=this.str.charCodeAt(t);if(s<48||s>57)break}return this.pos===t&&this.error("Expect a number"),this.substringToPos(t)}scanString(){const t=this.str.indexOf("'",this.pos+1);return-1===t&&(this.pos=this.str.length,this.error("Expect an apostrophe")),this.substringToPos(t+1)}}export{r as Scanner};