diff --git a/autotests/folding/test.c.fold b/autotests/folding/test.c.fold --- a/autotests/folding/test.c.fold +++ b/autotests/folding/test.c.fold @@ -54,3 +54,15 @@ */ #endif + +/* + * Empty lines after a line continuation character (see bug #405903) + */ +#define one \ +two \ + +int i = 0; // this should not be highlighted as a macro +char* str = "string \ + + +int i = 0; // this should not be highlighted as a string diff --git a/autotests/html/test.c.html b/autotests/html/test.c.html --- a/autotests/html/test.c.html +++ b/autotests/html/test.c.html @@ -60,4 +60,16 @@ */ #endif + +/* + * Empty lines after a line continuation character (see bug #405903) + */ +#define one \ +two \ + +int i = 0; // this should not be highlighted as a macro +char* str = "string \ + + +int i = 0; // this should not be highlighted as a string diff --git a/autotests/input/test.c b/autotests/input/test.c --- a/autotests/input/test.c +++ b/autotests/input/test.c @@ -54,3 +54,15 @@ */ #endif + +/* + * Empty lines after a line continuation character (see bug #405903) + */ +#define one \ +two \ + +int i = 0; // this should not be highlighted as a macro +char* str = "string \ + + +int i = 0; // this should not be highlighted as a string diff --git a/autotests/reference/test.c.ref b/autotests/reference/test.c.ref --- a/autotests/reference/test.c.ref +++ b/autotests/reference/test.c.ref @@ -54,3 +54,15 @@ */

#endif
+
+/*
+ * Empty lines after a line continuation character (see bug #405903)
+ */
+#define one \
+two \
+
+int i = 0; // this should not be highlighted as a macro
+char* str = "string \
+
+
+int i = 0; // this should not be highlighted as a string
diff --git a/src/lib/abstracthighlighter.cpp b/src/lib/abstracthighlighter.cpp --- a/src/lib/abstracthighlighter.cpp +++ b/src/lib/abstracthighlighter.cpp @@ -141,10 +141,30 @@ if (text.isEmpty()) { /** * handle line empty context switches + * (and line end context switches) * guard against endless loops * see https://phabricator.kde.org/D18509 */ int endlessLoopingCounter = 0; + + /** + * line end context switches when lineEmptyContext is #stay. + * This avoids skipping empty lines after a line continuation + * character (see bug 405903) + */ + while (stateData->topContext()->lineEmptyContext().isStay() && !stateData->topContext()->lineEndContext().isStay()) { + if (!d->switchContext(stateData, stateData->topContext()->lineEndContext(), QStringList())) + break; + + // guard against endless loops + ++endlessLoopingCounter; + if (endlessLoopingCounter > 1024) { + qCDebug(Log) << "Endless switch context transitions for line end context, aborting highlighting of line."; + break; + } + } + + endlessLoopingCounter = 0; while (!stateData->topContext()->lineEmptyContext().isStay()) { if (!d->switchContext(stateData, stateData->topContext()->lineEmptyContext(), QStringList())) break; diff --git a/src/lib/state_p.h b/src/lib/state_p.h --- a/src/lib/state_p.h +++ b/src/lib/state_p.h @@ -64,6 +64,11 @@ Context* topContext() const; const QStringList &topCaptures() const; + /* + * if the previous line has a line continuation character + */ + bool lineContinuation = false; + private: /** * weak reference to the used definition to filter out invalid states