Highlighter für Kommentare hinzugefügt.
This commit is contained in:
@@ -373,6 +373,62 @@ void PhpHighlighter::highlightPhpRange(const QString &text, int start, int lengt
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// /* */ Block-Kommentare innerhalb des PHP-Bereichs mehrzeilig behandeln.
|
||||
// Block-Zustand 3 = wir sind mitten in einem /* ... */ PHP-Kommentar.
|
||||
static const QRegularExpression blockOpen(R"(/\*)");
|
||||
static const QRegularExpression blockClose(R"(\*/)");
|
||||
|
||||
int searchFrom = 0;
|
||||
|
||||
// Waren wir bereits in einem Block-Kommentar?
|
||||
if (previousBlockState() == 3)
|
||||
{
|
||||
QRegularExpressionMatch closeMatch = blockClose.match(phpText, 0);
|
||||
if (closeMatch.hasMatch())
|
||||
{
|
||||
const int end = static_cast<int>(closeMatch.capturedStart())
|
||||
+ static_cast<int>(closeMatch.capturedLength());
|
||||
setFormat(start, end, m_phpCommentFormat);
|
||||
searchFrom = end;
|
||||
// Block-Kommentar geschlossen — Zustand wird weiter unten gesetzt
|
||||
}
|
||||
else
|
||||
{
|
||||
// Gesamter Bereich ist noch Kommentar
|
||||
setFormat(start, length, m_phpCommentFormat);
|
||||
setCurrentBlockState(3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Neue /* ... */ Kommentare innerhalb dieses PHP-Bereichs suchen
|
||||
while (searchFrom < phpText.length())
|
||||
{
|
||||
QRegularExpressionMatch openMatch = blockOpen.match(phpText, searchFrom);
|
||||
if (!openMatch.hasMatch())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
const int openPos = static_cast<int>(openMatch.capturedStart());
|
||||
QRegularExpressionMatch closeMatch = blockClose.match(phpText, openPos + 2);
|
||||
|
||||
if (closeMatch.hasMatch())
|
||||
{
|
||||
const int closeEnd = static_cast<int>(closeMatch.capturedStart())
|
||||
+ static_cast<int>(closeMatch.capturedLength());
|
||||
setFormat(start + openPos, closeEnd - openPos, m_phpCommentFormat);
|
||||
searchFrom = closeEnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Kein schließendes */ gefunden — geht über Zeilenende
|
||||
setFormat(start + openPos, length - openPos, m_phpCommentFormat);
|
||||
setCurrentBlockState(3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhpHighlighter::highlightBlock(const QString &text)
|
||||
@@ -380,8 +436,10 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
||||
// Zuerst HTML-Basis-Regeln auf den gesamten Text anwenden
|
||||
SyntaxHighlighter::highlightBlock(text);
|
||||
|
||||
// Dann PHP-Blöcke <?php ... ?> und <?= ... ?> finden und überschreiben
|
||||
// Block-Zustände: 0 = HTML, 2 = innerhalb PHP-Block
|
||||
// Block-Zustände:
|
||||
// 0 = HTML-Modus
|
||||
// 2 = innerhalb PHP-Block (kein /* */ Kommentar)
|
||||
// 3 = innerhalb PHP /* */ Block-Kommentar
|
||||
setCurrentBlockState(0);
|
||||
|
||||
static const QRegularExpression phpOpen(R"(<\?(?:php|=)?\s?)",
|
||||
@@ -390,9 +448,9 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
||||
|
||||
int pos = 0;
|
||||
|
||||
if (previousBlockState() == 2)
|
||||
if (previousBlockState() == 2 || previousBlockState() == 3)
|
||||
{
|
||||
// Wir befinden uns bereits in einem PHP-Block
|
||||
// Wir befinden uns bereits in einem PHP-Block (ggf. in einem Kommentar)
|
||||
QRegularExpressionMatch closeMatch = phpClose.match(text, 0);
|
||||
if (closeMatch.hasMatch())
|
||||
{
|
||||
@@ -408,7 +466,12 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
||||
else
|
||||
{
|
||||
highlightPhpRange(text, 0, text.length());
|
||||
setCurrentBlockState(2);
|
||||
// highlightPhpRange setzt den Zustand auf 3 falls nötig,
|
||||
// sonst behalten wir 2 (offener PHP-Block ohne Kommentar)
|
||||
if (currentBlockState() != 3)
|
||||
{
|
||||
setCurrentBlockState(2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -424,7 +487,6 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
||||
const int openStart = static_cast<int>(openMatch.capturedStart());
|
||||
const int openEnd = openStart + static_cast<int>(openMatch.capturedLength());
|
||||
|
||||
// <?php-Tag selbst einfärben
|
||||
setFormat(openStart, static_cast<int>(openMatch.capturedLength()), m_phpTagFormat);
|
||||
|
||||
QRegularExpressionMatch closeMatch = phpClose.match(text, openEnd);
|
||||
@@ -441,9 +503,11 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
||||
}
|
||||
else
|
||||
{
|
||||
// PHP-Block geht über Zeilenende hinaus
|
||||
highlightPhpRange(text, openEnd, text.length() - openEnd);
|
||||
setCurrentBlockState(2);
|
||||
if (currentBlockState() != 3)
|
||||
{
|
||||
setCurrentBlockState(2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user