我需要对QML格式文件(wiki)进行一些静态分析,但我找不到任何解析器。我看到的唯一方法是重用Qt 声明模块的源代码或编写我自己的解析器。我在网上找不到任何东西。谁能指点我一些工具,转换器到 XML 或 Perl/Python 模块来轻松解析 QML 文件中的元素?
非常感谢你的帮助!
qt-declarative中的解析器在 src/qml/qml/parser 中,其中很大一部分是使用 qlalr 生成的(与上一个链接相同,但使用 qlalr 而不是 qtdeclarative)。您可能还想查看qt-creator src/libs/qmljs/parser 中使用的解析器,它是从 qt-declarative 派生的。
You could look at the source code of the QML Viewer that comes with the SDK. The source code is available on Gitorious. QML Viewer code is in C++ not Python nor Perl.
Another possible solution, to use Python with no dependencies with Qt, is to use a standard Javascript parser and modify it so it can understand QML. From the wiki link you provided :
Because QML and JavaScript are very similar almost all code editors supporting JavaScript will do the job.
I found pynarcissus which is a Javascript interpreter in Python. May be you could modify it slightly so it can interprete corretly QML files?