From 9c4c4521d804c7d43fc0563c25523096be70e8a4 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Fri, 4 Oct 2024 13:34:22 +0300 Subject: [PATCH] Adding stripping of commented code during detection of BHL func signatures --- bhl.inc.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bhl.inc.php b/bhl.inc.php index f1b31ed..ad741b2 100644 --- a/bhl.inc.php +++ b/bhl.inc.php @@ -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*(?