UNPKG

unnestcss

Version:
3 lines (2 loc) 2.56 kB
import{RIGHT_SQUARE_BRACKET as e,RIGHT_PARENTHESIS as t,LEFT_SQUARE_BRACKET as n,LEFT_PARENTHESIS as r,SINGLE_QUOTE as i,DOUBLE_QUOTE as a,COLON as o,RIGHT_CURLY_BRACKET as s,LEFT_CURLY_BRACKET as c,SEMICOLON as l,TILDE as u,AT as d,GREATER_THAN as f,SOLIDUS as p,COMMA as m,PLUS as h,EXCLAMATION as g,SPACE as _,CARRIAGE_RETURN as v,LINE_FEED as y,HORIZONTAL_TAB as b,NULL_CHARACTER as x,REVERSE_SOLIDUS as S,ASTERISK as C}from"./enum.js";import{charCodeAt as w,isHexChar as T}from"./utility.js";const E=S=>{switch(S){case x:case b:case y:case v:case _:return 5;case g:case h:case m:case p:case f:case d:case u:case l:case c:case s:return 4;case o:return 3;case a:case i:case r:case n:return 2;case t:case e:return 1}return 0};class D{constructor(e){this.line=1,this.column=1,this.length=0,this.position=0,this.characters=e,this.length=this.characters.length}prev(){return this.position>0?(this.position--,this.character=this.characters[this.position]):this.character=x,this.column--,this.character===y&&(this.column=1,this.line--),this.character}next(){return this.position<this.length?(this.character=this.characters[this.position],this.position++):this.character=x,this.column++,this.character===y&&(this.column=1,this.line++),this.character}peek(){return this.characters[this.position]||x}slice(e,t){return this.characters.slice(e,t)}delimit(i){return this.slice(this.position-1,this._delimiter(i===n?e:i===r?t:i)).trim()}tokenize(){return this._tokenizer([])}whitespace(e){for(this.character=this.peek();this.character!==x&&(this.character=this.peek(),w(this.character)<33);)this.next();return E(e)>2||E(this.character)>3?``:_}_tokenizer(e){for(;this.next()!==x;)switch(E(this.character)){case 0:e.push(this.identifier(this.position-1));break;case 2:e.push(this.delimit(this.character));break;default:e.push(this.character)}return e}escaping(e,t){for(t--;t&&this.next()!==x&&(t--,T(this.character)););return this.slice(e,this.position+ +(t<6&&this.peek()===_&&this.next()===_))}_delimiter(e){for(;this.next()!==x;)switch(this.character){case e:return this.position;case a:case i:e!==a&&e!==i&&this._delimiter(this.character);break;case r:e===t&&this._delimiter(e);break;case S:this.next();break}return this.position}commenter(e,t){for(;this.next()!==x&&!(e===p&&this.character===y||e===C&&this.character===C&&this.peek()===p););return`/*${this.slice(t,this.position-1)}*${e===p?e:this.next()}`}identifier(e){for(;!E(this.peek());)this.next();return this.slice(e,this.position)}}export{D as Tokenizer,E as token}; //# sourceMappingURL=tokenizer.js.map