Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Tags and Blade Namespaced Components #156

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Languages/Blade/BladeLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Tempest\Highlight\Languages\Blade\Injections\BladePhpInjection;
use Tempest\Highlight\Languages\Blade\Injections\BladeRawEchoInjection;
use Tempest\Highlight\Languages\Blade\Patterns\BladeCommentPattern;
use Tempest\Highlight\Languages\Blade\Patterns\BladeComponentCloseTagPattern;
use Tempest\Highlight\Languages\Blade\Patterns\BladeComponentOpenTagPattern;
use Tempest\Highlight\Languages\Blade\Patterns\BladeKeywordPattern;
use Tempest\Highlight\Languages\Html\HtmlLanguage;

Expand All @@ -34,6 +36,8 @@ public function getPatterns(): array
{
return [
...parent::getPatterns(),
new BladeComponentOpenTagPattern(),
new BladeComponentCloseTagPattern(),
new BladeKeywordPattern(),
new BladeCommentPattern(),
];
Expand Down
29 changes: 29 additions & 0 deletions src/Languages/Blade/Patterns/BladeComponentCloseTagPattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\Languages\Blade\Patterns;

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

#[PatternTest(input: '</a>', output: 'a')]
#[PatternTest(input: '</x-hello>', output: 'x-hello')]
#[PatternTest(input: '</x-hello::world>', output: 'x-hello::world')]
#[PatternTest(input: '</x-hello::world.lorem>', output: 'x-hello::world.lorem')]
final readonly class BladeComponentCloseTagPattern implements Pattern
{
use IsPattern;

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

public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
}
}
29 changes: 29 additions & 0 deletions src/Languages/Blade/Patterns/BladeComponentOpenTagPattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\Languages\Blade\Patterns;

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

#[PatternTest(input: '<a attr="">', output: 'a')]
#[PatternTest(input: '<x-hello attr="">', output: 'x-hello')]
#[PatternTest(input: '<x-hello::world attr="">', output: 'x-hello::world')]
#[PatternTest(input: '<x-hello::world.lorem attr="">', output: 'x-hello::world.lorem')]
final readonly class BladeComponentOpenTagPattern implements Pattern
{
use IsPattern;

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

public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
}
}
26 changes: 26 additions & 0 deletions src/Languages/Php/Patterns/PhpCloseTagPattern.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\TokenTypeEnum;

#[PatternTest(input: '?>', output: '?>')]
final readonly class PhpCloseTagPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '(?<match>\?\>+)';
}

public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
}
}
27 changes: 27 additions & 0 deletions src/Languages/Php/Patterns/PhpOpenTagPattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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\TokenTypeEnum;

#[PatternTest(input: '<?php', output: '<?php')]
#[PatternTest(input: '<?=', output: '<?=')]
final readonly class PhpOpenTagPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '(?<match>\<\?[=|php]+)';
}

public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
}
}
4 changes: 4 additions & 0 deletions src/Languages/Php/PhpLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
use Tempest\Highlight\Languages\Php\Patterns\NestedFunctionCallPattern;
use Tempest\Highlight\Languages\Php\Patterns\NewObjectPattern;
use Tempest\Highlight\Languages\Php\Patterns\OperatorPattern;
use Tempest\Highlight\Languages\Php\Patterns\PhpCloseTagPattern;
use Tempest\Highlight\Languages\Php\Patterns\PhpOpenTagPattern;
use Tempest\Highlight\Languages\Php\Patterns\PropertyAccessPattern;
use Tempest\Highlight\Languages\Php\Patterns\PropertyHookGetPattern;
use Tempest\Highlight\Languages\Php\Patterns\PropertyHookSetParameterTypePattern;
Expand Down Expand Up @@ -76,6 +78,8 @@ public function getPatterns(): array
return [
...parent::getPatterns(),

new PhpOpenTagPattern(),
new PhpCloseTagPattern(),
new UseFunctionNamePattern(),
new UseFunctionPattern(),
new ClassNamePattern(),
Expand Down
Loading