causaly-parser
Advanced tools
Comparing version 0.1.0 to 0.2.0
'use strict'; | ||
var context = (function () { | ||
var parser = (function () { | ||
function peg$subclass(child, parent) { | ||
@@ -760,2 +760,52 @@ function ctor() { | ||
var AND = 'AND'; | ||
var OR = 'OR'; | ||
var NOT = 'NOT'; | ||
var operators = Object.freeze({ | ||
AND: AND, | ||
OR: OR, | ||
NOT: NOT | ||
}); | ||
function compile(ast, parentOperator) { | ||
if (!Array.isArray(ast)) { | ||
return ast; | ||
} | ||
var operator = operators[ast[0]]; // eslint-disable-line import/namespace | ||
var expr = ast.slice(operator ? 1 : 0).reduce(function (buf, e, i, arr) { | ||
if (operator === NOT) { | ||
buf += `${operator} `; | ||
} | ||
if (Array.isArray(e)) { | ||
buf += compile(e, operator); | ||
} else { | ||
buf += e; | ||
} | ||
if (i !== arr.length - 1 && operator !== NOT) { | ||
buf += ` ${operator} `; | ||
} | ||
return buf; | ||
}, ''); | ||
if (parentOperator && operator !== NOT) { | ||
return `(${expr})`; | ||
} | ||
return expr; | ||
} | ||
var context = { | ||
parse: parser.parse, | ||
compile, | ||
operators | ||
}; | ||
var index = { | ||
@@ -762,0 +812,0 @@ context |
{ | ||
"name": "causaly-parser", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Set of parsers for the causaly query language", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
20602
671