diff --git a/app/MarkDown/CustomHL/Languages/Json/Injections/JsonArrayInjection.php b/app/MarkDown/CustomHL/Languages/Json/Injections/JsonArrayInjection.php index bec8a002..50195fe2 100644 --- a/app/MarkDown/CustomHL/Languages/Json/Injections/JsonArrayInjection.php +++ b/app/MarkDown/CustomHL/Languages/Json/Injections/JsonArrayInjection.php @@ -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'))), diff --git a/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonPropertyPattern.php b/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonPropertyPattern.php index 3365dfc6..babf4d3b 100644 --- a/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonPropertyPattern.php +++ b/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonPropertyPattern.php @@ -15,7 +15,7 @@ public function getPattern(): string { - return '/\"(?[\w\\\\\-\.]+)\"(\s)*\:/'; + return '/\"(?[\w\\\\\-\. \|]+)\"(\s)*\:/'; } public function getTokenType(): TokenType diff --git a/app/MarkDown/CustomHL/Languages/Php/Injections/DoubleQuoteValueInjection.php b/app/MarkDown/CustomHL/Languages/Php/Injections/DoubleQuoteValueInjection.php index 62f03962..2eccfa25 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Injections/DoubleQuoteValueInjection.php +++ b/app/MarkDown/CustomHL/Languages/Php/Injections/DoubleQuoteValueInjection.php @@ -16,7 +16,7 @@ public function getPattern(): string { - return '(?".*?")'; + return '(?"(\\\"|.)*?")'; } public function parseContent(string $content, Highlighter $highlighter): string diff --git a/app/MarkDown/CustomHL/Languages/Php/Injections/NewObjectInjection.php b/app/MarkDown/CustomHL/Languages/Php/Injections/NewObjectInjection.php index 57c270fe..a1b25e20 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Injections/NewObjectInjection.php +++ b/app/MarkDown/CustomHL/Languages/Php/Injections/NewObjectInjection.php @@ -18,7 +18,8 @@ public function getPattern(): string { - return 'new (?[\w\\\\]+)'; + //return 'new (?[\w\\\\]+)'; + return '/new [\w\\\\]*\b(?[\w]+)/'; } public function parseContent(string $content, Highlighter $highlighter): string diff --git a/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php b/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php index b410f60a..8e9ae59c 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php +++ b/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php @@ -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 "(?'(?!(s ))(.|\n)*?')"; + return "(?'(?!(s ))(\\\'|.|\n)*?')"; } public function parseContent(string $content, Highlighter $highlighter): string @@ -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'))) ); } } diff --git a/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php b/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php index aacd5613..b5b0ba99 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php +++ b/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php @@ -16,6 +16,7 @@ public function getPattern(): string { return '/[(^)| |>|:]?(?!\$)\b(?[_\-a-z\w]+)\(/'; + //return '/[^\$][(^)| |>|:]?(?!\$)\b(?[_\-a-z\w]+)\(/'; } public function getTokenType(): TokenType diff --git a/app/MarkDown/CustomHL/Languages/Php/Patterns/NewObjectPattern.php b/app/MarkDown/CustomHL/Languages/Php/Patterns/NewObjectPattern.php index cbc551cc..b5fa196d 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Patterns/NewObjectPattern.php +++ b/app/MarkDown/CustomHL/Languages/Php/Patterns/NewObjectPattern.php @@ -15,7 +15,8 @@ public function getPattern(): string { - return 'new (?[\w\\\\]+)'; + //return 'new (?[\w\\\\]+)'; + return '/new [\w\\\\]*\b(?[\w]+)/'; } public function getTokenType(): TokenType diff --git a/app/MarkDown/CustomHL/Languages/Php/PhpConst.php b/app/MarkDown/CustomHL/Languages/Php/PhpConst.php index bcfa8bc9..43aea383 100644 --- a/app/MarkDown/CustomHL/Languages/Php/PhpConst.php +++ b/app/MarkDown/CustomHL/Languages/Php/PhpConst.php @@ -14,5 +14,6 @@ class PhpConst 'void', 'int', 'mixed', + 'object', ]; } diff --git a/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php b/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php index 50871262..e556ba0c 100644 --- a/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php +++ b/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php @@ -84,6 +84,11 @@ public function getName(): string return 'php'; } + public function getAliases(): array + { + return ['txt']; + } + public function getInjections(): array { return [ @@ -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(), @@ -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'), diff --git a/app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php b/app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php index 94689a4b..a72c1623 100644 --- a/app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php +++ b/app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php @@ -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