Skip to content

Commit

Permalink
Support attributes in PHP lexer (#1915)
Browse files Browse the repository at this point in the history
  • Loading branch information
tancnle authored Jan 24, 2023
1 parent 6f5aecd commit a4ed658
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rouge/lexers/php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def builtins

state :whitespace do
rule %r/\s+/, Text
rule %r/#.*?$/, Comment::Single
rule %r/#[^\[].*?$/, Comment::Single
rule %r(//.*?$), Comment::Single
rule %r(/\*\*(?!/).*?\*/)m, Comment::Doc
rule %r(/\*.*?\*/)m, Comment::Multiline
Expand All @@ -235,6 +235,8 @@ def builtins
groups Keyword::Namespace, Text, Name::Namespace
end

rule %r/#\[.*\]$/, Name::Attribute

rule %r/(class|interface|trait|extends|implements)
(\s+)
(#{id_with_ns})/ix do |m|
Expand Down
22 changes: 22 additions & 0 deletions spec/visual/samples/php
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,25 @@ class Test {
<?php endif ?>

<p>it's html here at the end, too.</p>


/* Attributes */

<?php

#[MyAttribute]
#[\MyExample\MyAttribute]
#[MyAttribute(1234)]
#[MyAttribute(value: 1234)]
#[MyAttribute(MyAttribute::VALUE)]
#[MyAttribute(array("key" => "value"))]
#[MyAttribute(100 + 200)]
class SetUp {
#[JsonSerialize('Setup')]
public const version = '0.0.1';

#[SetUp]
public function fileExists() {}
}

?>

0 comments on commit a4ed658

Please sign in to comment.