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.<p><pre><code> var expression = compileExpression('transactions <= 5 and abs(profit) > 20.5');
</code></pre>
...should also be possible to write as this, to help DRY everything...<p><pre><code> var fewTransactions = compileExpression('transactions <= 5');
var lotsOfProfit = compileExpression('abs(profit) > 20.5');
var expression = fewTransactions.and(lotsOfProfit);
</code></pre>
You might look into the Specification pattern [0] to handle the heavy lifting in a simple way.<p>[0]: <a href="http://www.martinfowler.com/apsupp/spec.pdf" rel="nofollow">http://www.martinfowler.com/apsupp/spec.pdf</a>