# http://www.json.org/
# http://www.asciitable.com/
@{%
const moo = require('moo')
let lexer = moo.compile({
space: {match: /\s+/, lineBreaks: true},
number: /-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\b/,
string: /"(?:\\["bfnrt\/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/,
key: /[a-zA-Z-_]+/,
comparator: /=|<|<=|>=|>|!=/,
})
%}
@lexer lexer
start -> condition {% d => { return d[0]} %}
operator -> "AND" {% d => { return d[0].value} %}
| "OR" {% d => { return d[0].value} %}
comparator -> %comparator {% d => { return d[0].value} %}
condition -> _ expression (_ operator _ expression ):* _ {% extractCondition %}
expression -> IDENTIFIER _ comparator _ LITERAL {% function(d) { return [d[0], d[2], d[4]]; } %}
| "(" _ condition _ ")" {% function(d) { return [d[0], d[2], d[4]]; } %}
key -> %key {% function(d) { return d[0].value } %}
IDENTIFIER -> key {% id %}
number -> %number {% function(d) { return parseFloat(d[0].value) } %}
string -> %string {% function(d) { return d[0].value } %}
LITERAL -> number {% id %}
| string {% id %}
| [a-zA-Z-_] {% function(d) { return d[0].value } %}
_ -> null | %space {% function(d) { return null; } %}
@{%
function extractCondition(d){
console.log("@@@@@@@@@@@@",d)
let output = [d[1]];
for (let i in d[2]) {
output.push(d[2][i][1]);
output.push(d[2][i][3]);
}
return output;
}
%}