[Development] Toolability of mixing QML and JS

Thomas Hartmann Thomas.Hartmann at digia.com
Wed Jun 26 15:27:45 CEST 2013


Hi,

Am 26/06/2013 14:26, schrieb Rutledge Shawn:
>
> On 26 Jun 2013, at 12:00 PM, Thomas Hartmann wrote:
>
>>> - Editors: A lot of IDE's out there understand .js files. Writing a parser for only the declarative parts of QML is relatively easy. Writing a parser for .qml files that also understands all of JS, not so easy.
>>
>> We provide a QML parser that includes Java Script as open source. Anyone
>> who wants to parse QML is most likely to use this one and even if not he
>> has access to the complete grammar. So this is not really an issue.
>
> I see it as an issue if you had to write that parser.  No wonder it's out of sync with the actual language parser.  The one in declarative should have all the features that you need, with suitable (ideally even public) APIs to access those features, it should be in the declarative module, and there should be autotests to keep it consistent.  So the workflow for tooling should be that you use the declarative parser to get the AST, the tooling has the opportunity to modify the AST whenever the user does something, then you can send it on to the engine for rendering a preview, and you can also regenerate the source code by pretty-printing the AST.  That means the AST must be complete: it must include Javascript (even if they are only unmodifiable blobs) and comments, so that the pretty-printing will generate the same source code with only the changes the user wanted to make.  But for optimization purposes there could be a parameter to the parser to ignore the comments, becaus
 e tooli
ng needs them whereas the interpreter does not.
>

The problem with that approach is that an AST is read only by design. 
What you need for tooling that modifies QML is something like a DOM.

In the early days there was a QmlDom class if I remember correctly, but 
it was not properly maintained and did not have the required features.

In the Qt Quick Designer we have a DOM like structure that is slightly 
more abstract than an AST. We called it just "model" and it can modify 
QML code by using a rewriter and it can instantiate the corresponding 
objects using the qml(2)puppet.

Kind Regards,
Thomas Hartmann



More information about the Development mailing list