Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved JavaScript parser

    QML and Qt Quick
    2
    6
    1946
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Archie888 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

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Do you mean something like esprima ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply Reply Quote 1
        • A
          Archie888 @SGaist 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.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 1
            • A
              Archie888 last edited by

              I am currently using Esprima, running on Node.js, via XmlHttpRequest. Was easy to setup.

              1 Reply Last reply Reply Quote 0
              • A
                Archie888 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 Reply Last reply Reply Quote 0
                • First post
                  Last post