forked from tempestphp/highlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalUrlPattern.php
More file actions
29 lines (23 loc) · 965 Bytes
/
TerminalUrlPattern.php
File metadata and controls
29 lines (23 loc) · 965 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
<?php
declare(strict_types=1);
namespace Tempest\Highlight\Languages\Terminal\Patterns;
use Tempest\Highlight\IsPattern;
use Tempest\Highlight\Pattern;
use Tempest\Highlight\PatternTest;
use Tempest\Highlight\Tokens\TokenTypeEnum;
#[PatternTest(input: 'curl -OL https://example.com/file.phar', output: 'https://example.com/file.phar')]
#[PatternTest(input: 'wget http://archive.ubuntu.com/ubuntu', output: 'http://archive.ubuntu.com/ubuntu')]
#[PatternTest(input: 'curl ftp://files.example.com/data.csv', output: 'ftp://files.example.com/data.csv')]
#[PatternTest(input: 'git clone ssh://git@github.com/user/repo', output: 'ssh://git@github.com/user/repo')]
final readonly class TerminalUrlPattern implements Pattern
{
use IsPattern;
public function getPattern(): string
{
return '/(?<match>(?:https?|ftp|sftp|ssh|file):\/\/\S+)/';
}
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::VALUE;
}
}