@qrvey/formula-lang v2.0.0
Qrvey Formula Language
Usage
Transpile function
import { ENGINES, Transpile } from "@qrvey/formula-lang";
const program = "MID(MID(\"This is a test\", 1, 5), 1, 2)"
const transpiled = Transpile(program, ENGINES.ELASTICSEARCH)
console.log(transpiled)
the output will be
'This is a test'.substring(1, 5).substring(1, 2)
TranspileAST function
import { ENGINES, TranspileAST } from "@qrvey/formula-lang";
const ast = {
"type": "Program",
"exp": "1 + 2",
"lang": "QrveyLang",
"version": "0.0.0",
"body": {
"operator": "+",
"type": "BinaryExpression",
"left": {
"type": "Literal",
"dataType": "number",
"value": 1
},
"right": {
"type": "Literal",
"dataType": "number",
"value": 2
}
}
}
const transpiled = TranspileAST(ast, ENGINES.ELASTICSEARCH)
console.log(transpiled)
the output will be
(1 + 2)
codemirror editor
import { EditorState } from "@codemirror/state";
import { basicSetup } from "codemirror";
import { FormulaHighlight, calculateAST } from "@qrvey/formula-lang"
// set the editor state with the QFormula plugin. This adds the support for
this._state = EditorState.create({
doc: 'Test formula',
extensions: [
basicSetup,
FormulaHighlight(),
...
]
})
// On every edit update you can calculate the AST
private dispatchTextUpdate(state: EditorState) {
const tree = (state as any).tree;
const text = ((state.doc as any).text as Array<string>).join('\n');
const ast = calculateAST(text, tree.topNode);
// dispatch event after return
return { text, ast }
}
9 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago