Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
ce319fa6
Commit
ce319fa6
authored
Sep 14, 2022
by
Alain Laporte
Committed by
Christoph Cullmann
Sep 15, 2022
Browse files
php_parser: add trait support
parent
005b3ab4
Pipeline
#232702
passed with stage
in 8 minutes and 31 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
addons/symbolviewer/php_parser.cpp
View file @
ce319fa6
...
...
@@ -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
));
...
...
addons/symbolviewer/samples/testfile.php
View file @
ce319fa6
...
...
@@ -22,6 +22,10 @@ class classExtendClass1 extends class1 {
function
foo1_in_classExtendClass1
()
{
}
}
trait
trait1
{
function
foo1_in_trait1
()
{
}
}
class
classImplementInterface
implements
interface1
{
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment