Adding stripping of commented code during detection of BHL func signatures
Publish PHP Package / docker (push) Successful in 6s Details

This commit is contained in:
Pavel Shevaev 2024-10-04 13:34:22 +03:00
parent 63dee1f015
commit 9c4c4521d8
1 changed files with 18 additions and 0 deletions

View File

@ -264,6 +264,7 @@ function bhl_validate_func_ref(string $module_file, string $func_full_name, arra
$namespace = implode('.', $name_items);
$module_src = file_get_contents($module_file);
$module_src = _bhl_remove_comments($module_src);
if(!$module_src)
throw new Exception("Bad module file '{$module_file}'");
@ -317,6 +318,23 @@ function bhl_validate_func_ref(string $module_file, string $func_full_name, arra
throw new Exception("Func '$func_full_name(".implode(',', $signature).")' not found in '$module_file'");
}
function _bhl_remove_comments(string $txt) : string
{
//block comments
if(strpos($txt, '/*') !== false)
{
$regex = '~/\*.*?\*/~s';
$txt = preg_replace_callback(
$regex,
//preserve the new lines for better error reporting
function($m) { return str_repeat("\n", substr_count($m[0], "\n")); },
$txt);
}
//line comments
$txt = preg_replace("~\s*(?<!:)//.*~", "\n", $txt);
return $txt;
}
function _bhl_split_by_namespaces(string $src) : array
{
$nss = array();