JavaScript parser
-
wrote on 19 Apr 2016, 19:00 last edited by
Hi,
I would be interested in somehow getting an AST for a QML JS function, is there anything in the Qt stack that I could use for that?
Any tips for this outside Qt? I see there are some open-source parsers for JS written in JS, I might try some of those if necessary.
Cheers,
-A888 -
Hi,
Do you mean something like esprima ?
-
wrote on 20 Apr 2016, 11:47 last edited by Archie888
@SGaist Thanks for the reply. Yes, that seems good by a glance, I am wondering if it would be possible to perhaps use this or some other open source / free JavaScript parser either as external library, or as imported C++/JS source code in a Qt project? This is just a quick question if you or someone would have a clue right away, of course I'll need to dive into the topic myself.
Also I am wondering if it is really so that no tool in the Qt stack really produces an AST for JS or QML+JS? If I have understood correctly it might be indeed so that this stuff is generated straight into bytecode instructions or so on.
-
You have a starting point here for the integration of JavaScript in a QML application.
AFAIK, no. QML is backed by a dedicated engine. You can see this in the qtdeclarative module.
-
wrote on 25 Apr 2016, 00:16 last edited by
I am currently using Esprima, running on Node.js, via XmlHttpRequest. Was easy to setup.
-
wrote on 25 Apr 2016, 19:14 last edited by Archie888
Found a "hack" to integrate esprima to the build somewhat easily: By using QML WebView that loads a resource-included html page that includes the resource-included esprima.js file, and has some custom js functions to utilize it. The "experimental" features of WebView can be used to communicate with the js functions of the page -- or directly with esprima of course.
Simply importing esprima.js to a QML file does not work on Qt 5.4 (not sure about later versions), as there seems to be some problems with the parsing. It seems, however, that the WV engine can utilize it, I think it uses V8 (likely does, as it is based on the Chromium project, if I have understood correctly).
About the WV experimental features: http://stackoverflow.com/questions/24797813/getting-text-from-qt-webview-using-javascript
Also, as a curiosity, I am using the esprima.js file that is fetched when you install the esprima module to a Node.js project with npm. This file is not present in this form in the Git repository.
1/6