From e869b891c0f397f1d4559b6766d3afcd5efe09c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 25 Dec 2016 15:36:14 +0300 Subject: [PATCH] qmlweb_parse: support QML pragma statements Those are added as the third element of the 'toplevel' node, for backwards compatibility. If there are no 'pragma' statements, the third element is omitted. Fixes: https://github.com/qmlweb/qmlweb-parser/issues/27 --- src/api.js | 22 +++++++++++++++++++--- tests/qml/Pragma.qml | 5 +++++ tests/qml/Pragma.qml.json | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/qml/Pragma.qml create mode 100644 tests/qml/Pragma.qml.json diff --git a/src/api.js b/src/api.js index 8c2a8ed..9f290a4 100644 --- a/src/api.js +++ b/src/api.js @@ -313,6 +313,13 @@ function qmlweb_parse($TEXT, document_type, exigent_mode) { return as("qmlpragma", pragma); } + function qmlpragma() { + next(); + var pragma = S.token.value; + next(); + return as("qmlpragma", pragma); + } + function qmlimport() { // todo next(); @@ -340,13 +347,22 @@ function qmlweb_parse($TEXT, document_type, exigent_mode) { function qmldocument() { var imports = []; - while (is("name", "import")) { - imports.push(qmlimport()); + var pragma = []; + while (true) { + if (is("name", "import")) { + imports.push(qmlimport()); + } else if (is("name", "pragma")) { + pragma.push(qmlpragma()); + } else { + break; + } } var root = qmlstatement(); if (!is("eof")) unexpected(); - return as("toplevel", imports, root); + return pragma.length > 0 ? + as("toplevel", imports, root, pragma) : + as("toplevel", imports, root); } function jsdocument() { diff --git a/tests/qml/Pragma.qml b/tests/qml/Pragma.qml new file mode 100644 index 0000000..6410d07 --- /dev/null +++ b/tests/qml/Pragma.qml @@ -0,0 +1,5 @@ +pragma Singleton +import QtQuick 2.0 + +Item { +} diff --git a/tests/qml/Pragma.qml.json b/tests/qml/Pragma.qml.json new file mode 100644 index 0000000..c877a76 --- /dev/null +++ b/tests/qml/Pragma.qml.json @@ -0,0 +1,24 @@ +[ + "toplevel", + [ + [ + "qmlimport", + "QtQuick", + 2, + "", + true + ] + ], + [ + "qmlelem", + "Item", + null, + [] + ], + [ + [ + "qmlpragma", + "Singleton" + ] + ] +] \ No newline at end of file