Skip to content

Commit

Permalink
Fix lexing PHP anonymous classes with no parameters (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen committed Feb 28, 2023
1 parent 8035782 commit 5b96a7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions pygments/lexers/php.py
Expand Up @@ -205,6 +205,7 @@ class PhpLexer(RegexLexer):
(r'[~!%^&*+=|:.<>/@-]+', Operator),
(r'\?', Operator), # don't add to the charclass above!
(r'[\[\]{}();,]+', Punctuation),
(r'(new)(\s+)(class)\b', bygroups(Keyword, Text, Keyword)),
(r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
(r'(function)(\s*)(?=\()', bygroups(Keyword, Text)),
(r'(function)(\s+)(&?)(\s*)',
Expand Down
28 changes: 28 additions & 0 deletions tests/snippets/php/anonymous_class.txt
@@ -0,0 +1,28 @@
---input---
<?php
$containerObject = new class {
public $something;
}

---tokens---
'<?php' Comment.Preproc
'\n' Text

'$containerObject' Name.Variable
' ' Text
'=' Operator
' ' Text
'new' Keyword
' ' Text
'class' Keyword
' ' Text
'{' Punctuation
'\n ' Text
'public' Keyword
' ' Text
'$something' Name.Variable
';' Punctuation
'\n' Text

'}' Punctuation
'\n' Text

0 comments on commit 5b96a7f

Please sign in to comment.