Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. JavaScript parser
QtWS25 Last Chance

JavaScript parser

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 2.4k Views
  • 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 Offline
    A Offline
    Archie888
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • SGaistS SGaist

        Hi,

        Do you mean something like esprima ?

        A Offline
        A Offline
        Archie888
        wrote on last edited by Archie888
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          1
          • A Offline
            A Offline
            Archie888
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Archie888
              wrote on last edited by Archie888
              #6

              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
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved