Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw 'Invalid unary operator: ' + tree.operator;
}
// Binary Operators
if (tree.type === 'BinaryExpression') {
if (tree.operator in binaryOperators) {
usedTerms.binaryOperators.add(tree.operator);
return {['$' + binaryOperators[tree.operator]]: [parse(tree.left), parse(tree.right)]};
}
throw 'Invalid binary operator: ' + tree.operator;
}
throw 'Unknown syntax: ' + tree.type;
};
return {query: parse(jsep(text)), usedTerms};
}
function formulaToExpression(input) {
if (input === '' || input === undefined) {
return;
}
if (typeof input !== 'string') {
throw new Error('input must be a string');
}
// Change hyphens in expression operators to underscores. This allows JS
// parsing to work, but then needs to be reversed above.
input = input.replace(/([a-z]+)-([a-z]+)\(/, '$1_$2(');
let ast;
try {
ast = jsep(input);
} catch (syntaxError) {
throw handleSyntaxErrors(syntaxError, input);
}
const expression = astToExpression(ast);
return expression;
}
export function parseVizDefinition (str) {
prepareJsep();
const ast = jsep(cleanComments(str));
let vizSpec = { variables: {} };
if (ast.type === 'Compound') {
ast.body.map(node => parseVizNamedExpr(vizSpec, node));
} else {
parseVizNamedExpr(vizSpec, ast);
}
cleanJsep();
return vizSpec;
}
const parseTree = (target, scope)=> {
let cache = {
iterationObj: scope
}
function parseNode (node){
let result = null
each(ExpressionTypes, type=> {
if (node.type == type) {
result = EXP_HANDLER[type](parseNode, cache)(node, scope)
return false
}
})
return result
}
return parseNode(jsep(target))
}
export function parseVizExpression (str) {
prepareJsep();
const r = implicitCast(parseNode(jsep(str)));
cleanJsep();
return r;
}
function stringToAst(input) {
try {
return jsep(input);
} catch (e) {
throw handleSyntaxErrors(e);
}
}
export function parseVizDefinition (str) {
prepareJsep();
const ast = jsep(cleanComments(str));
let vizSpec = { variables: {} };
if (ast.type === 'Compound') {
ast.body.map(node => parseVizNamedExpr(vizSpec, node));
} else {
parseVizNamedExpr(vizSpec, ast);
}
cleanJsep();
return vizSpec;
}