-
-
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
12 changed files
with
520 additions
and
71 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,26 @@ | ||
<?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\TokenType; | ||
|
||
#[PatternTest(input: 'class Rectangle', output: 'Rectangle')] | ||
final readonly class JsClassNamePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return 'class (?<match>[\w]+)'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\JavaScript\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\Tokens\TokenType; | ||
|
||
final class JsKeywordPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
private bool $caseInsensitive = false; | ||
|
||
public function __construct(private string $keyword) | ||
{ | ||
} | ||
|
||
public function caseInsensitive(): self | ||
{ | ||
$this->caseInsensitive = true; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPattern(): string | ||
{ | ||
$pattern = "/\b(?<!\.)(?<match>{$this->keyword})(\,|\.|\)|\;|\:|\s|\()/"; | ||
|
||
if ($this->caseInsensitive) { | ||
$pattern .= 'i'; | ||
} | ||
|
||
return $pattern; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::KEYWORD; | ||
} | ||
} |
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,26 @@ | ||
<?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\TokenType; | ||
|
||
#[PatternTest(input: 'calcArea() {', output: 'calcArea')] | ||
final readonly class JsMethodPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '(?<match>[\w]+)\('; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::PROPERTY; | ||
} | ||
} |
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\TokenType; | ||
|
||
#[PatternTest(input: 'new Rectangle(', output: 'Rectangle')] | ||
#[PatternTest(input: 'new qq.AjaxRequester(', output: 'AjaxRequester')] | ||
final readonly class JsNewObjectPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return 'new (\w+\.)*(?<match>[\w]+)(\s)*\('; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::TYPE; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Languages/JavaScript/Patterns/JsStaticClassPattern.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,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\TokenType; | ||
|
||
#[PatternTest(input: 'Math.round', output: 'Math')] | ||
#[PatternTest(input: 'customHeaders.get', output: null)] | ||
final readonly class JsStaticClassPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '\b(?<match>[A-Z][\w]+)\.'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::TYPE; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Languages/JavaScript/Patterns/JsStaticPropertyPattern.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,26 @@ | ||
<?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\TokenType; | ||
|
||
#[PatternTest(input: 'static foo', output: 'foo')] | ||
final readonly class JsStaticPropertyPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return 'static (?<match>[\w]+)'; | ||
} | ||
|
||
public function getTokenType(): TokenType | ||
{ | ||
return TokenType::PROPERTY; | ||
} | ||
} |
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
Oops, something went wrong.