
Filtrex: A simple JavaScript filter expression compiler - joewalnes
https://github.com/joewalnes/filtrex
======
couchand
This is really slick. I wonder if it would be useful to build an object model
for the filters rather than directly concatenating the code. That would allow
for interesting inspection on the parsed expressions or transformation of
them. For instance, combining two filters should be just as easy as combining
two expressions.

    
    
        var expression = compileExpression('transactions <= 5 and abs(profit) > 20.5');
    

...should also be possible to write as this, to help DRY everything...

    
    
        var fewTransactions = compileExpression('transactions <= 5');
        var lotsOfProfit = compileExpression('abs(profit) > 20.5');
        var expression = fewTransactions.and(lotsOfProfit);
    

You might look into the Specification pattern [0] to handle the heavy lifting
in a simple way.

[0]:
[http://www.martinfowler.com/apsupp/spec.pdf](http://www.martinfowler.com/apsupp/spec.pdf)

------
michaelsbradley
It's less general purpose, but the polymer-expressions library is also worth a
look:

[https://github.com/Polymer/polymer-
expressions](https://github.com/Polymer/polymer-expressions)

------
mappu
Including all of jison?

I've implemented something similar several times in different ways now, and I
strongly recommend looking into the Precedence Climbing algorithm - you can
build something like this without the jison dependency in almost as few lines
as `filtrex.js` already is.

~~~
mappum
Your username...

------
SchizoDuckie
It looks brilliant, but the 128kb dependency kills it. You'd have to do _a
lot_ of these expressions to be able to validate the usage of yet another 128k
lib imo.

------
afternooner
I love this, but I think I'll wait until a few more people play around with
hacking it.

