Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
fcfa71aa0c | |
|
22ec477ddf | |
|
82ad2216da | |
|
4a85fa9b4d | |
|
d74b15c7ce | |
|
9c4c4521d8 |
58
bhl.inc.php
58
bhl.inc.php
|
@ -156,11 +156,9 @@ function bhl_run(bool $debug = true, bool $force = false, bool $exit_on_err = tr
|
|||
if(!$exit_on_err)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
else if($debug)
|
||||
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . ", CRC " . hexdec(hash_file('CRC32', $result_file, false)) . "\n";
|
||||
}
|
||||
|
||||
@touch($result_file);
|
||||
}
|
||||
|
||||
function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit = true)
|
||||
|
@ -201,7 +199,7 @@ function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit =
|
|||
function bhl_clean()
|
||||
{
|
||||
bhl_clean_cache();
|
||||
bhl_shell_ensure("clean");
|
||||
bhl_shell("clean", $ret, $out);
|
||||
}
|
||||
|
||||
function bhl_clean_cache()
|
||||
|
@ -264,28 +262,30 @@ 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}'");
|
||||
|
||||
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
||||
|
||||
$module_chunks = array();
|
||||
if($namespace)
|
||||
{
|
||||
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
||||
if(count($ns_chunks) == 0)
|
||||
throw new Exception("No namespaces found in '$module_file'");
|
||||
if(!isset($ns_chunks[$namespace]))
|
||||
throw new Exception("No namespace '$namespace' found in '$module_file'");
|
||||
|
||||
foreach($ns_chunks as $ns => $ns_src)
|
||||
{
|
||||
if($ns === $namespace)
|
||||
$module_chunks[] = $ns_src;
|
||||
}
|
||||
|
||||
if(count($module_chunks) == 0)
|
||||
throw new Exception("Namespace '$namespace' for func '$func_full_name' not found in '$module_file'");
|
||||
foreach($ns_chunks[$namespace] as $ns_src)
|
||||
$module_chunks[] = $ns_src;
|
||||
}
|
||||
else
|
||||
$module_chunks[] = $module_src;
|
||||
{
|
||||
if(!isset($ns_chunks['']))
|
||||
throw new Exception("No global namespace found in '$module_file'");
|
||||
|
||||
foreach($ns_chunks[''] as $ns_src)
|
||||
$module_chunks[] = $ns_src;
|
||||
}
|
||||
|
||||
$signature_pattern = '';
|
||||
$signature_pattern .= '~func\s+';
|
||||
|
@ -317,6 +317,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();
|
||||
|
@ -330,11 +347,18 @@ function _bhl_split_by_namespaces(string $src) : array
|
|||
{
|
||||
$ns = trim(substr(ltrim($chunk), 9));
|
||||
$body = $chunks[$i+1];
|
||||
$nss[$ns] = $body;
|
||||
if(!isset($nss[$ns]))
|
||||
$nss[$ns] = array();
|
||||
$nss[$ns][] = $body;
|
||||
$i+=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!isset($nss['']))
|
||||
$nss[''] = array();
|
||||
$nss[''][] = $chunk;
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
|
||||
return $nss;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
namespace metagen_php;
|
||||
use Exception;
|
||||
|
||||
function flt_bhl_ref($val, $name, $struct, $str_args)
|
||||
function flt_bhl_ref($val, $name, $data, $str_args)
|
||||
{
|
||||
if(!$val)
|
||||
return $val;
|
||||
|
|
Loading…
Reference in New Issue