forked from tempestphp/highlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBashKeywordPattern.php
More file actions
35 lines (27 loc) · 873 Bytes
/
BashKeywordPattern.php
File metadata and controls
35 lines (27 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace Tempest\Highlight\Languages\Bash\Patterns;
use Tempest\Highlight\IsPattern;
use Tempest\Highlight\Pattern;
use Tempest\Highlight\Tokens\TokenTypeEnum;
final readonly class BashKeywordPattern implements Pattern
{
use IsPattern;
public function __construct(private array $keywords = [
'if', 'then', 'else', 'elif', 'fi', 'for', 'while', 'do', 'done',
'case', 'esac', 'function', 'return', 'in', 'select', 'until',
'break', 'continue', 'declare', 'local', 'export', 'readonly',
'unset', 'shift', 'trap', 'source',
])
{
}
public function getPattern(): string
{
$keywords = implode('|', $this->keywords);
return "\b(?<match>(?:{$keywords}))\b";
}
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
}
}