Skip to content

Commit

Permalink
highlighter tmp commit 20241127
Browse files Browse the repository at this point in the history
  • Loading branch information
demn98 committed Nov 28, 2024
1 parent 49cdab6 commit 46a2fe4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function parseContent(string $content, Highlighter $highlighter): string

foreach($match['match'] as $val) {
$content = preg_replace(
'/\b' . $val[0] . '[\b]*/',
'/\b' . addcslashes($val[0], '/*') . '[\b]*/',
Escape::tokens($theme->before(new DynamicTokenType('hl-json-value')))
. $val[0]
. Escape::tokens($theme->after(new DynamicTokenType('hl-json-value'))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public function getPattern(): string
{
return '/\"(?<match>[\w\\\\\-\.]+)\"(\s)*\:/';
return '/\"(?<match>[\w\\\\\-\. \|]+)\"(\s)*\:/';
}

public function getTokenType(): TokenType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public function getPattern(): string
{
return '(?<match>".*?")';
return '(?<match>"(\\\"|.)*?")';
}

public function parseContent(string $content, Highlighter $highlighter): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

public function getPattern(): string
{
return 'new (?<match>[\w\\\\]+)';
//return 'new (?<match>[\w\\\\]+)';
return '/new [\w\\\\]*\b(?<match>[\w]+)/';
}

public function parseContent(string $content, Highlighter $highlighter): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

namespace App\MarkDown\CustomHL\Languages\Php\Injections;

use Tempest\Highlight\After;
use Tempest\Highlight\Highlighter;
use Tempest\Highlight\Injection;
use Tempest\Highlight\IsInjection;
use Tempest\Highlight\Escape;
use Tempest\Highlight\Tokens\DynamicTokenType;
//use Tempest\Highlight\Tokens\DynamicTokenType;
use App\MarkDown\CustomHL\Tokens\QuotedValueTokenType;

#[After]
final readonly class SingleQuoteValueInjection implements Injection
{
use IsInjection;

public function getPattern(): string
{
return "(?<match>'(?!(s ))(.|\n)*?')";
return "(?<match>'(?!(s ))(\\\'|.|\n)*?')";
}

public function parseContent(string $content, Highlighter $highlighter): string
Expand All @@ -26,9 +29,9 @@ public function parseContent(string $content, Highlighter $highlighter): string
$clear_content = Escape::terminal($content);

return Escape::injection(
Escape::tokens($theme->before(new DynamicTokenType('hl-php-value')))
Escape::tokens($theme->before(new QuotedValueTokenType('hl-php-value')))
. $clear_content
. Escape::tokens($theme->after(new DynamicTokenType('hl-php-value')))
. Escape::tokens($theme->after(new QuotedValueTokenType('hl-php-value')))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public function getPattern(): string
{
return '/[(^)| |>|:]?(?!\$)\b(?<match>[_\-a-z\w]+)\(/';
//return '/[^\$][(^)| |>|:]?(?!\$)\b(?<match>[_\-a-z\w]+)\(/';
}

public function getTokenType(): TokenType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

public function getPattern(): string
{
return 'new (?<match>[\w\\\\]+)';
//return 'new (?<match>[\w\\\\]+)';
return '/new [\w\\\\]*\b(?<match>[\w]+)/';
}

public function getTokenType(): TokenType
Expand Down
1 change: 1 addition & 0 deletions app/MarkDown/CustomHL/Languages/Php/PhpConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class PhpConst
'void',
'int',
'mixed',
'object',
];
}
9 changes: 7 additions & 2 deletions app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public function getName(): string
return 'php';
}

public function getAliases(): array
{
return ['txt'];
}

public function getInjections(): array
{
return [
Expand Down Expand Up @@ -117,7 +122,7 @@ public function getPatterns(): array
new NamedArgumentPattern(),
////new OperatorPattern('&&'),
////new OperatorPattern('\|\|'),
new OperatorPattern('(!==|===|==|<=>|<|=>|>|=|\*|\+\+|\+|&&|\?)'),
new OperatorPattern('(!==|===|==|<=>|<|=>|>|=|\*|\+\+|\+|&&|\?|\|\|)'),
//new OperatorPattern('instanceof'),
////new OperatorPattern('\?'),
////new FunctionNamePattern(),
Expand All @@ -141,7 +146,7 @@ public function getPatterns(): array
////new KeywordPattern('and'),
new KeywordPattern('as'),
////new KeywordPattern('break'),
////new KeywordPattern('callable'),
new KeywordPattern('callable'),
new KeywordPattern('case'),
new KeywordPattern('catch'),
new KeywordPattern('class'),
Expand Down
6 changes: 5 additions & 1 deletion app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

final readonly class QuotedValueTokenType implements TokenType
{
public function __construct(
private string $value = 'hl-json-value'
) {}

public function getValue(): string
{
return 'hl-json-value';
return $this->value;
}

public function canContain(TokenType $other): bool
Expand Down

0 comments on commit 46a2fe4

Please sign in to comment.