Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Mar 21, 2024
1 parent 986c73c commit 04a546d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ You can build your own CSS theme with just a couple of classes:
color: #D14F57;
}

.hl-generic .hl-type,
.hl-generic {
color: #9D3AF6;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Languages/Php/Patterns/KeywordPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function caseInsensitive(): self

public function getPattern(): string
{
$pattern = "/\b(?<!\\$)(?<!\-\>)(?<match>{$this->keyword})(\:|\s|\()/";
$pattern = "/\b(?<!\\$)(?<!\-\>)(?<match>{$this->keyword})(\)|\;|\:|\s|\()/";

if ($this->caseInsensitive) {
$pattern .= 'i';
Expand Down
3 changes: 3 additions & 0 deletions src/Languages/Php/PhpLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function getPatterns(): array
new OperatorPattern('\?'),

// KEYWORDS
new KeywordPattern('null'),
new KeywordPattern('true'),
new KeywordPattern('false'),
new KeywordPattern('__halt_compiler'),
new KeywordPattern('abstract'),
new KeywordPattern('and'),
Expand Down
1 change: 0 additions & 1 deletion src/Themes/highlight-light-lite.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
color: var(--type-color);
}

.hl-generic .hl-type,
.hl-generic {
color: var(--generic-color);
}
Expand Down
1 change: 0 additions & 1 deletion src/Themes/highlight-tempest.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
color: var(--type-color);
}

.hl-generic .hl-type,
.hl-generic {
color: var(--generic-color);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Tokens/TokenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function canContain(self $other): bool
{
return match ($this) {
self::OPERATOR, self::VARIABLE, self::VALUE, self::INJECTION, self::COMMENT => false,
self::TYPE => ! in_array($other->value, [self::KEYWORD->value]),
self::GENERIC => ! in_array($other->value, [self::TYPE->value]),
default => true,
};
}
Expand Down
7 changes: 6 additions & 1 deletion tests/Languages/Php/PhpLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ public static function data(): array
['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>'],
['$foo::class;', '<span class="hl-variable">$foo</span>::<span class="hl-keyword">class</span>;'],
['function ((Foo&Bar)|null $bar)', '<span class="hl-keyword">function</span> (<span class="hl-type">(Foo&amp;Bar)</span><span class="hl-type">|null</span> <span class="hl-variable">$bar</span>)'],
['while (true) {', '<span class="hl-keyword">while</span> (true) {'],
['function (Foo|false $bar)', '<span class="hl-keyword">function</span> (<span class="hl-type">Foo|false</span> <span class="hl-variable">$bar</span>)'],
['function (Foo|true $bar)', '<span class="hl-keyword">function</span> (<span class="hl-type">Foo|true</span> <span class="hl-variable">$bar</span>)'],
['while (true) {', '<span class="hl-keyword">while</span> (<span class="hl-keyword">true</span>) {'],
['catch (Foo|Bar) {}', '<span class="hl-keyword">catch</span> (<span class="hl-type">Foo|Bar</span>) {}'],
['fn&(', '<span class="hl-keyword">fn</span>&amp;('],
['enum Foo: string', '<span class="hl-keyword">enum</span> <span class="hl-type">Foo</span>: <span class="hl-type">string</span>'],
['case Foo;', '<span class="hl-keyword">case</span> <span class="hl-property">Foo</span>;'],
['$this->extends("View/base.view.php");', '<span class="hl-variable">$this</span>-&gt;<span class="hl-property">extends</span>(&quot;<span class="hl-value">View/base.view.php</span>&quot;);'],
['$foo = null;', '<span class="hl-variable">$foo</span> = <span class="hl-keyword">null</span>;'],
['$foo = true;', '<span class="hl-variable">$foo</span> = <span class="hl-keyword">true</span>;'],
['$foo = false;', '<span class="hl-variable">$foo</span> = <span class="hl-keyword">false</span>;'],
['/** @var Foo $var */', '<span class="hl-comment">/** <span class="hl-value">@var</span> <span class="hl-type">Foo</span> <span class="hl-variable">$var</span> */</span>'],
[
"// We'll
Expand Down
20 changes: 10 additions & 10 deletions tests/test.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
```json
{
"name": "tempest/highlight",
"description": "Fast, extensible, server-side code highlighting",
"autoload": {
"psr-4": {
"Tempest\\Highlight\\": "src/"
}
}
}
```php
$foo = null;
$foo = true;
$foo = false;
while(true) {}

function (Foo|null $bar);
function (Foo|true $bar);
function (Foo|false $bar);
function ((Foo&Bar)|null $bar);
```

0 comments on commit 04a546d

Please sign in to comment.