@qrvey/formula-lang 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +15 -0
- package/CHANGELOG.md +23 -0
- package/dist/bundle.js +23152 -0
- package/dist/cjs/constants/index.d.ts +53 -0
- package/dist/cjs/constants/index.js +117 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/constants/interfaces.d.ts +91 -0
- package/dist/cjs/constants/interfaces.js +3 -0
- package/dist/cjs/constants/interfaces.js.map +1 -0
- package/dist/cjs/errors/definitions.d.ts +43 -0
- package/dist/cjs/errors/definitions.js +91 -0
- package/dist/cjs/errors/definitions.js.map +1 -0
- package/dist/cjs/errors/elasticsearch.d.ts +24 -0
- package/dist/cjs/errors/elasticsearch.js +30 -0
- package/dist/cjs/errors/elasticsearch.js.map +1 -0
- package/dist/cjs/errors/engineErrors.d.ts +2 -0
- package/dist/cjs/errors/engineErrors.js +25 -0
- package/dist/cjs/errors/engineErrors.js.map +1 -0
- package/dist/cjs/errors/index.d.ts +2 -0
- package/dist/cjs/errors/index.js +21 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/errors/snowflake.d.ts +15 -0
- package/dist/cjs/errors/snowflake.js +20 -0
- package/dist/cjs/errors/snowflake.js.map +1 -0
- package/dist/cjs/functions/abs.d.ts +5 -0
- package/dist/cjs/functions/abs.js +38 -0
- package/dist/cjs/functions/abs.js.map +1 -0
- package/dist/cjs/functions/datedif.d.ts +5 -0
- package/dist/cjs/functions/datedif.js +64 -0
- package/dist/cjs/functions/datedif.js.map +1 -0
- package/dist/cjs/functions/day.d.ts +5 -0
- package/dist/cjs/functions/day.js +39 -0
- package/dist/cjs/functions/day.js.map +1 -0
- package/dist/cjs/functions/hour.d.ts +5 -0
- package/dist/cjs/functions/hour.js +39 -0
- package/dist/cjs/functions/hour.js.map +1 -0
- package/dist/cjs/functions/if.d.ts +5 -0
- package/dist/cjs/functions/if.js +52 -0
- package/dist/cjs/functions/if.js.map +1 -0
- package/dist/cjs/functions/ifs.d.ts +5 -0
- package/dist/cjs/functions/ifs.js +74 -0
- package/dist/cjs/functions/ifs.js.map +1 -0
- package/dist/cjs/functions/index.d.ts +4 -0
- package/dist/cjs/functions/index.js +33 -0
- package/dist/cjs/functions/index.js.map +1 -0
- package/dist/cjs/functions/mid.d.ts +5 -0
- package/dist/cjs/functions/mid.js +54 -0
- package/dist/cjs/functions/mid.js.map +1 -0
- package/dist/cjs/functions/minute.d.ts +5 -0
- package/dist/cjs/functions/minute.js +39 -0
- package/dist/cjs/functions/minute.js.map +1 -0
- package/dist/cjs/functions/month.d.ts +5 -0
- package/dist/cjs/functions/month.js +39 -0
- package/dist/cjs/functions/month.js.map +1 -0
- package/dist/cjs/functions/second.d.ts +5 -0
- package/dist/cjs/functions/second.js +39 -0
- package/dist/cjs/functions/second.js.map +1 -0
- package/dist/cjs/functions/year.d.ts +5 -0
- package/dist/cjs/functions/year.js +39 -0
- package/dist/cjs/functions/year.js.map +1 -0
- package/dist/cjs/grammar/generated/qformula.lang.d.ts +13 -0
- package/dist/cjs/grammar/generated/qformula.lang.js +50 -0
- package/dist/cjs/grammar/generated/qformula.lang.js.map +1 -0
- package/dist/cjs/grammar/qformula.grammar.d.ts +1 -0
- package/dist/cjs/grammar/qformula.grammar.js +18 -0
- package/dist/cjs/grammar/qformula.grammar.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/main.d.ts +1 -0
- package/dist/cjs/main.js +69 -0
- package/dist/cjs/main.js.map +1 -0
- package/dist/cjs/parser/json-parser.d.ts +3 -0
- package/dist/cjs/parser/json-parser.js +201 -0
- package/dist/cjs/parser/json-parser.js.map +1 -0
- package/dist/cjs/parser/syntax-errors.d.ts +3 -0
- package/dist/cjs/parser/syntax-errors.js +28 -0
- package/dist/cjs/parser/syntax-errors.js.map +1 -0
- package/dist/cjs/transpiler/columnTranspilation.d.ts +3 -0
- package/dist/cjs/transpiler/columnTranspilation.js +29 -0
- package/dist/cjs/transpiler/columnTranspilation.js.map +1 -0
- package/dist/cjs/transpiler/index.d.ts +18 -0
- package/dist/cjs/transpiler/index.js +107 -0
- package/dist/cjs/transpiler/index.js.map +1 -0
- package/dist/cjs/transpiler/unshiftCustomFunctions.d.ts +2 -0
- package/dist/cjs/transpiler/unshiftCustomFunctions.js +14 -0
- package/dist/cjs/transpiler/unshiftCustomFunctions.js.map +1 -0
- package/dist/cjs/transpiler/validateFuncStructure.d.ts +2 -0
- package/dist/cjs/transpiler/validateFuncStructure.js +41 -0
- package/dist/cjs/transpiler/validateFuncStructure.js.map +1 -0
- package/dist/cjs/utils/customFunctions.d.ts +4 -0
- package/dist/cjs/utils/customFunctions.js +35 -0
- package/dist/cjs/utils/customFunctions.js.map +1 -0
- package/dist/cjs/utils/elasticsearch/index.d.ts +2 -0
- package/dist/cjs/utils/elasticsearch/index.js +22 -0
- package/dist/cjs/utils/elasticsearch/index.js.map +1 -0
- package/dist/cjs/utils/elasticsearch/scripts.d.ts +11 -0
- package/dist/cjs/utils/elasticsearch/scripts.js +57 -0
- package/dist/cjs/utils/elasticsearch/scripts.js.map +1 -0
- package/dist/cjs/utils/getMonthMaxDayAllowed.d.ts +7 -0
- package/dist/cjs/utils/getMonthMaxDayAllowed.js +26 -0
- package/dist/cjs/utils/getMonthMaxDayAllowed.js.map +1 -0
- package/dist/cjs/utils/getNodeValue.d.ts +2 -0
- package/dist/cjs/utils/getNodeValue.js +13 -0
- package/dist/cjs/utils/getNodeValue.js.map +1 -0
- package/dist/cjs/utils/getVariableType.d.ts +3 -0
- package/dist/cjs/utils/getVariableType.js +19 -0
- package/dist/cjs/utils/getVariableType.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +10 -0
- package/dist/cjs/utils/index.js +29 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/isDateParam.d.ts +2 -0
- package/dist/cjs/utils/isDateParam.js +12 -0
- package/dist/cjs/utils/isDateParam.js.map +1 -0
- package/dist/cjs/utils/isNumberParam.d.ts +2 -0
- package/dist/cjs/utils/isNumberParam.js +12 -0
- package/dist/cjs/utils/isNumberParam.js.map +1 -0
- package/dist/cjs/utils/isPositiveNumberParam.d.ts +2 -0
- package/dist/cjs/utils/isPositiveNumberParam.js +12 -0
- package/dist/cjs/utils/isPositiveNumberParam.js.map +1 -0
- package/dist/cjs/utils/isStringParam.d.ts +2 -0
- package/dist/cjs/utils/isStringParam.js +12 -0
- package/dist/cjs/utils/isStringParam.js.map +1 -0
- package/dist/cjs/utils/isValidDate.d.ts +1 -0
- package/dist/cjs/utils/isValidDate.js +8 -0
- package/dist/cjs/utils/isValidDate.js.map +1 -0
- package/dist/cjs/utils/sql/index.d.ts +1 -0
- package/dist/cjs/utils/sql/index.js +6 -0
- package/dist/cjs/utils/sql/index.js.map +1 -0
- package/dist/cjs/utils/sql/scripts.d.ts +3 -0
- package/dist/cjs/utils/sql/scripts.js +44 -0
- package/dist/cjs/utils/sql/scripts.js.map +1 -0
- package/dist/constants/index.d.ts +11 -2
- package/dist/constants/index.js +11 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/interfaces.d.ts +21 -11
- package/dist/errors/definitions.d.ts +20 -3
- package/dist/errors/definitions.js +20 -2
- package/dist/errors/definitions.js.map +1 -1
- package/dist/grammar/generated/qformula.lang.d.ts +9 -0
- package/dist/grammar/generated/qformula.lang.js +5 -4
- package/dist/grammar/generated/qformula.lang.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.html +21 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/main.js +65 -0
- package/dist/main.js.map +1 -0
- package/dist/module/constants/index.d.ts +53 -0
- package/dist/module/constants/index.js +114 -0
- package/dist/module/constants/index.js.map +1 -0
- package/dist/module/constants/interfaces.d.ts +91 -0
- package/dist/module/constants/interfaces.js +2 -0
- package/dist/module/constants/interfaces.js.map +1 -0
- package/dist/module/errors/definitions.d.ts +43 -0
- package/dist/module/errors/definitions.js +78 -0
- package/dist/module/errors/definitions.js.map +1 -0
- package/dist/module/errors/elasticsearch.d.ts +24 -0
- package/dist/module/errors/elasticsearch.js +27 -0
- package/dist/module/errors/elasticsearch.js.map +1 -0
- package/dist/module/errors/engineErrors.d.ts +2 -0
- package/dist/module/errors/engineErrors.js +21 -0
- package/dist/module/errors/engineErrors.js.map +1 -0
- package/dist/module/errors/index.d.ts +2 -0
- package/dist/module/errors/index.js +5 -0
- package/dist/module/errors/index.js.map +1 -0
- package/dist/module/errors/snowflake.d.ts +15 -0
- package/dist/module/errors/snowflake.js +17 -0
- package/dist/module/errors/snowflake.js.map +1 -0
- package/dist/module/functions/abs.d.ts +5 -0
- package/dist/module/functions/abs.js +35 -0
- package/dist/module/functions/abs.js.map +1 -0
- package/dist/module/functions/datedif.d.ts +5 -0
- package/dist/module/functions/datedif.js +61 -0
- package/dist/module/functions/datedif.js.map +1 -0
- package/dist/module/functions/day.d.ts +5 -0
- package/dist/module/functions/day.js +36 -0
- package/dist/module/functions/day.js.map +1 -0
- package/dist/module/functions/hour.d.ts +5 -0
- package/dist/module/functions/hour.js +36 -0
- package/dist/module/functions/hour.js.map +1 -0
- package/dist/module/functions/if.d.ts +5 -0
- package/dist/module/functions/if.js +49 -0
- package/dist/module/functions/if.js.map +1 -0
- package/dist/module/functions/ifs.d.ts +5 -0
- package/dist/module/functions/ifs.js +71 -0
- package/dist/module/functions/ifs.js.map +1 -0
- package/dist/module/functions/index.d.ts +4 -0
- package/dist/module/functions/index.js +29 -0
- package/dist/module/functions/index.js.map +1 -0
- package/dist/module/functions/mid.d.ts +5 -0
- package/dist/module/functions/mid.js +51 -0
- package/dist/module/functions/mid.js.map +1 -0
- package/dist/module/functions/minute.d.ts +5 -0
- package/dist/module/functions/minute.js +36 -0
- package/dist/module/functions/minute.js.map +1 -0
- package/dist/module/functions/month.d.ts +5 -0
- package/dist/module/functions/month.js +36 -0
- package/dist/module/functions/month.js.map +1 -0
- package/dist/module/functions/second.d.ts +5 -0
- package/dist/module/functions/second.js +36 -0
- package/dist/module/functions/second.js.map +1 -0
- package/dist/module/functions/year.d.ts +5 -0
- package/dist/module/functions/year.js +36 -0
- package/dist/module/functions/year.js.map +1 -0
- package/dist/module/grammar/generated/qformula.lang.d.ts +13 -0
- package/dist/module/grammar/generated/qformula.lang.js +45 -0
- package/dist/module/grammar/generated/qformula.lang.js.map +1 -0
- package/dist/module/grammar/qformula.grammar.d.ts +1 -0
- package/dist/module/grammar/qformula.grammar.js +2 -0
- package/dist/module/grammar/qformula.grammar.js.map +1 -0
- package/dist/module/index.d.ts +10 -0
- package/dist/module/index.js +20 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/main.d.ts +1 -0
- package/dist/module/main.js +67 -0
- package/dist/module/main.js.map +1 -0
- package/dist/module/parser/json-parser.d.ts +3 -0
- package/dist/module/parser/json-parser.js +197 -0
- package/dist/module/parser/json-parser.js.map +1 -0
- package/dist/module/parser/syntax-errors.d.ts +3 -0
- package/dist/module/parser/syntax-errors.js +24 -0
- package/dist/module/parser/syntax-errors.js.map +1 -0
- package/dist/module/transpiler/columnTranspilation.d.ts +3 -0
- package/dist/module/transpiler/columnTranspilation.js +25 -0
- package/dist/module/transpiler/columnTranspilation.js.map +1 -0
- package/dist/module/transpiler/index.d.ts +18 -0
- package/dist/module/transpiler/index.js +102 -0
- package/dist/module/transpiler/index.js.map +1 -0
- package/dist/module/transpiler/unshiftCustomFunctions.d.ts +2 -0
- package/dist/module/transpiler/unshiftCustomFunctions.js +10 -0
- package/dist/module/transpiler/unshiftCustomFunctions.js.map +1 -0
- package/dist/module/transpiler/validateFuncStructure.d.ts +2 -0
- package/dist/module/transpiler/validateFuncStructure.js +37 -0
- package/dist/module/transpiler/validateFuncStructure.js.map +1 -0
- package/dist/module/utils/customFunctions.d.ts +4 -0
- package/dist/module/utils/customFunctions.js +29 -0
- package/dist/module/utils/customFunctions.js.map +1 -0
- package/dist/module/utils/elasticsearch/index.d.ts +2 -0
- package/dist/module/utils/elasticsearch/index.js +16 -0
- package/dist/module/utils/elasticsearch/index.js.map +1 -0
- package/dist/module/utils/elasticsearch/scripts.d.ts +11 -0
- package/dist/module/utils/elasticsearch/scripts.js +46 -0
- package/dist/module/utils/elasticsearch/scripts.js.map +1 -0
- package/dist/module/utils/getMonthMaxDayAllowed.d.ts +7 -0
- package/dist/module/utils/getMonthMaxDayAllowed.js +22 -0
- package/dist/module/utils/getMonthMaxDayAllowed.js.map +1 -0
- package/dist/module/utils/getNodeValue.d.ts +2 -0
- package/dist/module/utils/getNodeValue.js +9 -0
- package/dist/module/utils/getNodeValue.js.map +1 -0
- package/dist/module/utils/getVariableType.d.ts +3 -0
- package/dist/module/utils/getVariableType.js +14 -0
- package/dist/module/utils/getVariableType.js.map +1 -0
- package/dist/module/utils/index.d.ts +10 -0
- package/dist/module/utils/index.js +11 -0
- package/dist/module/utils/index.js.map +1 -0
- package/dist/module/utils/isDateParam.d.ts +2 -0
- package/dist/module/utils/isDateParam.js +8 -0
- package/dist/module/utils/isDateParam.js.map +1 -0
- package/dist/module/utils/isNumberParam.d.ts +2 -0
- package/dist/module/utils/isNumberParam.js +8 -0
- package/dist/module/utils/isNumberParam.js.map +1 -0
- package/dist/module/utils/isPositiveNumberParam.d.ts +2 -0
- package/dist/module/utils/isPositiveNumberParam.js +8 -0
- package/dist/module/utils/isPositiveNumberParam.js.map +1 -0
- package/dist/module/utils/isStringParam.d.ts +2 -0
- package/dist/module/utils/isStringParam.js +8 -0
- package/dist/module/utils/isStringParam.js.map +1 -0
- package/dist/module/utils/isValidDate.d.ts +1 -0
- package/dist/module/utils/isValidDate.js +4 -0
- package/dist/module/utils/isValidDate.js.map +1 -0
- package/dist/module/utils/sql/index.d.ts +1 -0
- package/dist/module/utils/sql/index.js +2 -0
- package/dist/module/utils/sql/index.js.map +1 -0
- package/dist/module/utils/sql/scripts.d.ts +3 -0
- package/dist/module/utils/sql/scripts.js +39 -0
- package/dist/module/utils/sql/scripts.js.map +1 -0
- package/dist/parser/json-parser.js +26 -15
- package/dist/parser/json-parser.js.map +1 -1
- package/dist/parser/syntax-errors.d.ts +3 -0
- package/dist/parser/syntax-errors.js +20 -0
- package/dist/parser/syntax-errors.js.map +1 -0
- package/dist/transpiler/columnTranspilation.d.ts +3 -0
- package/dist/transpiler/columnTranspilation.js +25 -0
- package/dist/transpiler/columnTranspilation.js.map +1 -0
- package/dist/transpiler/index.d.ts +6 -5
- package/dist/transpiler/index.js +33 -20
- package/dist/transpiler/index.js.map +1 -1
- package/dist/transpiler/unshiftCustomFunctions.d.ts +2 -0
- package/dist/transpiler/unshiftCustomFunctions.js +10 -0
- package/dist/transpiler/unshiftCustomFunctions.js.map +1 -0
- package/dist/utils/customFunctions.d.ts +1 -0
- package/dist/utils/customFunctions.js +10 -2
- package/dist/utils/customFunctions.js.map +1 -1
- package/dist/utils/elasticsearch/index.d.ts +1 -1
- package/dist/utils/elasticsearch/index.js +1 -1
- package/dist/utils/elasticsearch/index.js.map +1 -1
- package/dist/utils/elasticsearch/scripts.d.ts +1 -0
- package/dist/utils/elasticsearch/scripts.js +14 -4
- package/dist/utils/elasticsearch/scripts.js.map +1 -1
- package/dist/utils/getVariableType.d.ts +3 -3
- package/dist/utils/getVariableType.js.map +1 -1
- package/jest.config.ts +6 -0
- package/package.json +21 -6
- package/__tests__/integration/__mocks__/elasticsearchScripts.ts +0 -21
- package/__tests__/integration/__mocks__/sqlScripts.ts +0 -20
- package/__tests__/integration/elasticsearch.test.ts +0 -158
- package/__tests__/integration/expression.test.ts +0 -22
- package/__tests__/integration/redshift.test.ts +0 -127
- package/__tests__/integration/sonwflake.test.ts +0 -123
- package/__tests__/unit/parser.test.ts +0 -236
- package/__tests__/unit/transpiler.test.ts +0 -128
- package/bitbucket-pipelines.yml +0 -63
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QFormulaLang = exports.QFormulaHighlightConfig = exports.QFormula = void 0;
|
|
4
|
+
const lr_1 = require("@lezer/lr");
|
|
5
|
+
const language_1 = require("@codemirror/language");
|
|
6
|
+
const highlight_1 = require("@lezer/highlight");
|
|
7
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
8
|
+
const spec_identifier = { __proto__: null, true: 16, false: 16, null: 18 };
|
|
9
|
+
const parser = lr_1.LRParser.deserialize({
|
|
10
|
+
version: 14,
|
|
11
|
+
states: "%vO]QPOOO!cQPO'#CfOOQO'#C`'#C`OOQO'#Ch'#ChO!jQPO'#CgO!oQQO'#CjO]QPO'#CkQ!tQSOOO]QPO'#CqOOQO'#C_'#C_O#SQPO'#C{O#[QPO,59QO#aQPO,59RO#hQPO,59UOOQO,59V,59VO]QPO,59XO]QPO,59XO]QPO,59XO#mQSO,59]O$OQPO'#CrO$YQPO,59gOOQO1G.l1G.lO$bQSO'#DPOOQO'#Ci'#CiO$vQPO1G.mOOQO1G.p1G.pOOQO1G.s1G.sO%^QSO1G.sO%hQSO1G.sOOQO1G.w1G.wOOQO,59^,59^OOQO-E6p-E6pO%rQPO'#CsO%|QPO,59kOOQO7+$X7+$XO&UQSO,59_OOQO-E6q-E6q",
|
|
12
|
+
stateData: "&r~OjOSkOSPOS~OTQOUQOVQOWQOXQO`UOlROnPOrWOuTO~OTQOUQOVQOWQOXQOnPO~OmoP~P}Or[O~Ov]O~O`aOb_Oc`Od`O~OpcOmoX~OmeO~OqsP~P]OtiO~O`aOb_Oc`Od`OqmO~OmfXpfX~P}OpcOmoa~O`aOb_Oc`Od`OppOqsX~OqrO~Ob_O`aihaiqaipai~Ocaidai~P${Oc`Od`O~P${OpgXqgX~P]OppOqsa~O`aOb_Oc`Od`Opgaqga~OUVPjklc~",
|
|
13
|
+
goto: "#vtPPPu!_PPPPP!o!{#V#a!{!{P!{PPP!{#d#jPPPPPPP#pPPP#sQVOQ^UQbWQf[Qj_Qk`QlaRsp`XOUW[_`apQYPRnceQOPUW[_`acpaXOUW[_`apaSOUW[_`apRh[QdYRodQqfRtqRZPRg[",
|
|
14
|
+
nodeNames: "⚠ LineComment Program Expression Value Number Date String Boolean Null Array Function FunctionIdentifier FunctionArguments Variable UnaryExpression ArithOp BinaryExpression LogicOp ArithOp ArithOp ParenthesizedExpression",
|
|
15
|
+
maxTerm: 38,
|
|
16
|
+
skippedNodes: [0, 1],
|
|
17
|
+
repeatNodeCount: 2,
|
|
18
|
+
tokenData: "=S~RpXY#VYZ#zZ[#V]^#zpq#Vrs$Pxy7kyz7pz{7u{|7z|}9S}!O7z!O!P9X!P!Q:a!Q![;Q!^!_;n!_!`;{!`!a<Q!c!}<[!}#O<x#P#Q<}#R#S8h#T#o<[$f$g#V#BY#BZ#V$IS$I_#V$I|$I}#z$I}$JO#z$JT$JU#V$KV$KW#V&FU&FV#V?HT?HU#V~#[Yj~XY#VZ[#Vpq#V$f$g#V#BY#BZ#V$IS$I_#V$JT$JU#V$KV$KW#V&FU&FV#V?HT?HU#V~$POk~~$SZOr$urs%_s!Q$u!Q!R&c!R!S6r!S![6S![#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~$xVOr$urs%_s#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~%dOV~~%gRO;'S$u;'S;=`%p;=`O$u~%sWOr$urs%_s#O$u#O#P%d#P;'S$u;'S;=`&];=`<%l$u<%lO$u~&`P;=`<%l$u~&fYOr$urs%_s!P$u!P!Q'U!Q![6S![#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~'X]Or$urs%_s!Q$u!Q!R(Q!R!S(Q!S!T(Q!T!U(Q!U![5d![#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~(TYOr$urs%_s!P$u!P!Q(s!Q![5d![#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~(vXOr$urs%_s!Q$u!Q![)c![#O$u#O#P%d#P;'S$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_s!Q$u!Q!U0R!U![$u![!]0q!]#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~5gXOr$urs%_s!P$u!P!Q(s!Q#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~6VXOr$urs%_s!P$u!P!Q'U!Q#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~6u[Or$urs%_s!P$u!P!Q'U!Q!R6S!R!S6S!S!T6S!T#O$u#O#P%d#P;'S$u;'S;=`&]<%lO$u~7pOr~~7uOq~~7zOd~V8RV`TvQ{|8h}!O8h!O!P8h!Q![8h!c!}8h#R#S8h#T#o8hQ8mVvQ{|8h}!O8h!O!P8h!Q![8h!c!}8h#R#S8h#T#o8h~9XOp~R9^VvQ{|8h}!O8h!O!P8h!Q![9s!c!}8h#R#S8h#T#o8hR9zVTPvQ{|8h}!O8h!O!P8h!Q![9s!c!}8h#R#S9s#T#o8h~:fPc~!P!Q:i~:nSP~OY:iZ;'S:i;'S;=`:z<%lO:i~:}P;=`<%l:iR;XVTPvQ{|8h}!O8h!O!P9s!Q![;Q!c!}8h#R#S;Q#T#o8hT;uQnPbS!_!`;{!`!a;{S<QObST<XPmPbS!_!`;{R<cVvQlP{|8h}!O8h!O!P8h!Q![<[!c!}<[#R#S<[#T#o<[~<}Ou~~=SOt~",
|
|
19
|
+
tokenizers: [0, 1, 2],
|
|
20
|
+
topRules: { "Program": [0, 2] },
|
|
21
|
+
specialized: [{ term: 28, get: value => spec_identifier[value] || -1 }],
|
|
22
|
+
tokenPrec: 256
|
|
23
|
+
});
|
|
24
|
+
const QFormulaHighlightConfig = {
|
|
25
|
+
parser: parser.configure({
|
|
26
|
+
props: [
|
|
27
|
+
(0, highlight_1.styleTags)({
|
|
28
|
+
Boolean: highlight_1.tags.bool,
|
|
29
|
+
String: highlight_1.tags.string,
|
|
30
|
+
Date: highlight_1.tags.string,
|
|
31
|
+
Number: highlight_1.tags.number,
|
|
32
|
+
Variable: highlight_1.tags.keyword,
|
|
33
|
+
LineComment: highlight_1.tags.lineComment,
|
|
34
|
+
FunctionIdentifier: highlight_1.tags.lineComment,
|
|
35
|
+
'( )': highlight_1.tags.paren,
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
}),
|
|
39
|
+
languageData: {
|
|
40
|
+
commentTokens: { line: '//' },
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
exports.QFormulaHighlightConfig = QFormulaHighlightConfig;
|
|
44
|
+
const QFormulaLang = language_1.LRLanguage.define(QFormulaHighlightConfig);
|
|
45
|
+
exports.QFormulaLang = QFormulaLang;
|
|
46
|
+
function QFormula() {
|
|
47
|
+
return new language_1.LanguageSupport(QFormulaLang);
|
|
48
|
+
}
|
|
49
|
+
exports.QFormula = QFormula;
|
|
50
|
+
//# sourceMappingURL=qformula.lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qformula.lang.js","sourceRoot":"","sources":["../../../../src/grammar/generated/qformula.lang.js"],"names":[],"mappings":";;;AAAA,kCAAqC;AACrC,mDAAmE;AACnE,gDAAmD;AAEnD,8EAA8E;AAC9E,MAAM,eAAe,GAAG,EAAC,SAAS,EAAC,IAAI,EAAC,IAAI,EAAC,EAAE,EAAE,KAAK,EAAC,EAAE,EAAE,IAAI,EAAC,EAAE,EAAC,CAAC;AACpE,MAAM,MAAM,GAAG,aAAQ,CAAC,WAAW,CAAC;IAClC,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,oYAAoY;IAC5Y,SAAS,EAAE,8QAA8Q;IACzR,IAAI,EAAE,mJAAmJ;IACzJ,SAAS,EAAE,8NAA8N;IACzO,OAAO,EAAE,EAAE;IACX,YAAY,EAAE,CAAC,CAAC,EAAC,CAAC,CAAC;IACnB,eAAe,EAAE,CAAC;IAClB,SAAS,EAAE,s2EAAs2E;IACj3E,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACrB,QAAQ,EAAE,EAAC,SAAS,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC;IAC3B,WAAW,EAAE,CAAC,EAAC,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAC,CAAC;IACrE,SAAS,EAAE,GAAG;CACf,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC;QACrB,KAAK,EAAE;YACH,IAAA,qBAAS,EAAC;gBACN,OAAO,EAAE,gBAAI,CAAC,IAAI;gBAClB,MAAM,EAAE,gBAAI,CAAC,MAAM;gBACnB,IAAI,EAAE,gBAAI,CAAC,MAAM;gBACjB,MAAM,EAAE,gBAAI,CAAC,MAAM;gBACnB,QAAQ,EAAE,gBAAI,CAAC,OAAO;gBACtB,WAAW,EAAE,gBAAI,CAAC,WAAW;gBAC7B,kBAAkB,EAAE,gBAAI,CAAC,WAAW;gBACpC,KAAK,EAAE,gBAAI,CAAC,KAAK;aACpB,CAAC;SACL;KACJ,CAAC;IACF,YAAY,EAAE;QACV,aAAa,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;KAChC;CACJ,CAAC;AAMiB,0DAAuB;AAL1C,MAAM,YAAY,GAAG,qBAAU,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAKpB,oCAAY;AAJxD,SAAS,QAAQ;IACb,OAAO,IAAI,0BAAe,CAAC,YAAY,CAAC,CAAC;AAC7C,CAAC;AAEQ,4BAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generated/qformula.lang.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./generated/qformula.lang.js"), exports);
|
|
18
|
+
//# sourceMappingURL=qformula.grammar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qformula.grammar.js","sourceRoot":"","sources":["../../../src/grammar/qformula.grammar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ENGINES } from './constants/index';
|
|
2
|
+
import { FormulaContext, TranspilationResponse } from './constants/interfaces';
|
|
3
|
+
export { QFormula as FormulaHighlight, QFormulaLang as FormulaLang, QFormulaHighlightConfig as FormulaHightConfig, } from './grammar/qformula.grammar';
|
|
4
|
+
export { calculateAST } from './parser/json-parser';
|
|
5
|
+
export { ENGINES } from './constants/index';
|
|
6
|
+
export { FUNCTION_LIST, getFunctionDetail } from './functions/index';
|
|
7
|
+
export { TranspileAST } from './transpiler/index';
|
|
8
|
+
export { ProgramAST, TranspilationResponse, FormulaContext, } from './constants/interfaces';
|
|
9
|
+
export { BaseError } from './errors';
|
|
10
|
+
export declare function Transpile(program: string, engine: ENGINES, context?: FormulaContext): TranspilationResponse | undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transpile = exports.BaseError = exports.TranspileAST = exports.getFunctionDetail = exports.FUNCTION_LIST = exports.ENGINES = exports.calculateAST = exports.FormulaHightConfig = exports.FormulaLang = exports.FormulaHighlight = void 0;
|
|
4
|
+
const qformula_grammar_1 = require("./grammar/qformula.grammar");
|
|
5
|
+
const json_parser_1 = require("./parser/json-parser");
|
|
6
|
+
const index_1 = require("./transpiler/index");
|
|
7
|
+
var qformula_grammar_2 = require("./grammar/qformula.grammar");
|
|
8
|
+
Object.defineProperty(exports, "FormulaHighlight", { enumerable: true, get: function () { return qformula_grammar_2.QFormula; } });
|
|
9
|
+
Object.defineProperty(exports, "FormulaLang", { enumerable: true, get: function () { return qformula_grammar_2.QFormulaLang; } });
|
|
10
|
+
Object.defineProperty(exports, "FormulaHightConfig", { enumerable: true, get: function () { return qformula_grammar_2.QFormulaHighlightConfig; } });
|
|
11
|
+
var json_parser_2 = require("./parser/json-parser");
|
|
12
|
+
Object.defineProperty(exports, "calculateAST", { enumerable: true, get: function () { return json_parser_2.calculateAST; } });
|
|
13
|
+
var index_2 = require("./constants/index");
|
|
14
|
+
Object.defineProperty(exports, "ENGINES", { enumerable: true, get: function () { return index_2.ENGINES; } });
|
|
15
|
+
var index_3 = require("./functions/index");
|
|
16
|
+
Object.defineProperty(exports, "FUNCTION_LIST", { enumerable: true, get: function () { return index_3.FUNCTION_LIST; } });
|
|
17
|
+
Object.defineProperty(exports, "getFunctionDetail", { enumerable: true, get: function () { return index_3.getFunctionDetail; } });
|
|
18
|
+
var index_4 = require("./transpiler/index");
|
|
19
|
+
Object.defineProperty(exports, "TranspileAST", { enumerable: true, get: function () { return index_4.TranspileAST; } });
|
|
20
|
+
var errors_1 = require("./errors");
|
|
21
|
+
Object.defineProperty(exports, "BaseError", { enumerable: true, get: function () { return errors_1.BaseError; } });
|
|
22
|
+
function Transpile(program, engine, context) {
|
|
23
|
+
const parser = qformula_grammar_1.QFormulaLang.parser;
|
|
24
|
+
const { topNode } = parser.parse(program);
|
|
25
|
+
if (!topNode)
|
|
26
|
+
return;
|
|
27
|
+
const ast = (0, json_parser_1.calculateAST)(program, topNode, context);
|
|
28
|
+
if (!ast)
|
|
29
|
+
return;
|
|
30
|
+
return (0, index_1.TranspileAST)(ast, engine, context);
|
|
31
|
+
}
|
|
32
|
+
exports.Transpile = Transpile;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAEA,iEAA0D;AAC1D,sDAAoD;AACpD,8CAAkD;AAElD,+DAIoC;AAHhC,oHAAA,QAAQ,OAAoB;AAC5B,+GAAA,YAAY,OAAe;AAC3B,sHAAA,uBAAuB,OAAsB;AAEjD,oDAAoD;AAA3C,2GAAA,YAAY,OAAA;AACrB,2CAA4C;AAAnC,gGAAA,OAAO,OAAA;AAChB,2CAAqE;AAA5D,sGAAA,aAAa,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AACzC,4CAAkD;AAAzC,qGAAA,YAAY,OAAA;AAMrB,mCAAqC;AAA5B,mGAAA,SAAS,OAAA;AAElB,SAAgB,SAAS,CACrB,OAAe,EACf,MAAe,EACf,OAAwB;IAExB,MAAM,MAAM,GAAG,+BAAY,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,MAAM,GAAG,GAAG,IAAA,0BAAY,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACpD,IAAI,CAAC,GAAG;QAAE,OAAO;IACjB,OAAO,IAAA,oBAAY,EAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC;AAXD,8BAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cjs/main.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require(".");
|
|
4
|
+
customElements.whenDefined('q-codemirror-test').then(load);
|
|
5
|
+
const context = {
|
|
6
|
+
model: [
|
|
7
|
+
{
|
|
8
|
+
id: 'idColumn1',
|
|
9
|
+
replacement: 'Date_Origin_Column1',
|
|
10
|
+
label: 'Date',
|
|
11
|
+
type: 'date',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: 'idColumn2',
|
|
15
|
+
replacement: 'Date_Origin_Column2',
|
|
16
|
+
label: 'DateTime',
|
|
17
|
+
type: 'date',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: 'idColumn3',
|
|
21
|
+
replacement: 'Date_Origin_Column3',
|
|
22
|
+
label: 'Donations',
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 'idColumn4',
|
|
27
|
+
replacement: 'Date_Origin_Column4',
|
|
28
|
+
label: 'Duration',
|
|
29
|
+
type: 'number',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'idColumn5',
|
|
33
|
+
replacement: 'Date_Origin_Column5',
|
|
34
|
+
label: 'City',
|
|
35
|
+
type: 'string',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'idColumn6',
|
|
39
|
+
replacement: 'Date_Origin_Column6',
|
|
40
|
+
label: 'City New',
|
|
41
|
+
type: 'string',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'idColumn7',
|
|
45
|
+
replacement: 'Date_Origin_Column7',
|
|
46
|
+
label: 'City New Country',
|
|
47
|
+
type: 'string',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'idColumn8',
|
|
51
|
+
replacement: 'Date_Origin_Column8',
|
|
52
|
+
label: 'Country',
|
|
53
|
+
type: 'string',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
function load() {
|
|
58
|
+
const quiFormulaEditor = document.querySelector('q-codemirror-test');
|
|
59
|
+
if (quiFormulaEditor) {
|
|
60
|
+
// (quiFormulaEditor as any).value = 'DATEDIF([idColumn1], "11/02/2021 10:22:30", "Y") + 1 + MONTH([idColumn1]) + DAY([idColumn1])';
|
|
61
|
+
quiFormulaEditor.value = 'ABS()';
|
|
62
|
+
quiFormulaEditor.context = context;
|
|
63
|
+
quiFormulaEditor.langSupport = {
|
|
64
|
+
customCalculateAST: _1.calculateAST,
|
|
65
|
+
customTranspileAST: _1.TranspileAST,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":";;AAAA,wBAA+C;AAE/C,cAAc,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3D,MAAM,OAAO,GAAG;IACZ,KAAK,EAAE;QACH;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM;SACf;QACD;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,MAAM;SACf;QACD;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,WAAW;YAClB,IAAI,EAAE,QAAQ;SACjB;QACD;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,QAAQ;SACjB;QACD;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;SACjB;QACD;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,QAAQ;SACjB;QACD;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,kBAAkB;YACzB,IAAI,EAAE,QAAQ;SACjB;QACD;YACI,EAAE,EAAE,WAAW;YACf,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,QAAQ;SACjB;KACJ;CACJ,CAAC;AAEF,SAAS,IAAI;IACT,MAAM,gBAAgB,GAAG,QAAQ,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;IACrE,IAAI,gBAAgB,EAAE;QAClB,oIAAoI;QACnI,gBAAwB,CAAC,KAAK,GAAG,OAAO,CAAC;QACzC,gBAAwB,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3C,gBAAwB,CAAC,WAAW,GAAG;YACpC,kBAAkB,EAAE,eAAY;YAChC,kBAAkB,EAAE,eAAY;SACnC,CAAC;KACL;AACL,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateAST = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const syntax_errors_1 = require("./syntax-errors");
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
const functions_1 = require("../functions");
|
|
9
|
+
const PARSER_VERSION = '0.0.0';
|
|
10
|
+
const LANG_NAME = 'QrveyLang';
|
|
11
|
+
function calculateAST(program, startNode, context) {
|
|
12
|
+
if (!startNode)
|
|
13
|
+
return;
|
|
14
|
+
const syntaxErrors = (0, syntax_errors_1.calculateNodeSyntaxErrors)(program, startNode);
|
|
15
|
+
return {
|
|
16
|
+
type: constants_1.AST_TYPES.program,
|
|
17
|
+
exp: program,
|
|
18
|
+
lang: LANG_NAME,
|
|
19
|
+
version: PARSER_VERSION,
|
|
20
|
+
body: transformNode(program, startNode, syntaxErrors, context),
|
|
21
|
+
from: startNode.from,
|
|
22
|
+
to: startNode.to,
|
|
23
|
+
errors: syntaxErrors,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.calculateAST = calculateAST;
|
|
27
|
+
function transformNode(program, node, errorList, context) {
|
|
28
|
+
if (!node)
|
|
29
|
+
return undefined;
|
|
30
|
+
switch (node.name) {
|
|
31
|
+
case 'BinaryExpression':
|
|
32
|
+
return transformBinaryExpression(program, node, errorList, context);
|
|
33
|
+
case 'UnaryExpression':
|
|
34
|
+
return transformUnaryExpression(program, node, errorList, context);
|
|
35
|
+
case 'Function':
|
|
36
|
+
return transformFunctionExpression(program, node, errorList, context);
|
|
37
|
+
case 'Number':
|
|
38
|
+
return transformNumberValue(program, node);
|
|
39
|
+
case 'Date':
|
|
40
|
+
return transformDateValue(program, node);
|
|
41
|
+
case 'String':
|
|
42
|
+
return transformStringValue(program, node);
|
|
43
|
+
case 'Boolean':
|
|
44
|
+
return transformBooleanValue(program, node);
|
|
45
|
+
case 'Null':
|
|
46
|
+
return transformNullValue(program, node);
|
|
47
|
+
case 'Array':
|
|
48
|
+
return transformArrayValue(program, node, errorList, context);
|
|
49
|
+
case 'Variable':
|
|
50
|
+
return transformVariableValue(program, node, context);
|
|
51
|
+
default:
|
|
52
|
+
return node.firstChild
|
|
53
|
+
? transformNode(program, node.firstChild, errorList, context)
|
|
54
|
+
: undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function transformBinaryExpression(program, node, errorList, context) {
|
|
58
|
+
const [leftNode, rightNode] = node.getChildren('Expression');
|
|
59
|
+
const logicOperator = node.getChild('LogicOp');
|
|
60
|
+
const arithOperator = node.getChild('ArithOp');
|
|
61
|
+
const left = transformNode(program, leftNode, errorList, context);
|
|
62
|
+
const right = transformNode(program, rightNode, errorList, context);
|
|
63
|
+
const leftIsNotAValidNumber = (left === null || left === void 0 ? void 0 : left.type) === constants_1.AST_TYPES.literal &&
|
|
64
|
+
left.dataType !== 'number';
|
|
65
|
+
const rightIsNotAValidNumber = (right === null || right === void 0 ? void 0 : right.type) === constants_1.AST_TYPES.literal &&
|
|
66
|
+
right.dataType !== 'number';
|
|
67
|
+
const binaryAST = {
|
|
68
|
+
operator: (0, utils_1.getNodeValue)(program, (logicOperator !== null && logicOperator !== void 0 ? logicOperator : arithOperator)),
|
|
69
|
+
type: constants_1.AST_TYPES.binaryExpression,
|
|
70
|
+
left,
|
|
71
|
+
right,
|
|
72
|
+
from: node.from,
|
|
73
|
+
to: node.to,
|
|
74
|
+
};
|
|
75
|
+
if (!leftNode ||
|
|
76
|
+
!rightNode ||
|
|
77
|
+
(arithOperator && (leftIsNotAValidNumber || rightIsNotAValidNumber))) {
|
|
78
|
+
errorList.push(new errors_1.NotAllowedExpressionError(binaryAST));
|
|
79
|
+
}
|
|
80
|
+
return binaryAST;
|
|
81
|
+
}
|
|
82
|
+
function transformUnaryExpression(program, node, errorList, context) {
|
|
83
|
+
const [right] = node.getChildren('Expression');
|
|
84
|
+
const operator = node.getChild('ArithOp');
|
|
85
|
+
return {
|
|
86
|
+
operator: (0, utils_1.getNodeValue)(program, operator),
|
|
87
|
+
type: constants_1.AST_TYPES.unaryExpression,
|
|
88
|
+
right: transformNode(program, right, errorList, context),
|
|
89
|
+
from: node.from,
|
|
90
|
+
to: node.to,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function transformFunctionExpression(program, node, errorList, context) {
|
|
94
|
+
const args = node.getChild('FunctionArguments');
|
|
95
|
+
const fnIdentifier = node.getChild('FunctionIdentifier');
|
|
96
|
+
const fnName = (0, utils_1.getNodeValue)(program, fnIdentifier);
|
|
97
|
+
const fnString = (0, utils_1.getNodeValue)(program, node);
|
|
98
|
+
const parenthesisIsNotOpen = fnString.slice(fnName.length, fnName.length + 1) !== '(';
|
|
99
|
+
const parenthesisIsNotClosed = fnString.slice(-1) !== ')';
|
|
100
|
+
const resultNode = {
|
|
101
|
+
type: constants_1.AST_TYPES.functionCall,
|
|
102
|
+
name: (0, utils_1.getNodeValue)(program, fnIdentifier),
|
|
103
|
+
arguments: args
|
|
104
|
+
? args.getChildren('Expression').map((childNode) => {
|
|
105
|
+
const nodeResult = transformNode(program, childNode, errorList, context);
|
|
106
|
+
return (nodeResult !== null && nodeResult !== void 0 ? nodeResult : createUnknownValue(childNode, (0, utils_1.getNodeValue)(program, childNode)));
|
|
107
|
+
})
|
|
108
|
+
: [],
|
|
109
|
+
from: node.from,
|
|
110
|
+
to: node.to,
|
|
111
|
+
};
|
|
112
|
+
const functionExists = functions_1.FUNCTION_LIST.includes(fnName);
|
|
113
|
+
if (functionExists && (parenthesisIsNotOpen || parenthesisIsNotClosed)) {
|
|
114
|
+
errorList.push(new errors_1.MissingParenthesisError(resultNode));
|
|
115
|
+
}
|
|
116
|
+
return resultNode;
|
|
117
|
+
}
|
|
118
|
+
function createLiteralValue({ from, to }, dataType, value) {
|
|
119
|
+
return {
|
|
120
|
+
type: constants_1.AST_TYPES.literal,
|
|
121
|
+
dataType,
|
|
122
|
+
value,
|
|
123
|
+
from,
|
|
124
|
+
to,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function createUnknownValue({ from, to }, text) {
|
|
128
|
+
return {
|
|
129
|
+
type: constants_1.AST_TYPES.unknown,
|
|
130
|
+
from,
|
|
131
|
+
to,
|
|
132
|
+
text,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// "MM/DD/YYYY" or "MM/DD/YYYY HH:mm:ss"
|
|
136
|
+
const DATE_REGEXP = /^([0]?\d|[1][012])[/]([0-3]?\d)[/](\d{2}|\d{4})(?:\s+(\d|[01]\d|2[0-3]):([0-5]\d):([0-5]\d))?$/;
|
|
137
|
+
function transformDateValue(program, node) {
|
|
138
|
+
const dateStr = (0, utils_1.getNodeValue)(program, node).slice(1, -1);
|
|
139
|
+
const dateMatch = DATE_REGEXP.exec(dateStr);
|
|
140
|
+
if (!dateMatch)
|
|
141
|
+
return transformStringValue(program, node);
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
143
|
+
const [_full, dateMonth, dateDay, dateYear, dateHour, dateMin, dateSec] = dateMatch;
|
|
144
|
+
const [yy, mm, dd, HH, MM, SS] = [
|
|
145
|
+
Number(dateYear),
|
|
146
|
+
Number(dateMonth) - 1,
|
|
147
|
+
Number(dateDay),
|
|
148
|
+
Number(dateHour !== null && dateHour !== void 0 ? dateHour : 0),
|
|
149
|
+
Number(dateMin !== null && dateMin !== void 0 ? dateMin : 0),
|
|
150
|
+
Number(dateSec !== null && dateSec !== void 0 ? dateSec : 0),
|
|
151
|
+
];
|
|
152
|
+
const monthMaxDayAllowed = (0, utils_1.getMonthMaxDayAllowed)(mm, yy);
|
|
153
|
+
if (dd > monthMaxDayAllowed)
|
|
154
|
+
return transformStringValue(program, node);
|
|
155
|
+
const msValue = Date.UTC(yy, mm, dd, HH, MM, SS);
|
|
156
|
+
const dateValue = new Date(msValue);
|
|
157
|
+
if (!(0, utils_1.isValidDate)(dateValue))
|
|
158
|
+
return transformStringValue(program, node);
|
|
159
|
+
const value = dateValue.toISOString();
|
|
160
|
+
return createLiteralValue(node, 'date', value);
|
|
161
|
+
}
|
|
162
|
+
function transformStringValue(program, node) {
|
|
163
|
+
const value = (0, utils_1.getNodeValue)(program, node).slice(1, -1);
|
|
164
|
+
return createLiteralValue(node, 'string', value);
|
|
165
|
+
}
|
|
166
|
+
function transformNumberValue(program, node) {
|
|
167
|
+
const value = parseFloat((0, utils_1.getNodeValue)(program, node));
|
|
168
|
+
return createLiteralValue(node, 'number', value);
|
|
169
|
+
}
|
|
170
|
+
function transformBooleanValue(program, node) {
|
|
171
|
+
const value = (0, utils_1.getNodeValue)(program, node) === 'true';
|
|
172
|
+
return createLiteralValue(node, 'boolean', value);
|
|
173
|
+
}
|
|
174
|
+
function transformNullValue(_program, node) {
|
|
175
|
+
return createLiteralValue(node, 'null', null);
|
|
176
|
+
}
|
|
177
|
+
function transformArrayValue(program, node, errorList, context) {
|
|
178
|
+
const childValue = node.getChildren('Value');
|
|
179
|
+
const value = childValue
|
|
180
|
+
? childValue.map((childNode) => {
|
|
181
|
+
const nodeResult = transformNode(program, childNode, errorList, context);
|
|
182
|
+
return (nodeResult !== null && nodeResult !== void 0 ? nodeResult : createUnknownValue(childNode, (0, utils_1.getNodeValue)(program, childNode)));
|
|
183
|
+
})
|
|
184
|
+
: [];
|
|
185
|
+
return createLiteralValue(node, 'array', value);
|
|
186
|
+
}
|
|
187
|
+
function transformVariableValue(program, node, context) {
|
|
188
|
+
let variableValue = (0, utils_1.getNodeValue)(program, node).slice(1, -1);
|
|
189
|
+
const variableContext = (0, utils_1.getVariableContext)(variableValue, context);
|
|
190
|
+
const variableType = (0, utils_1.getVariableType)(variableContext);
|
|
191
|
+
if (variableType === 'Token')
|
|
192
|
+
variableValue = `{{${variableValue}}}`;
|
|
193
|
+
return {
|
|
194
|
+
type: variableType,
|
|
195
|
+
value: variableValue,
|
|
196
|
+
context: variableContext,
|
|
197
|
+
from: node.from,
|
|
198
|
+
to: node.to,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=json-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-parser.js","sourceRoot":"","sources":["../../../src/parser/json-parser.ts"],"names":[],"mappings":";;;AAaA,4CAAyC;AACzC,oCAMkB;AAClB,mDAA4D;AAC5D,sCAImB;AACnB,4CAA6C;AAE7C,MAAM,cAAc,GAAG,OAAO,CAAC;AAC/B,MAAM,SAAS,GAAG,WAAW,CAAC;AAE9B,SAAgB,YAAY,CACxB,OAAe,EACf,SAAqB,EACrB,OAAwB;IAExB,IAAI,CAAC,SAAS;QAAE,OAAO;IACvB,MAAM,YAAY,GAAG,IAAA,yCAAyB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACnE,OAAO;QACH,IAAI,EAAE,qBAAS,C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yntaxErrors = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
function calculateNodeSyntaxErrors(program, node) {
|
|
8
|
+
const text = (0, utils_1.getNodeValue)(program, node);
|
|
9
|
+
if (text === '')
|
|
10
|
+
return [];
|
|
11
|
+
const errorList = [];
|
|
12
|
+
node.cursor().iterate((n) => {
|
|
13
|
+
if (n.type.isError) {
|
|
14
|
+
const textError = (0, utils_1.getNodeValue)(program, n);
|
|
15
|
+
if (textError !== '') {
|
|
16
|
+
errorList.push(new errors_1.UnknownTokenError({
|
|
17
|
+
type: constants_1.AST_TYPES.unknown,
|
|
18
|
+
from: n.from,
|
|
19
|
+
to: n.to,
|
|
20
|
+
text: textError,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return errorList;
|
|
26
|
+
}
|
|
27
|
+
exports.calculateNodeSyntaxErrors = calculateNodeSyntaxErrors;
|
|
28
|
+
//# sourceMappingURL=syntax-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-errors.js","sourceRoot":"","sources":["../../../src/parser/syntax-errors.ts"],"names":[],"mappings":";;;AACA,sCAAyD;AACzD,oCAAwC;AACxC,4CAAyC;AAEzC,SAAgB,yBAAyB,CACrC,OAAe,EACf,IAAgB;IAEhB,MAAM,IAAI,GAAG,IAAA,oBAAY,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzC,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAE3B,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACxB,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE;YAChB,MAAM,SAAS,GAAG,IAAA,oBAAY,EAAC,OAAO,EAAE,CAAe,CAAC,CAAC;YACzD,IAAI,SAAS,KAAK,EAAE,EAAE;gBAClB,SAAS,CAAC,IAAI,CACV,IAAI,0BAAiB,CAAC;oBAClB,IAAI,EAAE,qBAAS,CAAC,OAAO;oBACvB,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,IAAI,EAAE,SAAS;iBAClB,CAAC,CACL,CAAC;aACL;SACJ;IACL,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACrB,CAAC;AAxBD,8DAwBC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ENGINES } from '../constants';
|
|
2
|
+
import { ProcessNodeResult, VariableAST, FormulaContext } from '../constants/interfaces';
|
|
3
|
+
export declare function columnTranspilation(engine: ENGINES, { value, context }: VariableAST, globalContext?: FormulaContext): ProcessNodeResult;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.columnTranspilation = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const constants_2 = require("../constants");
|
|
6
|
+
function columnTranspilation(engine, { value, context }, globalContext) {
|
|
7
|
+
if (!context || !context.replacement)
|
|
8
|
+
return { value };
|
|
9
|
+
const columnForEngine = {
|
|
10
|
+
[constants_1.ENGINES.ELASTICSEARCH]: elasticsearch,
|
|
11
|
+
[constants_1.ENGINES.SNOWFLAKE]: sql,
|
|
12
|
+
[constants_1.ENGINES.REDSHIFT]: sql,
|
|
13
|
+
};
|
|
14
|
+
const result = columnForEngine[engine](context, globalContext);
|
|
15
|
+
return { value: result, dataType: context.type };
|
|
16
|
+
}
|
|
17
|
+
exports.columnTranspilation = columnTranspilation;
|
|
18
|
+
function elasticsearch(context, globalContext) {
|
|
19
|
+
const value = `doc["${context.replacement}"]`;
|
|
20
|
+
if ((context === null || context === void 0 ? void 0 : context.type) === 'date' && (globalContext === null || globalContext === void 0 ? void 0 : globalContext.timezone)) {
|
|
21
|
+
const offset = globalContext === null || globalContext === void 0 ? void 0 : globalContext.timezone.offset;
|
|
22
|
+
return `${constants_2.ELASTICSEARCH_SCRIPT_NAMES.setTimezone}(${value}, '${offset}')`;
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function sql(context) {
|
|
27
|
+
return `"${context.replacement}"`;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=columnTranspilation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columnTranspilation.js","sourceRoot":"","sources":["../../../src/transpiler/columnTranspilation.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AACvC,4CAA0D;AAQ1D,SAAgB,mBAAmB,CAC/B,MAAe,EACf,EAAE,KAAK,EAAE,OAAO,EAAe,EAC/B,aAA8B;IAE9B,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW;QAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACvD,MAAM,eAAe,GAAG;QACpB,CAAC,mBAAO,CAAC,aAAa,CAAC,EAAE,aAAa;QACtC,CAAC,mBAAO,CAAC,SAAS,CAAC,EAAE,GAAG;QACxB,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,GAAG;KAC1B,CAAC;IACF,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;AACrD,CAAC;AAbD,kDAaC;AAED,SAAS,aAAa,CAClB,OAAkC,EAClC,aAA8B;IAE9B,MAAM,KAAK,GAAG,QAAQ,OAAO,CAAC,WAAW,IAAI,CAAC;IAC9C,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,MAAM,KAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,QAAQ,CAAA,EAAE;QACrD,MAAM,MAAM,GAAG,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,QAAQ,CAAC,MAAM,CAAC;QAC9C,OAAO,GAAG,sCAA0B,CAAC,WAAW,IAAI,KAAK,MAAM,MAAM,IAAI,CAAC;KAC7E;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,GAAG,CAAC,OAAkC;IAC3C,OAAO,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ENGINES } from '../constants';
|
|
2
|
+
import { CommonAST, ProgramAST, BinaryExpressionAST, UnaryExpressionAST, FunctionCallAST, LiteralAST, FunctionDefinition, TranspilationResponse, ProcessNodeResult, VariableAST, FormulaContext } from '../constants/interfaces';
|
|
3
|
+
export declare class Transpiler {
|
|
4
|
+
private ast;
|
|
5
|
+
private readonly engine;
|
|
6
|
+
private readonly globalContext?;
|
|
7
|
+
private customFunctionList;
|
|
8
|
+
constructor(ast: ProgramAST, engine: ENGINES, globalContext?: FormulaContext | undefined);
|
|
9
|
+
get(): TranspilationResponse;
|
|
10
|
+
processNode(expression: CommonAST): ProcessNodeResult;
|
|
11
|
+
column(data: VariableAST): ProcessNodeResult;
|
|
12
|
+
literal({ value, dataType }: LiteralAST): ProcessNodeResult;
|
|
13
|
+
unaryExpression({ operator, right, }: UnaryExpressionAST): ProcessNodeResult;
|
|
14
|
+
binaryExpression({ left, operator, right, }: BinaryExpressionAST): ProcessNodeResult;
|
|
15
|
+
functionCall(node: FunctionCallAST): ProcessNodeResult;
|
|
16
|
+
executer(func: FunctionDefinition, args: Array<ProcessNodeResult>, node: FunctionCallAST): string;
|
|
17
|
+
}
|
|
18
|
+
export declare function TranspileAST(ast: ProgramAST, engine: ENGINES, context?: FormulaContext): TranspilationResponse;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranspileAST = exports.Transpiler = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const definitions_1 = require("../errors/definitions");
|
|
6
|
+
const functions_1 = require("../functions");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const validateFuncStructure_1 = require("./validateFuncStructure");
|
|
9
|
+
const columnTranspilation_1 = require("./columnTranspilation");
|
|
10
|
+
const unshiftCustomFunctions_1 = require("./unshiftCustomFunctions");
|
|
11
|
+
class Transpiler {
|
|
12
|
+
constructor(ast, engine, globalContext) {
|
|
13
|
+
this.ast = ast;
|
|
14
|
+
this.engine = engine;
|
|
15
|
+
this.globalContext = globalContext;
|
|
16
|
+
this.customFunctionList = new Set();
|
|
17
|
+
}
|
|
18
|
+
get() {
|
|
19
|
+
try {
|
|
20
|
+
const { body } = this.ast;
|
|
21
|
+
const result = body ? this.processNode(body) : undefined;
|
|
22
|
+
const expression = (0, unshiftCustomFunctions_1.unshiftCustomFunctions)(this.customFunctionList, result);
|
|
23
|
+
return {
|
|
24
|
+
valid: body !== undefined,
|
|
25
|
+
expression,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return {
|
|
30
|
+
valid: false,
|
|
31
|
+
errors: [error],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
processNode(expression) {
|
|
36
|
+
const { type } = expression !== null && expression !== void 0 ? expression : { type: constants_1.AST_TYPES.unknown };
|
|
37
|
+
const nodes = {
|
|
38
|
+
[constants_1.AST_TYPES.token]: this.literal,
|
|
39
|
+
[constants_1.AST_TYPES.literal]: this.literal,
|
|
40
|
+
[constants_1.AST_TYPES.column]: this.column,
|
|
41
|
+
[constants_1.AST_TYPES.unaryExpression]: this.unaryExpression,
|
|
42
|
+
[constants_1.AST_TYPES.binaryExpression]: this.binaryExpression,
|
|
43
|
+
[constants_1.AST_TYPES.functionCall]: this.functionCall,
|
|
44
|
+
};
|
|
45
|
+
if (!nodes[type]) {
|
|
46
|
+
throw new definitions_1.UnknownExpressionError(expression);
|
|
47
|
+
}
|
|
48
|
+
return nodes[type].call(this, expression);
|
|
49
|
+
}
|
|
50
|
+
column(data) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
if (((_a = data === null || data === void 0 ? void 0 : data.context) === null || _a === void 0 ? void 0 : _a.type) === 'date' && ((_b = this.globalContext) === null || _b === void 0 ? void 0 : _b.timezone)) {
|
|
53
|
+
const customFunction = (0, utils_1.customTimezone)(this.engine);
|
|
54
|
+
if (customFunction)
|
|
55
|
+
this.customFunctionList.add(customFunction);
|
|
56
|
+
}
|
|
57
|
+
return (0, columnTranspilation_1.columnTranspilation)(this.engine, data, this.globalContext);
|
|
58
|
+
}
|
|
59
|
+
literal({ value, dataType }) {
|
|
60
|
+
if (dataType === 'date')
|
|
61
|
+
value = (0, utils_1.customDateCast)(this.engine)(value);
|
|
62
|
+
if (dataType === 'string')
|
|
63
|
+
value = `'${value}'`;
|
|
64
|
+
return { value, dataType };
|
|
65
|
+
}
|
|
66
|
+
unaryExpression({ operator, right, }) {
|
|
67
|
+
const { value: rightResult } = this.processNode(right);
|
|
68
|
+
const value = `(${operator} ${rightResult})`;
|
|
69
|
+
return { value };
|
|
70
|
+
}
|
|
71
|
+
binaryExpression({ left, operator, right, }) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const { value: leftResult } = this.processNode(left);
|
|
74
|
+
const { value: rightResult } = this.processNode(right);
|
|
75
|
+
const value = `(${leftResult} ${(_b = (_a = constants_1.CustomOperators[this.engine]) === null || _a === void 0 ? void 0 : _a[operator]) !== null && _b !== void 0 ? _b : operator} ${rightResult})`;
|
|
76
|
+
return { value };
|
|
77
|
+
}
|
|
78
|
+
functionCall(node) {
|
|
79
|
+
const { name, arguments: args } = node;
|
|
80
|
+
const func = functions_1.functionList[name];
|
|
81
|
+
if (!func)
|
|
82
|
+
throw new definitions_1.UnknownFunctionError(node);
|
|
83
|
+
const customFunction = (0, utils_1.customFunction)(this.engine, name);
|
|
84
|
+
if (customFunction)
|
|
85
|
+
this.customFunctionList.add(customFunction);
|
|
86
|
+
const parameters = args.map((param) => this.processNode(param));
|
|
87
|
+
const value = this.executer(func, parameters, node);
|
|
88
|
+
return { value };
|
|
89
|
+
}
|
|
90
|
+
executer(func, args, node) {
|
|
91
|
+
(0, validateFuncStructure_1.validateFuncStructure)(node, func, args);
|
|
92
|
+
args = args.map((item) => item.value);
|
|
93
|
+
return func.transpiler[this.engine](...args);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Transpiler = Transpiler;
|
|
97
|
+
function TranspileAST(ast, engine, context) {
|
|
98
|
+
var _a, _b, _c, _d, _e;
|
|
99
|
+
const hasSyntaxErrors = ((_b = (_a = ast.errors) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
100
|
+
const transpiler = new Transpiler(ast, engine, context);
|
|
101
|
+
const transpileResult = transpiler.get();
|
|
102
|
+
return Object.assign(Object.assign({}, transpileResult), { valid: transpileResult.valid && !hasSyntaxErrors, errors: transpileResult.errors || (ast.errors && ((_c = ast.errors) === null || _c === void 0 ? void 0 : _c.length) > 0)
|
|
103
|
+
? [...((_d = transpileResult.errors) !== null && _d !== void 0 ? _d : []), ...((_e = ast.errors) !== null && _e !== void 0 ? _e : [])]
|
|
104
|
+
: undefined });
|
|
105
|
+
}
|
|
106
|
+
exports.TranspileAST = TranspileAST;
|
|
107
|
+
//# sourceMappingURL=index.js.map
|