-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
121 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\JavaScript\Injections; | ||
|
||
use Tempest\Highlight\Highlighter; | ||
use Tempest\Highlight\Injection; | ||
use Tempest\Highlight\IsInjection; | ||
use Tempest\Highlight\Languages\JavaScript\JsDocLanguage; | ||
|
||
final readonly class JsDocInjection implements Injection | ||
{ | ||
use IsInjection; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '/(?<match>\/\*\*(.|\n)*?\*\/)/m'; | ||
} | ||
|
||
public function parseContent(string $content, Highlighter $highlighter): string | ||
{ | ||
return $highlighter->parse($content, new JsDocLanguage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\JavaScript; | ||
|
||
use Tempest\Highlight\Languages\DocComment\DocCommentLanguage; | ||
use Tempest\Highlight\Languages\JavaScript\Patterns\JsDocParamNamePattern; | ||
use Tempest\Highlight\Languages\JavaScript\Patterns\JsDocTypePattern; | ||
|
||
class JsDocLanguage extends DocCommentLanguage | ||
{ | ||
public function getPatterns(): array | ||
{ | ||
return [ | ||
...parent::getPatterns(), | ||
new JsDocTypePattern(), | ||
new JsDocParamNamePattern(), | ||
]; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Languages/JavaScript/Patterns/JsDocParamNamePattern.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\JavaScript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenTypeEnum; | ||
|
||
#[PatternTest('@param {string} foo ', 'foo')] | ||
#[PatternTest('@param {Object[]} foo', 'foo')] | ||
#[PatternTest('@param {string} employees[].name', 'employees[].name')] | ||
#[PatternTest('@param {string} employees[].name The name', 'employees[].name')] | ||
final readonly class JsDocParamNamePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '@param\s(.*?)\s(?<match>(.*?))(\s|$)'; | ||
} | ||
|
||
public function getTokenType(): TokenTypeEnum | ||
{ | ||
return TokenTypeEnum::VALUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\JavaScript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenTypeEnum; | ||
|
||
#[PatternTest('@param {string} foo ', '{string}')] | ||
#[PatternTest('@param {Object[]} foo', '{Object[]}')] | ||
final readonly class JsDocTypePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '(?<match>\{(.*?)\})'; | ||
} | ||
|
||
public function getTokenType(): TokenTypeEnum | ||
{ | ||
return TokenTypeEnum::TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
```php | ||
```js | ||
/** | ||
* This function will do some things | ||
* | ||
* @template T | ||
* @param class-string<T> $className the class' name | ||
* @param int $id | ||
* @return T|null | ||
* | ||
* That's about all | ||
* Class making something fun and easy. | ||
* @param {string} arg1 An argument that makes this more interesting. | ||
* @param {Array.<number>} arg2 List of numbers to be processed. | ||
* @constructor | ||
*/ | ||
``` |