Skip to content

Commit

Permalink
UsAsPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Mar 20, 2024
1 parent 6f86073 commit bca654f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
26 changes: 26 additions & 0 deletions src/Languages/Php/Patterns/UseAsPattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\Languages\Php\Patterns;

use Tempest\Highlight\IsPattern;
use Tempest\Highlight\Pattern;
use Tempest\Highlight\PatternTest;
use Tempest\Highlight\Tokens\TokenType;

#[PatternTest('use Illuminate\Contracts\Container\Container as ContainerContract', 'ContainerContract')]
final readonly class UseAsPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return 'use [\w\\\\]+ as (?<match>[\w]+)';
}

public function getTokenType(): TokenType
{
return TokenType::TYPE;
}
}
2 changes: 2 additions & 0 deletions src/Languages/Php/PhpLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Tempest\Highlight\Languages\Php\Patterns\SingleQuoteValuePattern;
use Tempest\Highlight\Languages\Php\Patterns\StaticClassCallPattern;
use Tempest\Highlight\Languages\Php\Patterns\UntypedClassPropertyPattern;
use Tempest\Highlight\Languages\Php\Patterns\UseAsPattern;
use Tempest\Highlight\Languages\Php\Patterns\UsePattern;

class PhpLanguage extends BaseLanguage
Expand Down Expand Up @@ -147,6 +148,7 @@ public function getPatterns(): array
new ParameterTypePattern(),
new NewObjectPattern(),
new InstanceOfPattern(),
new UseAsPattern(),

// PROPERTIES
new ClassPropertyPattern(),
Expand Down
1 change: 1 addition & 0 deletions tests/Languages/Php/PhpLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function data(): array
['protected Foo $resolved = [];', '<span class="hl-keyword">protected</span> <span class="hl-type">Foo</span> <span class="hl-property">$resolved</span> = [];'],
['$concrete instanceof Closure', '$concrete <span class="hl-keyword">instanceof</span> <span class="hl-type">Closure</span>'],
['extends Foo implements ArrayAccess, ContainerContract', '<span class="hl-keyword">extends</span> <span class="hl-type">Foo</span> <span class="hl-keyword">implements</span><span class="hl-type"> ArrayAccess, ContainerContract</span>'],
['use Illuminate\Contracts\Container\Container as ContainerContract', '<span class="hl-keyword">use</span> <span class="hl-type">Illuminate\Contracts\Container\Container</span> <span class="hl-keyword">as</span> <span class="hl-type">ContainerContract</span>'],
[
"// We'll
Expand Down
5 changes: 1 addition & 4 deletions tests/test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
```php
extends Foo implements ArrayAccess, ContainerContract
{

}
use Illuminate\Contracts\Container\Container as ContainerContract
```

0 comments on commit bca654f

Please sign in to comment.