Liferay.Loader.define("data-engine-js-components-web@1.0.79/js/utils/Tokenizer",["module","exports","require","./Token"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.Tokenizer=void 0;var i=n("./Token");const e=["*","/","+","-"];class s{static stringifyTokens(e){return e.reduce(((e,t)=>{let{value:n}=t;return t.type===i.Token.VARIABLE&&(n="[".concat(n,"]")),e+n}),"")}static tokenize(e){const t=[];e=e.replace(/\s/g,"");let n=[],s=[],o=[];const r=()=>{s.length&&(t.push(new i.Token(i.Token.LITERAL,s.join(""))),s=[])},h=()=>{t.push(new i.Token(i.Token.VARIABLE,o.join(""))),o=[]},T=e.split("");for(;T.length;){let e=T.shift();if(this.isDigit(e))s.push(e);else if(this.isDot(e))s.includes(".")||s.push(e);else if(this.isLeftBracket(e)){s.length&&(r(),t.push(new i.Token(i.Token.OPERATOR,"*")));do{if(e=T.shift(),this.isRightBracket(e)){h();break}o.push(e)}while(T.length)}else if(this.isLetter(e)){s.length&&(r(),t.push(new i.Token(i.Token.OPERATOR,"*")));do{n.push(e),e=T.shift()}while(this.isLetter(e));void 0!==e&&T.unshift(e),t.push(new i.Token(i.Token.FUNCTION,n.join(""))),n=[]}else if(this.isOperator(e))r(),t.push(new i.Token(i.Token.OPERATOR,e));else if(this.isLeftParenthesis(e))s.length&&(r(),t.push(new i.Token(i.Token.OPERATOR,"*"))),t.push(new i.Token(i.Token.LEFT_PARENTHESIS,e));else{if(!this.isRightParenthesis(e))throw new Error("Unsupported character ".concat(e));r(),t.push(new i.Token(i.Token.RIGHT_PARENTHESIS,e))}}return s.length&&r(),o.length&&h(),t}static isDot(e){return"."===e}static isDigit(e){return void 0!==e&&/[0-9]/.test(e)}static isLetter(e){return void 0!==e&&/[a-zA-Z]/.test(e)}static isLeftBracket(e){return"["===e}static isRightBracket(e){return"]"===e}static isLeftParenthesis(e){return"("===e}static isRightParenthesis(e){return")"===e}static isOperator(t){return e.includes(t)}static isValid(e){const t=s.tokenize(e),n=t.filter((({type:e})=>e===i.Token.LEFT_PARENTHESIS)),o=t.filter((({type:e})=>e===i.Token.RIGHT_PARENTHESIS)),r=t.map((({type:e},n)=>e===i.Token.OPERATOR?Boolean(t[n-1])&&Boolean(t[n+1]):e!==i.Token.FUNCTION||Boolean(t[n+2]))).every((e=>!0===e));return n.length===o.length&&r}}t.Tokenizer=s}}));
//# sourceMappingURL=Tokenizer.js.map