From b3cd58716572fe235a717a6801b6a62722437718 Mon Sep 17 00:00:00 2001 From: Brent Roose Date: Wed, 20 Mar 2024 13:21:09 +0100 Subject: [PATCH] Trait and enum --- src/Languages/Php/Patterns/ClassNamePattern.php | 7 ++++++- src/Languages/Php/Patterns/GroupedTypePattern.php | 2 +- tests/test.md | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Languages/Php/Patterns/ClassNamePattern.php b/src/Languages/Php/Patterns/ClassNamePattern.php index 1dd34b0..a246e00 100644 --- a/src/Languages/Php/Patterns/ClassNamePattern.php +++ b/src/Languages/Php/Patterns/ClassNamePattern.php @@ -6,15 +6,20 @@ use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; +use Tempest\Highlight\PatternTest; use Tempest\Highlight\Tokens\TokenType; +#[PatternTest(input: 'class Foo {}', output: 'Foo')] +#[PatternTest(input: 'interface Foo {}', output: 'Foo')] +#[PatternTest(input: 'trait Foo {}', output: 'Foo')] +#[PatternTest(input: 'enum Foo {}', output: 'Foo')] final readonly class ClassNamePattern implements Pattern { use IsPattern; public function getPattern(): string { - return '(class|interface) (?[\w]+)'; + return '(class|interface|trait|enum) (?[\w]+)'; } public function getTokenType(): TokenType diff --git a/src/Languages/Php/Patterns/GroupedTypePattern.php b/src/Languages/Php/Patterns/GroupedTypePattern.php index 2aa5002..fd3220b 100644 --- a/src/Languages/Php/Patterns/GroupedTypePattern.php +++ b/src/Languages/Php/Patterns/GroupedTypePattern.php @@ -14,7 +14,7 @@ #[PatternTest(input: 'null|(Foo|Bar) $bar', output: '(Foo|Bar)')] #[PatternTest(input: 'null|(?Bar) $bar', output: '(?Bar)')] //#[PatternTest(input: 'while (true)', output: null)] -// TODO: this rule is broken and disabled +// TODO: this pattern is broken and disabled final readonly class GroupedTypePattern implements Pattern { use IsPattern; diff --git a/tests/test.md b/tests/test.md index 42b369a..bb7038f 100644 --- a/tests/test.md +++ b/tests/test.md @@ -1,3 +1,6 @@ ```php -while (true) { +trait Test { + abstract public function test(int $input): int; +} + ``` \ No newline at end of file