summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard van Velzen <rvanvelzen1@gmail.com>2023-02-21 16:05:13 +0100
committerGitHub <noreply@github.com>2023-02-21 16:05:13 +0100
commitb4e9027ec01939bbbb9953bf5dfbc3f1cbe81148 (patch)
tree472245746cde4fc61a9467432ca02fad8b4ef293
parent4cfd3fdf7e74d47124ca58ad39e89a00304a28ad (diff)
downloadpygments-git-b4e9027ec01939bbbb9953bf5dfbc3f1cbe81148.tar.gz
Support PHP attributes (#2347)
-rw-r--r--pygments/lexers/php.py1
-rw-r--r--tests/examplefiles/php/test.php4
-rw-r--r--tests/examplefiles/php/test.php.output18
3 files changed, 23 insertions, 0 deletions
diff --git a/pygments/lexers/php.py b/pygments/lexers/php.py
index 61d552ab..c99daa4d 100644
--- a/pygments/lexers/php.py
+++ b/pygments/lexers/php.py
@@ -192,6 +192,7 @@ class PhpLexer(RegexLexer):
bygroups(String, String, String.Delimiter, String, String.Delimiter,
Punctuation, Text)),
(r'\s+', Text),
+ (r'#\[', Punctuation),
(r'#.*?\n', Comment.Single),
(r'//.*?\n', Comment.Single),
# put the empty comment here, it is otherwise seen as
diff --git a/tests/examplefiles/php/test.php b/tests/examplefiles/php/test.php
index e8efdc6a..0076e04b 100644
--- a/tests/examplefiles/php/test.php
+++ b/tests/examplefiles/php/test.php
@@ -542,3 +542,7 @@ some_delimiter;
?>
+<?php
+#[Attribute]
+class Extra {}
+?> \ No newline at end of file
diff --git a/tests/examplefiles/php/test.php.output b/tests/examplefiles/php/test.php.output
index 7d63ddb3..8337da7b 100644
--- a/tests/examplefiles/php/test.php.output
+++ b/tests/examplefiles/php/test.php.output
@@ -3101,4 +3101,22 @@
'\n' Text
'?>' Comment.Preproc
+'\n\n' Other
+
+'<?php' Comment.Preproc
+'\n' Text
+
+'#[' Punctuation
+'Attribute' Name.Other
+']' Punctuation
+'\n' Text
+
+'class' Keyword
+' ' Text
+'Extra' Name.Class
+' ' Text
+'{}' Punctuation
+'\n' Text
+
+'?>' Comment.Preproc
'\n' Other