metarhia / JSQL

JavaScript Query Language
https://metarhia.com
25 stars 1 forks source link

Find a way to get query AST #3

Open tshemsedinov opened 8 years ago

tshemsedinov commented 8 years ago

For interest of @metarhia/angeli Now we have query language as simple as JavaScript, example:

(person) => (
  person.name !== '' &&
  person.age > 18 &&
  person.city === 'Rome'
)

I also made an example of dynamic prototype building from metadata for positioning array processing as if they were objects in JSTP: https://github.com/metarhia/JSQL/blob/master/Examples/filterArray.js

Usage of this query is quite simple var res = data.filter(query);

But we need indexing, sharding and distributed execution in GlobalStorage, so I think we need to parse query into AST or get AST from V8 to programmatically analyze query structure before execution to find indexes for example or to separate execution into multiple servers. @DzyubSpirit may prepare some research, maybe @aqrln and @lundibundi or somebody from @metarhia/angeli may help.

DzyubSpirit commented 8 years ago

On site of one of ast-parsers there is ability to run test which parses JQuery, Angular and React libraries by different libraries. Speed test Triple test results: Test 1 Test 2 Test 3 Esprima, Acorn and Shift are much faster than others. Shift is the fastest. But I have found more links to Esprima in forums for some reason.

DzyubSpirit commented 8 years ago

Developers answer that that do not want to give API to AST. Answer 1 Answer 2 Main causes about this:

  1. AST in V8 not entirely represent source code because it is used in optimizing. It is not how it must be but how it is now.
  2. Developers do not want define contract for AST because they want it to be flexible. That allows them to change realization if it is needed.

On other hand SpiderMonkey has the parser API: Parser API documentation So it is real and it can be implemented if rewrite V8... But now it is better to use third-party libraries for parsing AST.