Skip to content

Commit

Permalink
add missing detection of interfaces and traits for php
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfedr committed Jul 9, 2019
1 parent e5136f3 commit b307cde
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.detect?(text)

rule %r/[~!%^&*+=\|:.<>\/?@-]+/, Operator
rule %r/[\[\]{}();,]/, Punctuation
rule %r/class\b/, Keyword, :classname
rule %r/(class|interface|trait)\b/, Keyword::Declaration, :classname
# anonymous functions
rule %r/(function)(\s*)(?=\()/ do
groups Keyword, Text
Expand Down
12 changes: 12 additions & 0 deletions spec/lexers/php_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,17 @@
it 'recognizes try catch finally definition' do
assert_tokens_equal 'try {} catch () {} finally {}', ["Keyword", "try"], ["Text", " "], ["Punctuation", "{}"], ["Text", " "], ["Keyword", "catch"], ["Text", " "], ["Punctuation", "()"], ["Text", " "], ["Punctuation", "{}"], ["Text", " "], ["Keyword", "finally"], ["Text", " "], ["Punctuation", "{}"]
end

it 'recognizes class definition' do
assert_tokens_equal 'class A {}', ["Keyword.Declaration", "class"], ["Text", " "], ["Name.Class", "A"], ["Text", " "], ["Punctuation", "{}"]
end

it 'recognizes interface definition' do
assert_tokens_equal 'interface A {}', ["Keyword.Declaration", "interface"], ["Text", " "], ["Name.Class", "A"], ["Text", " "], ["Punctuation", "{}"]
end

it 'recognizes trait definition' do
assert_tokens_equal 'trait A {}', ["Keyword.Declaration", "trait"], ["Text", " "], ["Name.Class", "A"], ["Text", " "], ["Punctuation", "{}"]
end
end
end

0 comments on commit b307cde

Please sign in to comment.