UNPKG

extra-pg-english

Version:

Convert english query to informal SQL SELECT.

1,348 lines (1,333 loc) 397 kB
import require$$0 from 'natural'; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var _build = {}; var informalize = {}; var token = {}; var hasRequiredToken; function requireToken () { if (hasRequiredToken) return token; hasRequiredToken = 1; Object.defineProperty(token, "__esModule", { value: true }); token.stringifyTokens = token.parseTokens = token.createToken = token.TokenType = void 0; var TokenType; (function (TokenType) { TokenType[TokenType["NONE"] = 0] = "NONE"; TokenType[TokenType["TEXT"] = 16] = "TEXT"; TokenType[TokenType["NORMAL"] = 17] = "NORMAL"; TokenType[TokenType["QUOTED"] = 18] = "QUOTED"; TokenType[TokenType["NUMBER"] = 32] = "NUMBER"; TokenType[TokenType["CARDINAL"] = 33] = "CARDINAL"; TokenType[TokenType["ORDINAL"] = 34] = "ORDINAL"; TokenType[TokenType["UNIT"] = 48] = "UNIT"; TokenType[TokenType["MASS"] = 49] = "MASS"; TokenType[TokenType["ENTITY"] = 64] = "ENTITY"; TokenType[TokenType["TABLE"] = 65] = "TABLE"; TokenType[TokenType["COLUMN"] = 66] = "COLUMN"; TokenType[TokenType["ROW"] = 67] = "ROW"; TokenType[TokenType["BRACKET"] = 80] = "BRACKET"; TokenType[TokenType["OPEN"] = 81] = "OPEN"; TokenType[TokenType["CLOSE"] = 82] = "CLOSE"; TokenType[TokenType["SEPARATOR"] = 96] = "SEPARATOR"; TokenType[TokenType["OPERATOR"] = 112] = "OPERATOR"; TokenType[TokenType["UNARY"] = 113] = "UNARY"; TokenType[TokenType["BINARY"] = 114] = "BINARY"; TokenType[TokenType["TERNARY"] = 115] = "TERNARY"; TokenType[TokenType["FUNCTION"] = 128] = "FUNCTION"; TokenType[TokenType["KEYWORD"] = 144] = "KEYWORD"; TokenType[TokenType["EXPRESSION"] = 160] = "EXPRESSION"; TokenType[TokenType["VALUE"] = 161] = "VALUE"; TokenType[TokenType["BOOLEAN"] = 162] = "BOOLEAN"; })(TokenType || (token.TokenType = TokenType = {})); function createToken(type = 0, value = null, hint = null) { return { type, value, hint }; } token.createToken = createToken; function parseTokens(txt) { var quo = null, x = ''; var a = []; for (var c of txt) { if ((quo && quo != c) || /\w/.test(c)) { x += c; continue; } if (x) { a.push(createToken(quo ? TokenType.QUOTED : TokenType.TEXT, x)); x = ''; } if (/[\'\"\`]/.test(c)) quo = !quo ? c : null; else if (/\S/g.test(c)) a.push(createToken(TokenType.TEXT, c)); } if (x) a.push(createToken(quo ? TokenType.QUOTED : TokenType.TEXT, x)); return a; } token.parseTokens = parseTokens; function stringifyTokens(tokens) { var a = ''; for (var t of tokens) a += t.value + ' '; return a.trim(); } token.stringifyTokens = stringifyTokens; return token; } var number = {}; var hasRequiredNumber; function requireNumber () { if (hasRequiredNumber) return number; hasRequiredNumber = 1; Object.defineProperty(number, "__esModule", { value: true }); number.processNumberTokens = void 0; const token_1 = requireToken(); const DECIMAL = new Set(['dot', 'point', 'decimal']); const SPECIAL = new Map([ ['infinity', Infinity], ['infinite', Infinity], ['inf', Infinity], ['∞', Infinity], ['not-a-number', NaN], ['not-number', NaN], ['nan', NaN], ]); const CARDINAL = new Map([ ['oh', 0], ['nil', 0], ['zero', 0], ['nought', 0], ['naught', 0], ['one', 1], ['two', 2], ['three', 3], ['four', 4], ['five', 5], ['six', 6], ['seven', 7], ['eight', 8], ['nine', 9], ['ten', 10], ['eleven', 11], ['twelve', 12], ['thirteen', 13], ['fourteen', 14], ['fifteen', 15], ['sixteen', 16], ['seventeen', 17], ['eighteen', 18], ['nineteen', 19], ['twenty', 20], ['thirty', 30], ['forty', 40], ['fifty', 50], ['sixty', 60], ['seventy', 70], ['eighty', 80], ['ninety', 90], ['hundred', 1e+2], ['thousand', 1e+3], ['lakh', 1e+5], ['million', 1e+6], ['crore', 1e+7], ['billion', 1e+9], ['trillion', 1e+12], ['quadrillion', 1e+15], ['quintillion', 1e+18], ['sextillion', 1e+21], ['septillion', 1e+24], ['octillion', 1e+27], ['nonillion', 1e+30], ['decillion', 1e+33] ]); const ORDINAL = new Map([ ['zeroth', 0], ['first', 1], ['half', 2], ['second', 2], ['third', 3], ['quarter', 4], ['fourth', 4], ['fifth', 5], ['sixth', 6], ['seventh', 7], ['eighth', 8], ['ninth', 9], ['tenth', 10], ['eleventh', 11], ['twelfth', 12], ['thirteenth', 13], ['fourteenth', 14], ['fifteenth', 15], ['sixteenth', 16], ['seventeenth', 17], ['eighteenth', 18], ['nineteenth', 19], ['twentieth', 20], ['thirtieth', 30], ['fortieth', 40], ['fiftieth', 50], ['sixtieth', 60], ['seventieth', 70], ['eightieth', 80], ['ninetieth', 90], ['hundredth', 1e+2], ['thousandth', 1e+3], ['lakhth', 1e+5], ['millionth', 1e+6], ['croreth', 1e+7], ['billionth', 1e+9], ['trillionth', 1e+12], ['quadrillionth', 1e+15], ['quintillionth', 1e+18], ['sextillionth', 1e+21], ['septillionth', 1e+24], ['octillionth', 1e+27], ['nonillionth', 1e+30], ['decillionth', 1e+33] ]); function log10(x) { return x < 1 ? 0 : Math.floor(Math.log10(x)); } function numberStateFuse(s, i = s.length) { if (s[i - 2] <= s[i - 4]) s[i - 6] += s[i - 3]; else { s[i - 6] = s[i - 6] * (10 ** s[i - 2]) + s[i - 3]; s[i - 5] += s[i - 2]; } s[i - 4] = s[i - 2]; } function numberStateValue(s, pre = NaN) { if (s.length === 0) return Number.isNaN(pre) ? 0 : pre; for (var i = s.length; i > 3; i -= 3) numberStateFuse(s, i); return Number.isNaN(pre) ? s[i - 3] : pre + s[i - 3] * (10 ** -s[i - 2]); } function numberStateAdd(s, num) { var i = s.length; var len = log10(num) + 1; var spc = num < 20 ? 0 : len - 1; if (i === 0 || num < 100) return s.push(num, len, spc); for (; i > 3 && s[i - 2] + spc > s[i - 4]; i -= 3) numberStateFuse(s, i); s[i - 3] *= num; s[i - 2] += spc; s[i - 1] += spc; s.length = i; } function numberStateAddOrdinal(s, num) { var val = numberStateValue(s); if (val >= 20) return numberStateAdd(s, num); s.length = 0; s.push(val / num, 1, 0); } function processNumberTokens(tokens) { var s = [], pre = NaN, val = false; var brk = null; var a = []; for (var t of tokens) { var txt = (t.type & 0xF0) === token_1.TokenType.TEXT ? t.value.replace(/[\s,]/g, '').toLowerCase() : null; if (val && (!txt || brk)) { a.push((0, token_1.createToken)(token_1.TokenType.CARDINAL, numberStateValue(s, pre))); s.length = 0; pre = NaN, val = false; } if (brk && brk.type > 0) a.push(brk); brk = null; if (!txt) { a.push(t); continue; } if (SPECIAL.has(txt)) { brk = (0, token_1.createToken)(token_1.TokenType.CARDINAL, SPECIAL.get(txt)); continue; } if (ORDINAL.has(txt)) { numberStateAddOrdinal(s, ORDINAL.get(txt)); val = true; brk = (0, token_1.createToken)(); continue; } if (DECIMAL.has(txt)) { pre = numberStateValue(s); s.length = 0; continue; } if (CARDINAL.has(txt)) { numberStateAdd(s, CARDINAL.get(txt)); val = true; continue; } if (isNaN(txt)) { brk = t; continue; } brk = (0, token_1.createToken)(token_1.TokenType.CARDINAL, parseFloat(txt)); } if (val) a.push((0, token_1.createToken)(token_1.TokenType.CARDINAL, numberStateValue(s, pre))); if (brk && brk.type > 0) a.push(brk); return a; } number.processNumberTokens = processNumberTokens; return number; } var unit = {}; var hasRequiredUnit; function requireUnit () { if (hasRequiredUnit) return unit; hasRequiredUnit = 1; Object.defineProperty(unit, "__esModule", { value: true }); unit.processUnitTokens = void 0; const token_1 = requireToken(); const UNITS_MASS = new Map([ ['attogram', 1e-18], ['ag', 1e-18], ['femtogram', 1e-15], ['fg', 1e-15], ['picogram', 1e-12], ['pg', 1e-12], ['nanogram', 1e-9], ['ng', 1e-9], ['microgram', 1e-6], ['μg', 1e-6], ['ug', 1e-6], ['milligram', 1e-3], ['mg', 1e-3], ['centigram', 1e-2], ['cg', 1e-2], ['decigram', 1e-1], ['dg', 1e-1], ['gram', 1], ['gm', 1], ['g', 1], ['decagram', 1e+1], ['dekagram', 1e+1], ['dag', 1e+1], ['hectogram', 1e+2], ['hg', 1e+2], ['kilogram', 1e+3], ['kg', 1e+3], ['megagram', 1e+6], ['Mg', 1e+6], ['gigagram', 1e+9], ['Gg', 1e+9], ['teragram', 1e+12], ['Tg', 1e+12], ['petagram', 1e+15], ['Pg', 1e+15], ['exagram', 1e+18], ['Eg', 1e+18], ['quintal', 1e+5], ['metricton', 1e+6], ['tonne', 1e+6], ['ton', 1e+6], ['pound', 453.59237], ['lb', 453.59237], ]); function stemUnitText(txt) { return txt.search(/[sS]$/g) > 0 ? txt.substring(0, txt.length - 1) : txt; } function processUnitText(txt) { if (UNITS_MASS.has(txt = stemUnitText(txt))) return (0, token_1.createToken)(token_1.TokenType.MASS, UNITS_MASS.get(txt)); if (UNITS_MASS.has(txt = txt.toLowerCase())) return (0, token_1.createToken)(token_1.TokenType.MASS, UNITS_MASS.get(txt)); return null; } function processUnitTokens(tokens) { var a = []; for (var t of tokens) { var txt = t.type === token_1.TokenType.TEXT ? t.value : null; var unit = txt ? processUnitText(txt) : null; a.push(unit ? unit : t); } return a; } unit.processUnitTokens = processUnitTokens; return unit; } var reserved = {}; var hasRequiredReserved; function requireReserved () { if (hasRequiredReserved) return reserved; hasRequiredReserved = 1; Object.defineProperty(reserved, "__esModule", { value: true }); reserved.processReservedTokens = void 0; const natural_1 = require$$0; const token_1 = requireToken(); const LANCASTER = /^(equal|below|small|less|poor|low|above|great|high|rich|more|large|big|boolean).*/; const IGNORE = /^(an|the|i|he|him|she|her|they|their|as|at|are|if|in|is|it|of|on|to|want|well|that|than|then|thus|however|ok|okay)$/; const OPEN_BRACKET = new Map([ ['bracket curli start', '{'], ['begin bracket curli', '{'], ['bracket curli open', '{'], ['bracket round start', '('], ['begin bracket round', '('], ['bracket open round', '('], ['bracket squar start', '['], ['begin bracket squar', '['], ['bracket open squar', '['], ['bracket start', '('], ['begin bracket', '('], ['bracket open', '('], ['begin curli', '{'], ['curli start', '{'], ['curli open', '{'], ['begin brace', '{'], ['brace start', '{'], ['brace open', '{'], ['begin squar', '['], ['squar start', '['], ['open squar', '['], ['begin parenthes', '('], ['parenthes start', '('], ['open parenthes', '('], ['begin round', '('], ['round start', '('], ['open round', '('], ['begin', '('], ['start', '('], ['open', '('], ['(', '('], ['[', '['], ['{', '{'], ]); const CLOSE_BRACKET = new Map([ ['bracket stop', ')'], ['bracket end', ')'], ['bracket close', ')'], ['end', ')'], ['stop', ')'], ['close', ')'], [')', ')'], [']', ']'], ['}', '}'], ]); const SEPARATOR = new Map([ ['comma', ','], ['then', ','], [',', ','], ['semicolon', ';'], [';', ';'], ['colon', ':'], [':', ':'], ]); const UNARY_OPERATOR = new Map([ ['bool not', 'NOT'], ['not', 'NOT'], ['is null', 'IS NULL'], ['is not null', 'IS NOT NULL'], ['is true', 'IS TRUE'], ['is not true', 'IS NOT TRUE'], ['false is', 'IS FALSE'], ['false is not', 'IS NOT FALSE'], ['is unknown', 'IS UNKNOWN'], ['is not unknown', 'IS NOT UNKNOWN'], ['root squar', '|/'], ['root', '|/'], ['| /', '|/'], ['cube root', '|/'], ['| | /', '||/'], ['factori', '!'], ['! !', '!'], ['!', '!'], ['@', '@'], ['bitwis not', '~'], ['bit not', '~'], ['~', '~'], ['escape', 'ESCAPE'], ['negat', '!!'], ['empti not', 'EXISTS'], ['not noth', 'EXISTS'], ['exist', 'EXISTS'], ]); const BINARY_OPERATOR = new Map([ ['and bool', 'AND'], ['and', 'AND'], ['bool or', 'OR'], ['or', 'OR'], ['abov not same', '<'], ['gre not same', '<'], ['high not same', '<'], ['not rich same', '<'], ['good not same', '<'], ['better not same', '<'], ['larg not same', '<'], ['mor not same', '<'], ['big not same', '<'], ['abov not or same', '<'], ['gre not or same', '<'], ['high not or same', '<'], ['not or rich same', '<'], ['good not or same', '<'], ['better not or same', '<'], ['larg not or same', '<'], ['mor not or same', '<'], ['big not or same', '<'], ['big eq not', '<'], ['eq mor not', '<'], ['eq larg not', '<'], ['eq high not', '<'], ['eq not rich', '<'], ['eq good not', '<'], ['better eq not', '<'], ['abov eq not', '<'], ['eq gre not', '<'], ['big eq not or', '<'], ['eq mor not or', '<'], ['eq larg not or', '<'], ['eq not or rich', '<'], ['eq good not or', '<'], ['better eq not or', '<'], ['eq high not or', '<'], ['abov eq not or', '<'], ['eq gre not or', '<'], ['below', '<'], ['poor', '<'], ['bad', '<'], ['wors', '<'], ['smal', '<'], ['less', '<'], ['low', '<'], ['<', '<'], ['not same smal', '>'], ['low not same', '>'], ['below not same', '>'], ['less not same', '>'], ['not poor same', '>'], ['bad not same', '>'], ['not same wors', '>'], ['not or same smal', '>'], ['low not or same', '>'], ['below not or same', '>'], ['less not or same', '>'], ['not or poor same', '>'], ['bad not or same', '>'], ['not or same wors', '>'], ['eq not smal', '>'], ['eq low not', '>'], ['below eq not', '>'], ['eq less not', '>'], ['eq not poor', '>'], ['bad eq not', '>'], ['eq not wors', '>'], ['eq not or smal', '>'], ['eq low not or', '>'], ['below eq not or', '>'], ['eq less not or', '>'], ['eq not or poor', '>'], ['bad eq not or', '>'], ['eq not or wors', '>'], ['abov', '>'], ['gre', '>'], ['high', '>'], ['rich', '>'], ['good', '>'], ['better', '>'], ['larg', '>'], ['mor', '>'], ['big', '>'], ['>', '>'], ['same smal', '<='], ['low same', '<='], ['below same', '<='], ['less same', '<='], ['poor same', '<='], ['bad same', '<='], ['same wors', '<='], ['or same smal', '<='], ['low or same', '<='], ['below or same', '<='], ['less or same', '<='], ['or poor same', '<='], ['bad or same', '<='], ['or same wors', '<='], ['eq smal', '<='], ['eq low', '<='], ['below eq', '<='], ['eq less', '<='], ['eq poor', '<='], ['bad eq', '<='], ['eq wors', '<='], ['eq or smal', '<='], ['eq low or', '<='], ['below eq or', '<='], ['eq less or', '<='], ['eq or poor', '<='], ['bad eq or', '<='], ['eq or wors', '<='], ['abov not', '<='], ['gre not', '<='], ['high not', '<='], ['not rich', '<='], ['good not', '<='], ['better not', '<='], ['larg not', '<='], ['mor not', '<='], ['big not', '<='], ['< =', '<='], ['abov same', '>='], ['gre same', '>='], ['high same', '>='], ['rich same', '>='], ['good same', '>='], ['better same', '>='], ['larg same', '>='], ['mor same', '>='], ['big same', '>='], ['abov or same', '>='], ['gre or same', '>='], ['high or same', '>='], ['or rich same', '>='], ['good or same', '>='], ['better or same', '>='], ['larg or same', '>='], ['mor or same', '>='], ['big or same', '>='], ['big eq', '>='], ['eq mor', '>='], ['eq larg', '>='], ['eq high', '>='], ['eq rich', '>='], ['eq good', '>='], ['better eq', '>='], ['abov eq', '>='], ['eq gre', '>='], ['big eq or', '>='], ['eq mor or', '>='], ['eq larg or', '>='], ['eq high or', '>='], ['eq or rich', '>='], ['eq good or', '>='], ['better eq or', '>='], ['abov eq or', '>='], ['eq gre or', '>='], ['below not', '>='], ['not smal', '>='], ['less not', '>='], ['not poor', '>='], ['bad not', '>='], ['not wors', '>='], ['low not', '>='], ['> =', '>='], ['not same', '!='], ['eq not', '!='], ['differ', '!='], ['inequ', '!='], ['< >', '!='], ['! =', '!='], ['indiffer', '='], ['equival', '='], ['ident', '='], ['same', '='], ['eq', '='], ['is', '='], ['= =', '='], ['=', '='], ['diff from', 'IS DISTINCT FROM'], ['distinct from', 'IS DISTINCT FROM'], ['diff from is', 'IS DISTINCT FROM'], ['distinct from is', 'IS DISTINCT FROM'], ['diff from not', 'IS NOT DISTINCT FROM'], ['distinct from not', 'IS NOT DISTINCT FROM'], ['diff from is not', 'IS NOT DISTINCT FROM'], ['distinct from is not', 'IS NOT DISTINCT FROM'], ['addit', '+'], ['plu', '+'], ['sum', '+'], ['add', '+'], ['+', '+'], ['subtract', '-'], ['differ', '-'], ['minu', '-'], ['-', '-'], ['multipli', '*'], ['product', '*'], ['into', '*'], ['*', '*'], ['divis', '/'], ['divid', '/'], ['by', '/'], ['/', '/'], ['remaind', '%'], ['modulu', '%'], ['modulo', '%'], ['mod', '%'], ['%', '%'], ['exponenti', '^'], ['expon', '^'], ['power', '^'], ['pow', '^'], ['^', '^'], ['and bitwis', '&'], ['and bit', '&'], ['&', '&'], ['bitwis or', '|'], ['bit or', '|'], ['|', '|'], ['bitwis xor', '#'], ['bit xor', '#'], ['#', '#'], ['bitwis left shift', '<<'], ['bit left shift', '<<'], ['left shift', '<<'], ['< <', '<<'], ['bitwis right shift', '>>'], ['bit right shift', '>>'], ['right shift', '>>'], ['> >', '>>'], ['case express match regular sensit', '~'], ['express match regular sensit', '~'], ['express match regular', '~'], ['case express insensit match regular', '~*'], ['express insensit match regular', '~*'], ['case express match not regular sensit', '!~'], ['express match not regular sensit', '!~'], ['express match not regular', '!~'], ['case express insensit match not regular', '!~*'], ['express insensit match not regular', '!~*'], ['like', 'LIKE'], ['like not', 'NOT LIKE'], ['similar to', 'SIMILAR TO'], ['not similar to', 'NOT SIMILAR TO'], ['match', '@@'], ['@ @', '@@'], ['concaten', '||'], ['concat', '||'], ['| |', '||'], ['contains element', '@>'], ['contains range', '@>'], ['contains', '@>'], ['of superset', '<@'], ['@ >', '@>'], ['contained element', '<@'], ['contained range', '<@'], ['contained', '<@'], ['constituent of', '<@'], ['component of', '<@'], ['element of', '<@'], ['of portion', '<@'], ['member of', '<@'], ['of subset', '<@'], ['of piece', '<@'], ['of part', '<@'], ['< @', '<@'], ['common point', '&&'], ['intersects', '&&'], ['overlaps', '&&'], ['& &', '&&'], ['absolut left', '<<'], ['complet left', '<<'], ['exactli left', '<<'], ['exact left', '<<'], ['left rigidli', '<<'], ['left rigid', '<<'], ['left strictli', '<<'], ['left strict', '<<'], ['left pure', '<<'], ['absolut right', '>>'], ['complet right', '>>'], ['exactli right', '>>'], ['exact right', '>>'], ['right rigidli', '>>'], ['right rigid', '>>'], ['right strictli', '>>'], ['right strict', '>>'], ['pure right', '>>'], ['lengthen not right', '&<'], ['not right stretch', '&<'], ['not prolong right', '&<'], ['continu not right', '&<'], ['not right unfurl', '&<'], ['not right spread', '&<'], ['expand not right', '&<'], ['extend not right', '&<'], ['carri not right', '&<'], ['left lengthen not', '&>'], ['left not stretch', '&>'], ['left not prolong', '&>'], ['continu left not', '&>'], ['left not unfurl', '&>'], ['left not spread', '&>'], ['expand left not', '&>'], ['extend left not', '&>'], ['carri left not', '&>'], ['neighbour', '-|-'], ['alongsid', '-|-'], ['contigu', '-|-'], ['adjoin', '-|-'], ['touch', '-|-'], ['besid', '-|-'], ['adjac', '-|-'], ['- | -', '-|-'], ['union', '+'], ['∪', '+'], ['u', '+'], ['intersection', '*'], ['∩', '*'], ['complement rel', '-'], ['comp rel', '-'], ['differ', '-'], ['in', 'IN'], ['on', 'IN'], ['of', 'IN'], ['in not', 'NOT IN'], ['not on', 'NOT IN'], ['not of', 'NOT IN'], ['partial', 'ANY'], ['part', 'ANY'], ['some', 'ANY'], ['few', 'ANY'], ['ani', 'ANY'], ['everi on singl', 'ALL'], ['everi singl', 'ALL'], ['everi on', 'ALL'], ['everi', 'ALL'], ['each everi', 'ALL'], ['all', 'ALL'] ]); const TERNARY_OPERATOR = new Map([ ['between not', 'NOT BETWEEN SYMMETRIC'], ['not within', 'NOT BETWEEN SYMMETRIC'], ['between', 'BETWEEN SYMMETRIC'], ['within', 'BETWEEN SYMMETRIC'], ]); const FUNCTION = new Map([ ['absolut valu', 'abs'], ['absolut', 'abs'], ['abs', 'abs'], ['cube root', 'cbrt'], ['cbrt', 'cbrt'], ['integ round up', 'ceil'], ['round up', 'ceil'], ['ceiling', 'ceil'], ['ceil', 'ceil'], ['degrees', 'degrees'], ['deg', 'degrees'], ['integ quotient', 'div'], ['divis integ', 'div'], ['div', 'div'], ['exponenti', 'exp'], ['expon', 'exp'], ['exp', 'exp'], ['integ round down', 'floor'], ['round down', 'floor'], ['floor', 'floor'], ['base e logarithm', 'ln'], ['base e log', 'ln'], ['logarithm natur', 'ln'], ['log natur', 'ln'], ['e logarithm', 'ln'], ['e log', 'ln'], ['loge', 'ln'], ['ln', 'ln'], ['base logarithm', 'log'], ['base log', 'log'], ['logarithm', 'log'], ['log10', 'log'], ['log', 'log'], ['divis remaind', 'mod'], ['remaind', 'mod'], ['modulu', 'mod'], ['modulo', 'mod'], ['mod', 'mod'], ['constant pi', 'pi'], ['pi', 'pi'], ['π', 'pi'], ['power rais', 'power'], ['power', 'power'], ['pow', 'power'], ['radians', 'radians'], ['rad', 'radians'], ['integ round', 'round'], ['round', 'round'], ['integ nearest round', 'round'], ['integ round', 'round'], ['round', 'round'], ['sign', 'sign'], ['sgn', 'sign'], ['root squar', 'sqrt'], ['root', 'sqrt'], ['sqrt', 'sqrt'], ['toward truncat zero', 'trunc'], ['truncat zero', 'trunc'], ['truncat', 'trunc'], ['trunc', 'trunc'], ['number random', 'random'], ['num random', 'random'], ['number rand', 'random'], ['num rand', 'random'], ['random', 'random'], ['rand', 'random'], ['random seed set', 'setseed'], ['rand seed set', 'setseed'], ['seed set', 'setseed'], ['random seed', 'setseed'], ['rand seed', 'setseed'], ['setseed', 'setseed'], ['cosin invers', 'acos'], ['co invers', 'acos'], ['cosin inv', 'acos'], ['co inv', 'acos'], ['aco', 'acos'], ['invers sine', 'asin'], ['invers sin', 'asin'], ['inv sine', 'asin'], ['inv sin', 'asin'], ['asin', 'asin'], ['invers tangent', 'atan'], ['invers tan', 'atan'], ['inv tangent', 'atan'], ['inv tan', 'atan'], ['atan', 'atan'], ['invers tangent y / x', 'atan2'], ['invers tangent yx', 'atan2'], ['invers tangent 2', 'atan2'], ['invers tan y / x', 'atan2'], ['invers tan yx', 'atan2'], ['invers tan 2', 'atan2'], ['inv tangent y / x', 'atan2'], ['inv tangent yx', 'atan2'], ['inv tangent 2', 'atan2'], ['inv tan y / x', 'atan2'], ['inv tan yx', 'atan2'], ['inv tan 2', 'atan2'], ['atan2', 'atan2'], ['co', 'cos'], ['cosin', 'cos'], ['co', 'cos'], ['cotang', 'cot'], ['cot', 'cot'], ['sine', 'sin'], ['sin', 'sin'], ['tangent', 'tan'], ['tan', 'tan'], ['bit number string', 'bit_length'], ['bit length string', 'bit_length'], ['bit number', 'bit_length'], ['bit length', 'bit_length'], ['bit num', 'bit_length'], ['bit len', 'bit_length'], ['bit_length', 'bit_length'], ['bit_len', 'bit_length'], ['charact number string', 'char_length'], ['charact length string', 'char_length'], ['charact number', 'char_length'], ['charact length', 'char_length'], ['char number', 'char_length'], ['char length', 'char_length'], ['charact num', 'char_length'], ['charact len', 'char_length'], ['char num', 'char_length'], ['char len', 'char_length'], ['character_length', 'char_length'], ['char_length', 'char_length'], ['character_len', 'char_length'], ['char_len', 'char_length'], ['case convert low string', 'lower'], ['case convert low', 'lower'], ['case low string', 'lower'], ['case low', 'lower'], ['tolowercase', 'lower'], ['lowercase', 'lower'], ['tolcase', 'lower'], ['lcase', 'lower'], ['tolower', 'lower'], ['low', 'lower'], ['locat string', 'strpos'], ['locat', 'strpos'], ['index string', 'strpos'], ['index', 'strpos'], ['posit string', 'strpos'], ['posit', 'strpos'], ['indexof', 'strpos'], ['strpos', 'strpos'], ['extract substr', 'substr'], ['substr', 'substr'], ['and lead space trail trim', 'btrim'], ['and lead trail trim', 'btrim'], ['lead trail trim', 'btrim'], ['and left right space trim', 'btrim'], ['and left right trim', 'btrim'], ['left right trim', 'btrim'], ['both end trim', 'btrim'], ['both trim', 'btrim'], ['trim', 'btrim'], ['btrim', 'btrim'], ['lead space trim', 'ltrim'], ['lead trim', 'ltrim'], ['left space trim', 'ltrim'], ['left trim', 'ltrim'], ['ltrim', 'ltrim'], ['space trail trim', 'rtrim'], ['trail trim', 'rtrim'], ['right space trim', 'rtrim'], ['right trim', 'rtrim'], ['rtrim', 'rtrim'], ['case convert string upper', 'upper'], ['case convert upper', 'upper'], ['case string upper', 'upper'], ['case upper', 'upper'], ['touppercase', 'upper'], ['uppercase', 'upper'], ['toucase', 'upper'], ['ucase', 'upper'], ['toupper', 'upper'], ['upper', 'upper'], ['asci cod', 'ascii'], ['asci', 'ascii'], ['asc', 'ascii'], ['charact', 'chr'], ['char', 'chr'], ['chr', 'chr'], ['capit charact init', 'initcap'], ['capit char init', 'initcap'], ['cap char init', 'initcap'], ['cap init', 'initcap'], ['case titl', 'initcap'], ['totitlecase', 'initcap'], ['titlecase', 'initcap'], ['totcase', 'initcap'], ['tcase', 'initcap'], ['initcap', 'initcap'], ['left subst', 'left'], ['left', 'left'], ['leng', 'length'], ['len', 'length'], ['siz', 'length'], ['left pad spac', 'lpad'], ['left pad', 'lpad'], ['lpad', 'lpad'], ['hash md5', 'md5'], ['md5', 'md5'], ['express regul replac', 'regexp_replace'], ['regexp replac', 'regexp_replace'], ['regexp_replace', 'regexp_replace'], ['rep string', 'repeat'], ['rep', 'repeat'], ['replac subst', 'replace'], ['replac string', 'replace'], ['replac', 'replace'], ['revers string', 'reverse'], ['revers', 'reverse'], ['right subst', 'right'], ['right', 'right'], ['pad right spac', 'rpad'], ['pad right', 'rpad'], ['rpad', 'rpad'], ['part split string', 'split_part'], ['part split', 'split_part'], ['split string', 'split_part'], ['split', 'split_part'], ['split_part', 'split_part'], ['string to', 'to_char'], ['charact to', 'to_char'], ['tostring', 'to_char'], ['to_char', 'to_char'], ['dat to', 'to_date'], ['to_date', 'to_date'], ['number to', 'to_number'], ['integ to', 'to_number'], ['num to', 'to_number'], ['int to', 'to_number'], ['to_number', 'to_number'], ['timestamp to', 'to_timestamp'], ['time to', 'to_timestamp'], ['to_timestamp', 'to_timestamp'], ['coalesc', 'coalesce'], ['if null', 'nullif'], ['nullif', 'nullif'], ['mean', 'avg'], ['averag', 'avg'], ['avg', 'avg'], ['and bitwis', 'bit_and'], ['and bit', 'bit_and'], ['everi', 'bit_and'], ['bit_and', 'bit_and'], ['bitwis or', 'bit_or'], ['bit or', 'bit_or'], ['bit_or', 'bit_or'], ['and bool', 'bool_and'], ['and', 'bool_and'], ['bool_and', 'bool_and'], ['bool_and', 'bool_and'], ['bool or', 'bool_or'], ['or', 'bool_or'], ['bool_or', 'bool_or'], ['count row', 'count'], ['count', 'count'], ['maximum', 'max'], ['max', 'max'], ['minimum', 'min'], ['min', 'min'], ['sum', 'sum'], ]); const KEYWORD = new Map([ ['displai', 'SELECT'], ['disclos', 'SELECT'], ['discov', 'SELECT'], ['reveal', 'SELECT'], ['inform', 'SELECT'], ['search', 'SELECT'], ['found', 'SELECT'], ['find', 'SELECT'], ['shown', 'SELECT'], ['show', 'SELECT'], ['list', 'SELECT'], ['given', 'SELECT'], ['give', 'SELECT'], ['told', 'SELECT'], ['tell', 'SELECT'], ['select', 'SELECT'], ['from', 'FROM'], ['as', 'AS'], ['which', 'WHERE'], ['with', 'WHERE'], ['have', 'WHERE'], ['has', 'WHERE'], ['when', 'WHERE'], ['where', 'WHERE'], ['most', 'ORDER BY'], ['least', 'ORDER BY'], ['arrang', 'ORDER BY'], ['sort', 'ORDER BY'], ['order', 'ORDER BY'], ['by group', 'GROUP BY'], ['by grouped', 'GROUP BY'], ['by classify', 'GROUP BY'], ['by classified', 'GROUP BY'], ['having', 'HAVING'], ['on uniqu', 'DISTINCT'], ['distinct on', 'DISTINCT'], ['uniqu', 'DISTINCT'], ['distinct', 'DISTINCT'], ['ascend', 'ASC'], ['worst', 'ASC'], ['least', 'ASC'], ['lowest', 'ASC'], ['poorest', 'ASC'], ['descend', 'DESC'], ['best', 'DESC'], ['most', 'DESC'], ['highest', 'DESC'], ['richest', 'DESC'], ['limit', 'LIMIT'], ['top', 'LIMIT'], ['bottom', 'DESC LIMIT'], ['false', 'FALSE'], ['true', 'TRUE'], ['null', 'NULL'], ['per', 'PER'], ['type', 'TYPE'], ]); const RESERVED_STEPS = [ (txts) => txts.slice(), (txts) => txts.map(stemReservedText).sort(), (txts) => txts.filter((v) => !IGNORE.test(v)).sort(), (txts) => txts.filter((v) => !IGNORE.test(v)).map(stemReservedText).sort() ]; function stemReservedText(txt) { if (!LANCASTER.test(txt)) return natural_1.PorterStemmer.stem(txt); return natural_1.LancasterStemmer.stem(txt); } function findLastTokenOfType(tokens, i, type) { var a = -1; for (var I = tokens.length; i < I; a = i++) if (tokens[i].type !== type) break; return a; } function processReservedText(txt) { if (OPEN_BRACKET.has(txt)) return (0, token_1.createToken)(token_1.TokenType.OPEN, OPEN_BRACKET.get(txt)); if (CLOSE_BRACKET.has(txt)) return (0, token_1.createToken)(token_1.TokenType.CLOSE, CLOSE_BRACKET.get(txt)); if (SEPARATOR.has(txt)) return (0, token_1.createToken)(token_1.TokenType.SEPARATOR, SEPARATOR.get(txt)); if (TERNARY_OPERATOR.has(txt)) return (0, token_1.createToken)(token_1.TokenType.TERNARY, TERNARY_OPERATOR.get(txt)); if (BINARY_OPERATOR.has(txt)) return (0, token_1.createToken)(token_1.TokenType.BINARY, BINARY_OPERATOR.get(txt)); if (UNARY_OPERATOR.has(txt)) return (0, token_1.createToken)(token_1.TokenType.UNARY, UNARY_OPERATOR.get(txt)); if (FUNCTION.has(txt)) return (0, token_1.createToken)(token_1.TokenType.FUNCTION, FUNCTION.get(txt)); if (KEYWORD.has(txt)) return (0, token_1.createToken)(token_1.TokenType.KEYWORD, KEYWORD.get(txt)); return null; } function processReservedTexts(txts) { var a = null; for (var i = 0, I = RESERVED_STEPS.length; i < I && a == null; i++) a = processReservedText(RESERVED_STEPS[i](txts).join(' ')); return a; } function processReservedTokens(tokens) { var a = []; for (var i = 0, I = tokens.length; i < I; i++) { var J = findLastTokenOfType(tokens, i, token_1.TokenType.TEXT); if (J < 0) { a.push(tokens[i]); continue; } var words = tokens.slice(i, J + 1).map((v) => v.value.toLowerCase()); for (var j = J; j >= i; j--) { var rsv = processReservedTexts(words); if (rsv != null) { a.push(rsv); i = j; break; } words.pop(); } if (j < i) a.push(tokens[i]); } return a; } reserved.processReservedTokens = processReservedTokens; return reserved; } var entity = {}; var hasRequiredEntity; function requireEntity () { if (hasRequiredEntity) return entity; hasRequiredEntity = 1; Object.defineProperty(entity, "__esModule", { value: true }); entity.processEntityTokens = void 0; const token_1 = requireToken(); const EntityType = new Map([ ['t', token_1.TokenType.TABLE], ['c', token_1.TokenType.COLUMN], ['r', token_1.TokenType.ROW], ]); async function entityBlockScan(txts, fn, ths = null) { var a = []; for (var i = 0, I = txts.length; i < I;) { var ans = await fn.call(ths, txts.slice(i, I)); if (ans == null) { a.push((0, token_1.createToken)(token_1.TokenType.TEXT, txts[i++])); continue; } var typ = EntityType.get(ans.type[0].toLowerCase()) || 0; a.push((0, token_1.createToken)(typ, ans.value, ans.hint || null)); i += ans.length; } return a; } async function processEntityTokens(tokens, fn, ths = null) { var blk = [], txts = []; var a = []; for (var t of tokens) { if ((t.type & 0xF0) === token_1.TokenType.TEXT) { txts.push(t.value); continue; } if (txts.length > 0) { blk.push(entityBlockScan(txts, fn, ths)); txts = []; } blk.push(Promise.resolve([t])); } if (txts.length > 0) blk.push(entityBlockScan(txts, fn, ths)); var ans = await Promise.all(blk); for (var arr of ans) a.push.apply(a, arr); return a; } entity.processEntityTokens = processEntityTokens; return entity; } var hasRequiredInformalize; function requireInformalize () { if (hasRequiredInformalize) return informalize; hasRequiredInformalize = 1; Object.defineProperty(informalize, "__esModule", { value: true }); informalize.convertToInformalSQL = void 0; const token_1 = requireToken(); const number_1 = requireNumber(); const unit_1 = requireUnit(); const reserved_1 = requireReserved(); const entity_1 = requireEntity(); const NULLORDER = [ { t: [token_1.TokenType.KEYWORD, token_1.TokenType.KEYWORD, token_1.TokenType.ORDINAL], v: [/SELECT/, /NULL/, /1/], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.KEYWORD, 'NULLS FIRST') }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.KEYWORD, token_1.TokenType.TEXT], v: [/SELECT/, /NULL/, /last|first/i], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.KEYWORD, `NULLS ${t[i + 2].value.toUpperCase()}`) }, ]; const NUMBER = [ { t: [token_1.TokenType.CARDINAL, token_1.TokenType.ORDINAL], v: [null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.CARDINAL, t[i].value / t[i + 1].value) }, { t: [token_1.TokenType.CARDINAL, token_1.TokenType.UNIT], v: [null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.CARDINAL, t[i].value * t[i + 1].value) }, ]; const LIMIT = [ { t: [token_1.TokenType.KEYWORD, token_1.TokenType.NUMBER], v: [/ASC|LIMIT/, null], f: (s, t, i) => { s.limit = t[i + 1].value; return null; } }, { t: [token_1.TokenType.NUMBER, token_1.TokenType.KEYWORD], v: [null, /ASC|LIMIT/], f: (s, t, i) => { s.limit = t[i].value; return null; } }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.NUMBER], v: [/(DESC )?LIMIT/, null], f: (s, t, i) => { s.limit = t[i + 1].value; s.reverse = !s.reverse; return null; } }, { t: [token_1.TokenType.NUMBER, token_1.TokenType.KEYWORD], v: [null, /(DESC )?LIMIT/], f: (s, t, i) => { s.limit = t[i].value; s.reverse = !s.reverse; return null; } }, ]; const VALUE = [ { t: [token_1.TokenType.OPERATOR, token_1.TokenType.KEYWORD, token_1.TokenType.COLUMN], v: [/ALL/, /TYPE/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.COLUMN, `all: ${t[i + 2].value}`) }, { t: [token_1.TokenType.OPERATOR, token_1.TokenType.KEYWORD, token_1.TokenType.COLUMN], v: [/\+/, /TYPE/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.COLUMN, `sum: ${t[i + 2].value}`) }, { t: [token_1.TokenType.FUNCTION, token_1.TokenType.KEYWORD, token_1.TokenType.COLUMN], v: [/avg/, /TYPE/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.COLUMN, `avg: ${t[i + 2].value}`) }, { t: [token_1.TokenType.COLUMN, token_1.TokenType.KEYWORD, token_1.TokenType.CARDINAL], v: [null, /PER/, null], f: (s, t, i) => { s.columnsUsed.push(`"${t[i].value}"`); return (0, token_1.createToken)(token_1.TokenType.EXPRESSION, `("${t[i].value}"*${t[i + 2].value / 100})`); } }, { t: [token_1.TokenType.COLUMN, token_1.TokenType.KEYWORD, token_1.TokenType.UNIT], v: [null, /PER/, null], f: (s, t, i) => { s.columnsUsed.push(`"${t[i].value}"`); return (0, token_1.createToken)(token_1.TokenType.EXPRESSION, `("${t[i].value}"*${t[i + 2].value / 100})`); } }, { t: [token_1.TokenType.COLUMN, token_1.TokenType.KEYWORD, token_1.TokenType.UNIT], v: [null, /AS|IN/, null], f: (s, t, i) => { s.columnsUsed.push(`"${t[i].value}"`); return (0, token_1.createToken)(token_1.TokenType.EXPRESSION, `("${t[i].value}"/${t[i + 2].value})`); } }, { t: [token_1.TokenType.COLUMN], v: [null], f: (s, t, i) => { s.columnsUsed.push(`"${t[i].value}"`); return (0, token_1.createToken)(token_1.TokenType.VALUE, `"${t[i].value}"`); } }, { t: [token_1.TokenType.NUMBER], v: [null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.VALUE, `${t[i].value}`) }, { t: [token_1.TokenType.TEXT], v: [null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.VALUE, `'${t[i].value}'`) }, { t: [token_1.TokenType.KEYWORD], v: [/NULL/], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.VALUE, t[i].value) }, { t: [token_1.TokenType.KEYWORD], v: [/TRUE|FALSE/], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, t[i].value) }, ]; const EXPRESSION = [ { t: [token_1.TokenType.OPEN, token_1.TokenType.CLOSE], v: [null, null], f: (s, t, i) => null }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.EXPRESSION, token_1.TokenType.CLOSE], v: [null, null, null], f: (s, t, i) => [(0, token_1.createToken)(token_1.TokenType.EXPRESSION, `${t[i].value}, ${t[i + 1].value}`), t[i + 2]] }, { t: [token_1.TokenType.FUNCTION], v: [/pi|random/], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.EXPRESSION, `${t[i].value}()`) }, { t: [token_1.TokenType.FUNCTION, token_1.TokenType.OPEN, token_1.TokenType.EXPRESSION, token_1.TokenType.CLOSE], v: [null, null, null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.EXPRESSION, `${t[i].value}(${t[i + 2].value})`) }, { t: [token_1.TokenType.FUNCTION, token_1.TokenType.EXPRESSION], v: [null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.EXPRESSION, `${t[i].value}(${t[i + 1].value})`) }, { t: [token_1.TokenType.OPEN, token_1.TokenType.EXPRESSION, token_1.TokenType.CLOSE], v: [null, null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.EXPRESSION, `(${t[i + 1].value})`) }, { t: [token_1.TokenType.OPERATOR, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION], v: [null, /\+|\-/, null], f: (s, t, i) => [t[i], (0, token_1.createToken)(t[i + 2].type, `${t[i + 1].value}${t[i + 2].value}`)] }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION], v: [null, /\^/, null], f: (s, t, i) => (0, token_1.createToken)(t[i].type & t[i + 2].type, `power(${t[i].value}, ${t[i + 2].value})`) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION], v: [null, /[\*\/%]/, null], f: (s, t, i) => (0, token_1.createToken)(t[i].type & t[i + 2].type, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value}`) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION], v: [null, /[\+\-]/, null], f: (s, t, i) => (0, token_1.createToken)(t[i].type & t[i + 2].type, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value}`) }, { t: [token_1.TokenType.UNARY, token_1.TokenType.EXPRESSION], v: [/[^(NOT)]/, null], f: (s, t, i) => (0, token_1.createToken)(t[i + 1].type, `${t[i].value} ${t[i + 1].value}`) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.UNARY], v: [null, /IS.*/], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i].value} ${t[i + 1].value}`) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION], v: [null, /[^\w\s=!<>]+/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.VALUE, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value}`) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.TERNARY, token_1.TokenType.EXPRESSION, token_1.TokenType.OPERATOR, token_1.TokenType.EXPRESSION], v: [null, null, null, /AND/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value} AND ${t[i + 4].value}`) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.TERNARY, token_1.TokenType.EXPRESSION, token_1.TokenType.EXPRESSION], v: [null, null, null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value} AND ${t[i + 3].value}`) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION, token_1.TokenType.OPERATOR, token_1.TokenType.EXPRESSION], v: [null, null, null, /ESCAPE/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value} ESCAPE ${t[i + 4].value}`) }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.VALUE, token_1.TokenType.BINARY, token_1.TokenType.VALUE, token_1.TokenType.OPERATOR, token_1.TokenType.VALUE], v: [null, null, /[^(OR)|(AND)]/, null, /OR|AND/, null], f: (s, t, i) => i + 6 >= t.length ? [t[i], (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i + 1].value} ${t[i + 2].value} ${t[i + 3].value} AND ${t[i + 1].value} ${t[i + 2].value} ${t[i + 5].value}`)] : t.slice(i, i + 6) }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.VALUE, token_1.TokenType.OPERATOR, token_1.TokenType.VALUE, token_1.TokenType.BINARY, token_1.TokenType.VALUE], v: [null, null, /OR|AND/, null, /[^(OR)|(AND)]/, null], f: (s, t, i) => i + 6 >= t.length ? [t[i], (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i + 1].value} ${t[i + 4].value} ${t[i + 5].value} AND ${t[i + 3].value} ${t[i + 4].value} ${t[i + 4].value}`)] : t.slice(i, i + 6) }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION], v: [null, /[^(OR)(AND)]/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value}`) }, { t: [token_1.TokenType.UNARY, token_1.TokenType.EXPRESSION], v: [null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i].value} ${t[i + 1].value}`) }, { t: [token_1.TokenType.VALUE, token_1.TokenType.BINARY, token_1.TokenType.VALUE], v: [null, /AND/, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.VALUE, `${t[i].value} + ${t[i + 2].value}`) }, { t: [token_1.TokenType.BINARY, token_1.TokenType.VALUE], v: [/AND/, null], f: (s, t, i) => { s.columnsUsed.push(t[i + 1].value); return t[i + 1]; } }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.BINARY, token_1.TokenType.EXPRESSION], v: [null, null, null], f: (s, t, i) => (0, token_1.createToken)(token_1.TokenType.BOOLEAN, `${t[i].value} ${t[i + 1].value} ${t[i + 2].value}`) }, ]; const ORDERBY = [ { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.KEYWORD, token_1.TokenType.KEYWORD], v: [null, /DESC/, /NULLS (FIRST|LAST)/], f: (s, t, i) => { s.orderBy.push(`${t[i].value} ${s.reverse ? 'ASC' : 'DESC'} ${t[i + 2].value}`); return null; } }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.KEYWORD, token_1.TokenType.KEYWORD], v: [null, /ASC/, /NULLS (FIRST|LAST)/], f: (s, t, i) => { s.orderBy.push(`${t[i].value} ${s.reverse ? 'DESC' : 'ASC'} ${t[i + 2].value}`); return null; } }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.EXPRESSION, token_1.TokenType.KEYWORD], v: [/DESC/, null, /NULLS (FIRST|LAST)/], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'ASC' : 'DESC'} ${t[i + 2].value}`); return null; } }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.EXPRESSION, token_1.TokenType.KEYWORD], v: [/ASC/, null, /NULLS (FIRST|LAST)/], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'DESC' : 'ASC'} ${t[i + 2].value}`); return null; } }, { t: [token_1.TokenType.OPERATOR, token_1.TokenType.OPERATOR, token_1.TokenType.EXPRESSION], v: [/>|>=/, /IN/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'ASC' : 'DESC'}`); return null; } }, { t: [token_1.TokenType.OPERATOR, token_1.TokenType.OPERATOR, token_1.TokenType.EXPRESSION], v: [/<|<=/, /IN/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'DESC' : 'ASC'}`); return null; } }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.KEYWORD], v: [null, /NULLS (FIRST|LAST)/], f: (s, t, i) => { s.orderBy.push(`${t[i].value} ${s.reverse ? 'DESC' : 'ASC'} ${t[i + 1].value}`); return null; } }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.EXPRESSION], v: [/NULLS (FIRST|LAST)/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'DESC' : 'ASC'} ${t[i].value}`); return null; } }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.KEYWORD], v: [null, /DESC/], f: (s, t, i) => { s.orderBy.push(`${t[i].value} ${s.reverse ? 'ASC' : 'DESC'}`); return null; } }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.EXPRESSION], v: [/DESC/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'ASC' : 'DESC'}`); return null; } }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.KEYWORD], v: [null, /ASC/], f: (s, t, i) => { s.orderBy.push(`${t[i].value} ${s.reverse ? 'DESC' : 'ASC'}`); return null; } }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.EXPRESSION], v: [/ASC/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'DESC' : 'ASC'}`); return null; } }, { t: [token_1.TokenType.OPERATOR, token_1.TokenType.EXPRESSION], v: [/>|>=/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'ASC' : 'DESC'}`); return null; } }, { t: [token_1.TokenType.OPERATOR, token_1.TokenType.EXPRESSION], v: [/<|<=/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'DESC' : 'ASC'}`); return null; } }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.OPERATOR], v: [null, />|>=/], f: (s, t, i) => { s.orderBy.push(`${t[i].value} ${s.reverse ? 'ASC' : 'DESC'}`); return null; } }, { t: [token_1.TokenType.EXPRESSION, token_1.TokenType.OPERATOR], v: [null, /<|<=/], f: (s, t, i) => { s.orderBy.push(`${t[i].value} ${s.reverse ? 'DESC' : 'ASC'}`); return null; } }, { t: [token_1.TokenType.KEYWORD, token_1.TokenType.EXPRESSION], v: [/ORDER BY/, null], f: (s, t, i) => { s.orderBy.push(`${t[i + 1].value} ${s.reverse ? 'DESC' : 'ASC'}`); return t[i]; } }, ]; const GROUPBY = [