Commit ce319fa6 authored by Alain Laporte's avatar Alain Laporte Committed by Christoph Cullmann
Browse files

php_parser: add trait support

parent 005b3ab4
Pipeline #232702 passed with stage
in 8 minutes and 31 seconds
......@@ -65,6 +65,8 @@ void KatePluginSymbolViewerView::parsePhpSymbols(void)
QRegularExpression::CaseInsensitiveOption);
// interfaces: https://www.php.net/manual/en/language.oop5.interfaces.php
static const QRegularExpression interfaceRegExp(QLatin1String("^interface\\s+([\\w_][\\w\\d_]*)"), QRegularExpression::CaseInsensitiveOption);
// traits: https://www.php.net/manual/en/language.oop5.traits.php
static const QRegularExpression traitRegExp(QLatin1String("^trait\\s+([\\w_][\\w\\d_]*)"), QRegularExpression::CaseInsensitiveOption);
// classes constants: https://www.php.net/manual/en/language.oop5.constants.php
static const QRegularExpression constantRegExp(QLatin1String("^const\\s+([\\w_][\\w\\d_]*)"), QRegularExpression::CaseInsensitiveOption);
// functions: https://www.php.net/manual/en/language.oop5.constants.php
......@@ -85,7 +87,7 @@ void KatePluginSymbolViewerView::parsePhpSymbols(void)
// remove useless comments: “public/* static */ function a($b, $c=null) /* test */” => “public function a($b, $c=null)”
static const QRegularExpression blockCommentInline(QLatin1String("/\\*.*\\*/"), QRegularExpression::InvertedGreedinessOption);
QRegularExpressionMatch match, matchClass, matchInterface, matchFunctionArg;
QRegularExpressionMatch match, matchClass, matchInterface, matchTrait, matchFunctionArg;
QRegularExpressionMatchIterator matchFunctionArgs;
bool inBlockComment = false;
......@@ -169,10 +171,11 @@ void KatePluginSymbolViewerView::parsePhpSymbols(void)
node->setText(1, QString::number(i, 10));
}
// detect classes, interfaces
// detect classes, interfaces and trait
matchClass = classRegExp.match(line);
matchInterface = interfaceRegExp.match(line);
if (matchClass.hasMatch() || matchInterface.hasMatch()) {
matchTrait = traitRegExp.match(line);
if (matchClass.hasMatch() || matchInterface.hasMatch() || matchTrait.hasMatch()) {
if (m_treeOn->isChecked()) {
node = new QTreeWidgetItem(classNode, lastClassNode);
if (m_expandOn->isChecked()) {
......@@ -197,13 +200,20 @@ void KatePluginSymbolViewerView::parsePhpSymbols(void)
} else {
node->setText(0, matchClass.captured(3));
}
} else {
} else if(matchInterface.hasMatch()) {
if (m_typesOn->isChecked()) {
nameWithTypes = matchInterface.captured(1) + QLatin1String(" [interface]");
node->setText(0, nameWithTypes);
} else {
node->setText(0, matchInterface.captured(1));
}
} else {
if (m_typesOn->isChecked()) {
nameWithTypes = matchTrait.captured(1) + QLatin1String(" [trait]");
node->setText(0, nameWithTypes);
} else {
node->setText(0, matchTrait.captured(1));
}
}
node->setIcon(0, m_icon_class);
node->setText(1, QString::number(i, 10));
......
......@@ -22,6 +22,10 @@ class classExtendClass1 extends class1 {
function foo1_in_classExtendClass1() { }
}
trait trait1 {
function foo1_in_trait1() { }
}
class classImplementInterface implements interface1 {
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment