[Kde-bindings] KDE/kdebindings/generator/parser
Richard Dale
richard.j.dale at gmail.com
Sat Oct 9 12:51:45 UTC 2010
SVN commit 1184213 by rdale:
* Attempt to make it easier to track down parse errors in smokegen
by giving the text of the current line as part of the error.
* The source filename and line number would be nice too, but it isn't
obvious how to do that.
CCMAIL: kde-bindings at kde.org
M +1 -2 parser.cpp
M +20 -0 rpp/chartools.cpp
M +6 -0 rpp/chartools.h
--- trunk/KDE/kdebindings/generator/parser/parser.cpp #1184212:1184213
@@ -369,9 +369,8 @@
Problem *p = new Problem;
p->file = session->url().str();
p->position = position;
- p->description = msg;
+ p->description = msg + " : " + QString::fromUtf8(lineFromContents(session->contents(), p->position.line));
p->source = Problem::Source_Parser;
-
control->reportProblem(p);
}
else if (_M_hold_errors)
--- trunk/KDE/kdebindings/generator/parser/rpp/chartools.cpp #1184212:1184213
@@ -36,6 +36,26 @@
return ret;
}
+#include <stdio.h>
+
+QByteArray lineFromContents(const uint* contents, int lineNumber) {
+ int a1 = 0;
+ int lineCount = 0;
+ while (lineCount < lineNumber) {
+ if (isNewline(contents[a1])) {
+ lineCount++;
+ }
+ a1++;
+ }
+
+ int a2 = a1;
+ while (!isNewline(contents[a2])) {
+ a2++;
+ }
+
+ return stringFromContents(contents + a1, a2 - a1);
+}
+
QByteArray stringFromContents(const uint* contents, int count) {
QByteArray ret;
for(int a = 0; a < count; ++a) {
--- trunk/KDE/kdebindings/generator/parser/rpp/chartools.h #1184212:1184213
@@ -72,12 +72,18 @@
return isCharacter(c) && QChar(characterFromIndex(c)).isNumber();
}
+inline bool isNewline(unsigned int c) {
+ return isCharacter(c) && QChar(characterFromIndex(c)).toLatin1() == '\n';
+}
+
///Opposite of convertFromByteArray
CPPPARSER_EXPORT QByteArray stringFromContents(const PreprocessedContents& contents, int offset = 0, int count = 0);
///Opposite of convertFromByteArray
CPPPARSER_EXPORT QByteArray stringFromContents(const uint* contents, int count);
+CPPPARSER_EXPORT QByteArray lineFromContents(const uint* contents, int lineNumber);
+
///Returns a string that has a gap inserted between the tokens(for debugging)
CPPPARSER_EXPORT QByteArray stringFromContentsWithGaps(const PreprocessedContents& contents, int offset = 0, int count = 0);
More information about the Kde-bindings
mailing list