install.fairie/dotfiles/.vim/plugged/php.vim/attic/30-update.php
Git E2E Dev Test Username 20b4a91fbb git subrepo clone (merge) https://github.com/stanangeloff/php.vim.git ./dotfiles/.vim/plugged/php.vim
subrepo:
  subdir:   "dotfiles/.vim/plugged/php.vim"
  merged:   "930aec5c"
upstream:
  origin:   "https://github.com/stanangeloff/php.vim.git"
  branch:   "master"
  commit:   "930aec5c"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
2022-10-18 10:36:27 -04:00

71 lines
2.1 KiB
PHP

<?php
require __DIR__ . '/0-bootstrap.inc.php';
$blocks = unserialize(file_get_contents('php://stdin'), ['allowed_classes' => false]);
# Read the existing syntax file with block markers in it.
#
$template = file_get_contents($argv[1]);
# Clean up any previously defined blocks.
$template = preg_replace(
sprintf(
'/(@block\([\'"](%s)[\'"]\)["\r\n\t ]*).*?(["\r\n\t ]*@endblock)\b/ism',
implode(/* $glue = */ '|', array_keys($blocks))
),
"\\1___\\2___\\3",
$template
);
# Update block contents in the template.
foreach ($blocks as $blockName => $lines) {
$template = str_ireplace(
sprintf('___%s___', $blockName),
rtrim(is_array($lines) ? implode(/* $glue = */ "\n", $lines) : $lines),
$template
);
}
$template = preg_replace_callback(
'/
(?<begin>"\s*@copy\s+(?<copy>[a-zA-Z0-9_]+)(?<processors>(\s+(strip_maximum_size))+)?)
(?<script>.*?)
(?<end>"\s*@end\s+([a-zA-Z0-9_]+))
/sx',
function (array $groups) use ($template) {
$copy = preg_quote($groups['copy'], /* $delimiter = */ '/');
$processors = array_filter(array_map('trim', preg_split('{[;, ]+}', $groups['processors'])));
preg_match("/
\"\\s*@begin\\s+{$copy}\b
(?<script>.*?)
\"\\s*@end\\s+{$copy}\b
/sx", $template, $captures);
if (! isset($captures['script'])) {
file_put_contents('php://stderr', "[ERROR] The block referenced by '{$groups['begin']}' was not found." . PHP_EOL);
return $groups['begin'] . $groups['script'] . $groups['end'];
}
$script = $captures['script'];
foreach ($processors as $processor) {
switch ($processor) {
case 'strip_maximum_size':
$script = preg_replace('{\\\\@\d+}', '\@', $script);
break;
default:
file_put_contents('php://stderr', "[ERROR] The processor \"{$processor}\" is not supported, found in '{$groups['begin']}'." . PHP_EOL);
}
}
return $groups['begin'] . $script . $groups['end'];
},
$template
);
echo $template;