diff --git a/app/MarkDown/CustomHL/Languages/JavaScript/Injections/JsSingleQuoteValue2Injection.php b/app/MarkDown/CustomHL/Languages/JavaScript/Injections/JsSingleQuoteValue2Injection.php new file mode 100644 index 00000000..4edd0884 --- /dev/null +++ b/app/MarkDown/CustomHL/Languages/JavaScript/Injections/JsSingleQuoteValue2Injection.php @@ -0,0 +1,34 @@ +`.*?`)"; + } + + public function parseContent(string $content, Highlighter $highlighter): string + { + $theme = $highlighter->getTheme(); + + $clear_content = Escape::terminal($content); + + return Escape::injection( + Escape::tokens($theme->before(new DynamicTokenType('hl-js-value'))) + . $clear_content + . Escape::tokens($theme->after(new DynamicTokenType('hl-js-value'))) + ); + } +} diff --git a/app/MarkDown/CustomHL/Languages/JavaScript/Injections/JsSingleQuoteValueInjection.php b/app/MarkDown/CustomHL/Languages/JavaScript/Injections/JsSingleQuoteValueInjection.php new file mode 100644 index 00000000..be499397 --- /dev/null +++ b/app/MarkDown/CustomHL/Languages/JavaScript/Injections/JsSingleQuoteValueInjection.php @@ -0,0 +1,34 @@ +'.*?')"; + } + + public function parseContent(string $content, Highlighter $highlighter): string + { + $theme = $highlighter->getTheme(); + + $clear_content = Escape::terminal($content); + + return Escape::injection( + Escape::tokens($theme->before(new DynamicTokenType('hl-js-value'))) + . $clear_content + . Escape::tokens($theme->after(new DynamicTokenType('hl-js-value'))) + ); + } +} diff --git a/app/MarkDown/CustomHL/Languages/JavaScript/JavaScriptLanguage.php b/app/MarkDown/CustomHL/Languages/JavaScript/JavaScriptLanguage.php index 59b39178..4a74f6e7 100644 --- a/app/MarkDown/CustomHL/Languages/JavaScript/JavaScriptLanguage.php +++ b/app/MarkDown/CustomHL/Languages/JavaScript/JavaScriptLanguage.php @@ -10,17 +10,19 @@ //use App\Tempest\Highlight\Languages\JavaScript\Patterns\JsDoubleQuoteValuePattern; use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\JsKeywordPattern; use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\JsMethodPattern; -//use App\Tempest\Highlight\Languages\JavaScript\Patterns\JsMultilineCommentPattern; +use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\JsMultilineCommentPattern; //use App\Tempest\Highlight\Languages\JavaScript\Patterns\JsNewObjectPattern; //use App\Tempest\Highlight\Languages\JavaScript\Patterns\JsObjectPropertyPattern; use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\JsPropertyPattern; use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\JsSinglelineCommentPattern; -use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\JsSingleQuoteValuePattern; //use App\Tempest\Highlight\Languages\JavaScript\Patterns\JsStaticClassPattern; //use App\Tempest\Highlight\Languages\JavaScript\Patterns\JsStaticPropertyPattern; use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\DigitsPattern; use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\ConstantNamePattern; use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\OperatorPattern; +use App\MarkDown\CustomHL\Languages\JavaScript\Injections\JsSingleQuoteValueInjection; +use App\MarkDown\CustomHL\Languages\JavaScript\Injections\JsSingleQuoteValue2Injection; +use App\MarkDown\CustomHL\Languages\JavaScript\Patterns\FunctionEPattern; class JavaScriptLanguage extends CustomBaseLanguage { @@ -42,6 +44,8 @@ public function getInjections(): array return [ ...parent::getInjections(), //new JsDocInjection(), + new JsSingleQuoteValueInjection(), + new JsSingleQuoteValue2Injection(), ]; } @@ -56,6 +60,7 @@ public function getPatterns(): array new JsKeywordPattern('from'), new JsKeywordPattern('import'), new JsKeywordPattern('null', 'hl-js-slug'), + new JsKeywordPattern('this', 'hl-js-slug'), new JsKeywordPattern('true', 'hl-js-slug'), new JsKeywordPattern('var'), //new JsKeywordPattern('set'), @@ -111,7 +116,7 @@ public function getPatterns(): array new OperatorPattern('(=|\?\?|===)'), // COMMENTS - //new JsMultilineCommentPattern(), + new JsMultilineCommentPattern(), new JsSinglelineCommentPattern(), // TYPES @@ -126,12 +131,12 @@ public function getPatterns(): array //new JsStaticPropertyPattern(), // VALUES - new JsSingleQuoteValuePattern(), //new JsDoubleQuoteValuePattern(), new ConstantNamePattern(), new DigitsPattern(), + new FunctionEPattern(), ]; } } diff --git a/app/MarkDown/CustomHL/Languages/JavaScript/Patterns/JsSingleQuoteValuePattern.php b/app/MarkDown/CustomHL/Languages/JavaScript/Patterns/FunctionEPattern.php similarity index 71% rename from app/MarkDown/CustomHL/Languages/JavaScript/Patterns/JsSingleQuoteValuePattern.php rename to app/MarkDown/CustomHL/Languages/JavaScript/Patterns/FunctionEPattern.php index 7958dfdd..01bb34fd 100644 --- a/app/MarkDown/CustomHL/Languages/JavaScript/Patterns/JsSingleQuoteValuePattern.php +++ b/app/MarkDown/CustomHL/Languages/JavaScript/Patterns/FunctionEPattern.php @@ -9,17 +9,17 @@ use Tempest\Highlight\Tokens\TokenType; use Tempest\Highlight\Tokens\DynamicTokenType; -final readonly class JsSingleQuoteValuePattern implements Pattern +final readonly class FunctionEPattern implements Pattern { use IsPattern; public function getPattern(): string { - return "'(?.*?)'"; + return '\((?[a-z]+)\)'; } public function getTokenType(): TokenType { - return new DynamicTokenType('hl-js-value'); + return new DynamicTokenType('hl-js-constant'); } } diff --git a/app/MarkDown/CustomHL/Languages/JavaScript/Patterns/JsMultilineCommentPattern.php b/app/MarkDown/CustomHL/Languages/JavaScript/Patterns/JsMultilineCommentPattern.php new file mode 100644 index 00000000..5665ec53 --- /dev/null +++ b/app/MarkDown/CustomHL/Languages/JavaScript/Patterns/JsMultilineCommentPattern.php @@ -0,0 +1,25 @@ +\/\*(.|\n)*?\*\/)/m'; + } + + public function getTokenType(): TokenType + { + return new DynamicTokenType('hl-js-comment'); + } +} diff --git a/app/MarkDown/CustomHL/Languages/Json/JsonLanguage.php b/app/MarkDown/CustomHL/Languages/Json/JsonLanguage.php index d8fe28d4..005c9d93 100644 --- a/app/MarkDown/CustomHL/Languages/Json/JsonLanguage.php +++ b/app/MarkDown/CustomHL/Languages/Json/JsonLanguage.php @@ -10,6 +10,7 @@ use App\MarkDown\CustomHL\Languages\Json\Patterns\JsonDoubleQuoteValuePattern; use App\MarkDown\CustomHL\Languages\Json\Patterns\JsonPropertyPattern; use App\MarkDown\CustomHL\Languages\Json\Injections\JsonArrayInjection; +use App\MarkDown\CustomHL\Languages\Json\Patterns\DigitsValuePattern; class JsonLanguage extends CustomBaseLanguage { @@ -34,6 +35,7 @@ public function getPatterns(): array //new JsonAccoladesPattern(), //new JsonArrayBracketsPattern(), new JsonDoubleQuoteValuePattern(), + new DigitsValuePattern(), ]; } } diff --git a/app/MarkDown/CustomHL/Languages/Json/Patterns/DigitsValuePattern.php b/app/MarkDown/CustomHL/Languages/Json/Patterns/DigitsValuePattern.php new file mode 100644 index 00000000..53b2da19 --- /dev/null +++ b/app/MarkDown/CustomHL/Languages/Json/Patterns/DigitsValuePattern.php @@ -0,0 +1,25 @@ +[0-9.]+)/'; + } + + public function getTokenType(): TokenType + { + return new DynamicTokenType('hl-js-number'); + } +} diff --git a/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonDoubleQuoteValuePattern.php b/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonDoubleQuoteValuePattern.php index 46298510..1d1f88c4 100644 --- a/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonDoubleQuoteValuePattern.php +++ b/app/MarkDown/CustomHL/Languages/Json/Patterns/JsonDoubleQuoteValuePattern.php @@ -7,7 +7,8 @@ use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; use Tempest\Highlight\Tokens\TokenType; -use Tempest\Highlight\Tokens\DynamicTokenType; +//use Tempest\Highlight\Tokens\DynamicTokenType; +use App\MarkDown\CustomHL\Tokens\QuotedValueTokenType; final readonly class JsonDoubleQuoteValuePattern implements Pattern { @@ -20,6 +21,6 @@ public function getPattern(): string public function getTokenType(): TokenType { - return new DynamicTokenType('hl-json-value'); + return new QuotedValueTokenType(); //DynamicTokenType('hl-json-value'); } } diff --git a/app/MarkDown/CustomHL/Languages/Php/Injections/PhpDocCommentReturnTypeInjection.php b/app/MarkDown/CustomHL/Languages/Php/Injections/PhpDocCommentReturnTypeInjection.php index 642cd218..508c969d 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Injections/PhpDocCommentReturnTypeInjection.php +++ b/app/MarkDown/CustomHL/Languages/Php/Injections/PhpDocCommentReturnTypeInjection.php @@ -12,6 +12,8 @@ use Tempest\Highlight\Tokens\DynamicTokenType; use App\MarkDown\CustomHL\Languages\Php\PhpConst; +//use App\MarkDown\CustomHL\Languages\Php\PhpDocCommentParamTypes; + final readonly class PhpDocCommentReturnTypeInjection implements Injection { use IsInjection; @@ -25,6 +27,28 @@ public function parseContent(string $content, Highlighter $highlighter): string { $keywords = PhpConst::SYS_KEYWORDS; + $types = preg_match_all('/(?!([\w]+)\\\\)(?[\w]+)/', $content, $matches); + + $theme = $highlighter->getTheme(); + + if (key_exists('match', $matches)) + { + foreach($matches['match'] as $type) + { + $token = (in_array($type, $keywords)) ? 'hl-php-keyword' : 'hl-php-type'; + + $content = preg_replace( + '/\b' . $type . '[\b]*/', + Escape::tokens($theme->before(new DynamicTokenType($token))) + . $type + . Escape::tokens($theme->after(new DynamicTokenType($token))), + $content, + ); + } + } + + + /* $types = explode('|', trim($content)); $theme = $highlighter->getTheme(); @@ -34,7 +58,7 @@ public function parseContent(string $content, Highlighter $highlighter): string if (key_exists('match', $matches)) { $content = preg_replace( - '/\barray[\b]*/', + '/\barray[\b]* /', Escape::tokens($theme->before(new DynamicTokenType('hl-php-keyword'))) . 'array' . Escape::tokens($theme->after(new DynamicTokenType('hl-php-keyword'))), @@ -56,7 +80,7 @@ public function parseContent(string $content, Highlighter $highlighter): string $token = (in_array($tk, $keywords)) ? 'hl-php-keyword' : 'hl-php-type'; $content = preg_replace( - '/\b' . $tk . '[\b]*/', + '/\b' . $tk . '[\b]* /', Escape::tokens($theme->before(new DynamicTokenType($token))) . $tk . Escape::tokens($theme->after(new DynamicTokenType($token))), @@ -73,7 +97,7 @@ public function parseContent(string $content, Highlighter $highlighter): string $token = (in_array($type, $keywords)) ? 'hl-php-keyword' : 'hl-php-type'; $content = preg_replace( - '/\b' . $type . '[\b]*/', + '/\b' . $type . '[\b] * /', Escape::tokens($theme->before(new DynamicTokenType($token))) . $type . Escape::tokens($theme->after(new DynamicTokenType($token))), @@ -81,7 +105,7 @@ public function parseContent(string $content, Highlighter $highlighter): string ); } } - +*/ return $content; } } diff --git a/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php b/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php index 3e0faeeb..b410f60a 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php +++ b/app/MarkDown/CustomHL/Languages/Php/Injections/SingleQuoteValueInjection.php @@ -16,7 +16,7 @@ public function getPattern(): string { - return "(?'(.|\n)*?')"; + return "(?'(?!(s ))(.|\n)*?')"; } public function parseContent(string $content, Highlighter $highlighter): string diff --git a/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php b/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php index 432fa0bf..aacd5613 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php +++ b/app/MarkDown/CustomHL/Languages/Php/Patterns/FunctionCallPattern.php @@ -15,7 +15,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/UsePattern.php b/app/MarkDown/CustomHL/Languages/Php/Patterns/UsePattern.php index 130e63c3..e3abcc70 100644 --- a/app/MarkDown/CustomHL/Languages/Php/Patterns/UsePattern.php +++ b/app/MarkDown/CustomHL/Languages/Php/Patterns/UsePattern.php @@ -15,7 +15,7 @@ public function getPattern(): string { - return '/use\s+(function(\s)+)?[\w\\\\]*\b(?[\w]+)[;]*/'; + return '/use\s+(function(\s)+)?[\w\\\\]*\b(?[\w]+[, \w]*)[;]*/'; } public function getTokenType(): TokenType diff --git a/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php b/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php index 3c893295..50871262 100644 --- a/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php +++ b/app/MarkDown/CustomHL/Languages/Php/PhpLanguage.php @@ -117,7 +117,7 @@ public function getPatterns(): array new NamedArgumentPattern(), ////new OperatorPattern('&&'), ////new OperatorPattern('\|\|'), - new OperatorPattern('(!==|===|==|<|=>|>|=|\*|\+\+|&&|\?)'), + new OperatorPattern('(!==|===|==|<=>|<|=>|>|=|\*|\+\+|\+|&&|\?)'), //new OperatorPattern('instanceof'), ////new OperatorPattern('\?'), ////new FunctionNamePattern(), @@ -129,7 +129,7 @@ public function getPatterns(): array // KEYWORDS new KeywordPattern('null', 'hl-php-constant'), - new GenericPattern('/(?\$this)(\-|\$|\,|\)|\;|\:|\s|\()/', 'hl-php-this'), + new GenericPattern('/(?\$this)(\-|\$|\,|\)|\;|\:|\s|\(|\])/', 'hl-php-this'), new GenericPattern('/\->(?[\w]+?)\b[^\(]/', 'hl-php-delimeter'), new GenericPattern('/\((?(string))\)/', 'hl-php-keyword'), ////new KeywordPattern('parent'), @@ -169,7 +169,7 @@ public function getPatterns(): array ////new KeywordPattern('exit'), new KeywordPattern('extends'), ////new KeywordPattern('final'), - ////new KeywordPattern('finally'), + new KeywordPattern('finally'), new KeywordPattern('fn'), ////new KeywordPattern('for'), new KeywordPattern('foreach'), @@ -209,7 +209,7 @@ public function getPatterns(): array new KeywordPattern('use'), new KeywordPattern('validate', 'hl-php-constant'), new KeywordPattern('value', 'hl-php-constant'), - ////new KeywordPattern('while'), + new KeywordPattern('while'), ////new KeywordPattern('xor'), new KeywordPattern('yield'), ////new KeywordPattern('yield from'), diff --git a/app/MarkDown/CustomHL/Languages/Php/PhpTypeLanguage.php b/app/MarkDown/CustomHL/Languages/Php/PhpTypeLanguage.php index b689ef91..6a255bd6 100644 --- a/app/MarkDown/CustomHL/Languages/Php/PhpTypeLanguage.php +++ b/app/MarkDown/CustomHL/Languages/Php/PhpTypeLanguage.php @@ -17,6 +17,8 @@ //use Tempest\Highlight\Languages\Php\Patterns\VariablePattern; use App\MarkDown\CustomHL\Languages\Php\Patterns\OperatorPattern; use App\MarkDown\CustomHL\Languages\Php\Injections\TypeForVariableInjection; +use App\MarkDown\CustomHL\Languages\Php\Patterns\DigitsPattern; +//use App\MarkDown\CustomHL\Languages\Php\Patterns\NamedArgumentPattern; final class PhpTypeLanguage extends CustomBaseLanguage { @@ -47,6 +49,7 @@ public function getPatterns(): array //new TypeForVariablePattern(), + //new NamedArgumentPattern(), new OperatorPattern('(<|=>|>|=|\*)'), //new KeywordPattern('array'), //new KeywordPattern('bool'), @@ -56,6 +59,7 @@ public function getPatterns(): array new KeywordPattern('null', 'hl-php-constant'), new KeywordPattern('true', 'hl-php-constant'), new KeywordPattern('false', 'hl-php-constant'), + new KeywordPattern('use'), //new KeywordPattern('new'), //new KeywordPattern('readonly'), @@ -64,6 +68,8 @@ public function getPatterns(): array // VARIABLES //new VariablePattern(), + + new DigitsPattern(), ]; } } diff --git a/app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php b/app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php new file mode 100644 index 00000000..94689a4b --- /dev/null +++ b/app/MarkDown/CustomHL/Tokens/QuotedValueTokenType.php @@ -0,0 +1,20 @@ +