diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-01-17 14:28:09 +0100 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2020-01-30 08:24:40 +0100 |
commit | e080f48f905be597b1a645f1641b2b06553df6a2 (patch) | |
tree | eef0b5d503cf94ed217eab5008dff076e8833113 /tools/qmlformat/main.cpp | |
parent | 78a69fa05e3b2af6ed640692d81e2b1c355fe525 (diff) |
qmlformat: Support even more language features
Adds support (among other things) for:
- Pragmas
- Type annotations
- get / set properties
- Some previously unsupported escape sequences (\b,\v...)
- Calling methods on numeric literals
Also now checks whether the dumped code is still parsable.
Change-Id: Ia142a7c0b3e608115e79c1d98a62b682dce4eec9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools/qmlformat/main.cpp')
-rw-r--r-- | tools/qmlformat/main.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/tools/qmlformat/main.cpp b/tools/qmlformat/main.cpp index 036fbe9748..915389e3d2 100644 --- a/tools/qmlformat/main.cpp +++ b/tools/qmlformat/main.cpp @@ -101,11 +101,29 @@ bool parseFile(const QString& filename, bool inplace, bool verbose, bool sortImp DumpAstVisitor dump(parser.rootNode(), &comment); - if (dump.error()) { + QString dumpCode = dump.toString(); + + lexer.setCode(dumpCode, 1, true); + + bool dumpSuccess = parser.parse(); + + if (!dumpSuccess) { + if (verbose) { + const auto diagnosticMessages = parser.diagnosticMessages(); + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { + qWarning().noquote() << QString::fromLatin1("<formatted>:%2 : %3") + .arg(m.line).arg(m.message); + } + } + + qWarning().noquote() << "Failed to parse formatted code."; + } + + if (dump.error() || !dumpSuccess) { if (force) { qWarning().noquote() << "An error has occurred. The output may not be reliable."; } else { - qWarning().noquote() << "Am error has occurred. Aborting."; + qWarning().noquote() << "An error has occurred. Aborting."; return false; } } @@ -120,10 +138,10 @@ bool parseFile(const QString& filename, bool inplace, bool verbose, bool sortImp return false; } - file.write(dump.toString().toUtf8()); + file.write(dumpCode.toUtf8()); file.close(); } else { - QTextStream(stdout) << dump.toString(); + QTextStream(stdout) << dumpCode; } return true; |