funql

FUNctional Query Language

funql

FUNctional Query Language

Funql refers to two things:

  1. A minimalist query language that happens to be a superset of JSON.
  2. This module which can be used to parse funql syntax and compile that syntax into various other things.

For the remainder of this document, "funql" will refer to this module, and "funql syntax" will refer to the query language.

npm install funql

component install jdeal/funql

var funql = require('funql');
 
var ast = funql.parse("foo(bar)");
var funql = require('funql');
 
var jsCompile = funql.compiler({
  call_iffunction (nodecompile) {
    var args = node.nodes[1].nodes;
    var result = 'if (' + compile(args[0]) + ') {' + compile(args[1]) + '}';
    if (args[2]) {
      result += ' else {' + compile(args[2]) + '}';
    }
    return result;
  },
  namefunction (nodecompile) {
    return node.value;
  }
});
 
var jsCode = jsCompile("if(x,y,z)");
 
// jsCode: if (x) {y} else {z}