-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
1 parent
ea8bb97
commit 7432aa2
Showing
6 changed files
with
142 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Highlight\Languages\Yaml\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenTypeEnum; | ||
|
||
#[PatternTest(input: 'date: 2024-05-31', output: '2024-05-31')] | ||
#[PatternTest(input: 'time: 12:34:56', output: '12:34:56')] | ||
#[PatternTest(input: 'date_time: 2024-05-31 12:34:56', output: '2024-05-31 12:34:56')] | ||
final readonly class YamlDateTimePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '(?<match>\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?)'; | ||
} | ||
|
||
public function getTokenType(): TokenTypeEnum | ||
{ | ||
return TokenTypeEnum::NUMBER; | ||
} | ||
} |
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\Yaml\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenTypeEnum; | ||
|
||
#[PatternTest(input: 'required: true', output: 'true')] | ||
#[PatternTest(input: 'required: TRUE', output: 'TRUE')] | ||
final readonly class YamlLogicalValuePattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '(?i)\b(?<match>(?:true|false|yes|no|null))\b'; | ||
} | ||
|
||
public function getTokenType(): TokenTypeEnum | ||
{ | ||
return TokenTypeEnum::LITERAL; | ||
} | ||
} |
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\Yaml\Patterns; | ||
|
||
use Tempest\Highlight\IsPattern; | ||
use Tempest\Highlight\Pattern; | ||
use Tempest\Highlight\PatternTest; | ||
use Tempest\Highlight\Tokens\TokenTypeEnum; | ||
|
||
#[PatternTest(input: 'age: 28', output: '28')] | ||
final readonly class YamlNumberPattern implements Pattern | ||
{ | ||
use IsPattern; | ||
|
||
public function getPattern(): string | ||
{ | ||
return '(?<!\w)(?<match>[+-]?(?:0x[\da-fA-F]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan))(?!\w)'; | ||
} | ||
|
||
public function getTokenType(): TokenTypeEnum | ||
{ | ||
return TokenTypeEnum::NUMBER; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
```yaml | ||
# Example YAML for syntax highlighting test | ||
|
||
# Scalar values | ||
name: John Doe | ||
age: 30 | ||
is_student: false | ||
|
||
# Sequence (list) of scalars | ||
favorite_colors: | ||
- blue | ||
- green | ||
- red | ||
|
||
# Mapping (dictionary) | ||
address: | ||
street: 123 Main St | ||
city: Anytown | ||
postal_code: 12345 | ||
|
||
# Nested mappings | ||
education: | ||
high_school: | ||
name: Anytown High School | ||
graduation_year: 2010 | ||
university: | ||
name: State University | ||
graduation_year: 2014 | ||
degree: Computer Science | ||
|
||
# Sequence of mappings | ||
work_experience: | ||
- company: ABC Corp | ||
position: Software Engineer | ||
start_date: 2015-06-01 | ||
end_date: 2018-08-30 | ||
- company: XYZ Inc | ||
position: Senior Developer | ||
start_date: 2018-09-01 | ||
end_date: present | ||
|
||
# Multi-line string (literal block scalar) | ||
bio: | | ||
John Doe is a software developer with over 10 years of experience. | ||
He has worked on a variety of projects, ranging from web development to | ||
data analysis. In his free time, he enjoys hiking and photography. | ||
# Multi-line string (folded block scalar) | ||
quote: > | ||
"The only limit to our realization of tomorrow | ||
is our doubts of today." | ||
- Franklin D. Roosevelt | ||
``` |