Expressionist
Generate your own DSLs using native Javascript syntax. It lets you do cool stuff like delay the execution of a bunch of methods until the methods have been defined. This makes it easy to pass expressions around and let various adapters decide how they want to execute the expression.
Expressionist lets you programmatically generate expression trees in Node.js and then evaluate it after you have defined operation mapppings.
Work in progress.
Install
npm install expressionist
Usage
var WhereExpression = 'or' 'and' 'eql' 'notEql' 'in'; var _ = WhereExpressionstart; var res = ; var pretty = res; console; /* Outputs: { or: [ { eql: [ 'country', 'Canada' ] }, { and: [ { eql: [ 'country', 'USA' ] }, { notEql: [ 'job', 'spy' ] }, { notEql: [ 'company', 'nsa' ] } ] } ] } */ var map = { return ' (' + operands + ') '; } { return ' (' + operands + ') '; } { return operands0 + ' = "' + operands1 + '"'; } { return operands0 + ' != "' + operands1 + '"'; }; var res = expr; console; /*Outpus: (country = "Canada" OR (country = "USA" AND job != "spy" AND company != "nsa") )*/
Roadmap
- Syntax sugar.
- Operator precedence.
- Browser friendly build.
- Support this:
var MathExpr = { return l === right; } { return l > r; };// build expression (...) and thenvar result = expr;
- Nicer stringified representations and ability to transform to different representations.