diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-04-30 14:26:22 (GMT) |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-04-30 14:26:22 (GMT) |
commit | 6091b55ef4da3459ca3dd9d92e41fc223cf06aaf (patch) | |
tree | eaea7d2264527559867af03d5e837f64cb252021 /src | |
parent | 052e6a8e82b707749be2ecbad1af60effecefebb (diff) | |
download | Qt-6091b55ef4da3459ca3dd9d92e41fc223cf06aaf.zip Qt-6091b55ef4da3459ca3dd9d92e41fc223cf06aaf.tar.gz Qt-6091b55ef4da3459ca3dd9d92e41fc223cf06aaf.tar.bz2 |
Report the syntax errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index adc30dd..61cb2ee 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -547,7 +547,9 @@ bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url) } const QString fileName = url.toString(); - const QString code = QString::fromUtf8(data); // ### FIXME + + QTextStream stream(data, QIODevice::ReadOnly); + const QString code = stream.readAll(); JavaScriptParser parser; JavaScriptEnginePrivate driver; @@ -562,6 +564,41 @@ bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url) if (! parser.parse(&driver)) { _error = parser.errorMessage(); _errorLine = parser.errorLineNumber(); + + const QStringList lines = code.split(QLatin1Char('\n')); + + foreach (const JavaScriptParser::DiagnosticMessage &m, parser.diagnosticMessages()) { + + if (m.isWarning()) + continue; + + qWarning().nospace() << qPrintable(fileName) << ":" + << m.line << ":" + << m.column << ": " + << "error: " + << qPrintable(m.message); + + const QString textLine = lines.at(m.line - 1); + + qWarning() << qPrintable(textLine); + + int column = qMax(0, m.column - 1); + column = qMin(column, textLine.length()); // paranoia check + + QByteArray ind; + ind.reserve(column); + + for (int i = 0; i < column; ++i) { + const QChar ch = textLine.at(i); + if (ch.isSpace()) + ind.append(ch.unicode()); + else + ind.append(' '); + } + ind.append('^'); + qWarning() << ind.constData(); + } + return false; } |