More consitent naming

This commit is contained in:
Pavel Shevaev 2022-12-15 12:18:12 +03:00
parent 6373fb2fc7
commit 8f7ca8119a
1 changed files with 23 additions and 23 deletions

View File

@ -2,7 +2,7 @@
namespace bhl_bind;
use Exception;
function bhl_twig(array $inc_path = [])
function get_twig(array $inc_path = [])
{
array_unshift($inc_path, __DIR__ . "/../tpl/");
$loader = new \Twig\Loader\FilesystemLoader($inc_path);
@ -14,7 +14,7 @@ function bhl_twig(array $inc_path = [])
);
$twig->addExtension(new \Twig\Extension\DebugExtension());
bhl_add_twig_support($twig);
add_twig_support($twig);
return $twig;
}
@ -43,7 +43,7 @@ function supported_tokens()
];
}
function bhl_prepare_meta(\mtgMetaInfo $orig)
function prepare_meta(\mtgMetaInfo $orig)
{
//NOTE: making a deep clone
$meta = unserialize(serialize($orig));
@ -93,7 +93,7 @@ function bhl_prepare_meta(\mtgMetaInfo $orig)
return $meta;
}
function bhl_add_twig_support(\Twig\Environment $twig)
function add_twig_support(\Twig\Environment $twig)
{
$twig->addTest(new \Twig\TwigTest('instanceof',
function($obj, $class)
@ -104,37 +104,37 @@ function bhl_add_twig_support(\Twig\Environment $twig)
$twig->addFilter(new \Twig\TwigFilter('ns_last',
function($str)
{
return bhl_get_last_name($str);
return ns_last($str);
}
));
$twig->addFilter(new \Twig\TwigFilter('ns_prefix',
function($str)
{
return bhl_get_ns_prefix($str);
return ns_prefix($str);
}
));
$twig->addFilter(new \Twig\TwigFilter('bhl_type',
function($type)
{
return bhl_gen_type($type);
return bhl_type($type);
}
));
$twig->addFilter(new \Twig\TwigFilter('bhl_type_ref',
function($type)
{
return bhl_type_ref(is_string($type) ? $type : bhl_gen_type($type));
return bhl_type_ref(is_string($type) ? $type : bhl_type($type));
}
));
$twig->addFilter(new \Twig\TwigFilter('native_type',
function($type)
{
return bhl_gen_native_type($type);
return native_type($type);
}
));
$twig->addFilter(new \Twig\TwigFilter('norm_name',
function($name)
{
return bhl_normalize_name($name);
return norm_name($name);
}
));
$twig->addFilter(new \Twig\TwigFilter('rtrim_comma',
@ -223,18 +223,13 @@ function bhl_add_twig_support(\Twig\Environment $twig)
));
}
function bhl_get_last_name($name)
function ns_last($name)
{
$items = explode('.', $name);
return end($items);
}
function bhl_normalize_name($name)
{
return str_replace('.', '__', $name);
}
function bhl_get_ns_prefix($name)
function ns_prefix($name)
{
$items = explode('.', $name);
if(sizeof($items) == 1)
@ -247,6 +242,11 @@ function bhl_get_ns_prefix($name)
return $prefix;
}
function norm_name($name)
{
return str_replace('.', '__', $name);
}
function bhl_type_ref($type_str)
{
if(preg_match('~\[\]((\w|\.)+)~', $type_str, $ms))
@ -263,7 +263,7 @@ function bhl_type_ref($type_str)
return "types.T(\"$type_str\")";
}
function bhl_gen_type(\mtgType $type = null)
function bhl_type(\mtgType $type = null)
{
if($type === null)
return "void";
@ -282,7 +282,7 @@ function bhl_gen_type(\mtgType $type = null)
$str = "";
$str .= "func $ret_type(";
foreach($type->getArgs() as $arg)
$str .= bhl_gen_type($arg->getType()) . ",";
$str .= bhl_type($arg->getType()) . ",";
$str = rtrim($str, ',');
$str .= ")";
return $str;
@ -291,16 +291,16 @@ function bhl_gen_type(\mtgType $type = null)
{
$str = '';
foreach($type->getValues() as $sub_type)
$str .= bhl_gen_type($sub_type) . ",";
$str .= bhl_type($sub_type) . ",";
return rtrim($str, ",");
}
else if($type instanceof \mtgArrType)
return "[]" . bhl_gen_type($type->getValue());
return "[]" . bhl_type($type->getValue());
return ''.$type;
}
function bhl_gen_native_type(\mtgType $type)
function native_type(\mtgType $type)
{
//any special case
if($type == "any")
@ -311,7 +311,7 @@ function bhl_gen_native_type(\mtgType $type)
if($type->getValue()->getName() == "any")
return "bhl.ValList";
else
return "HList<".bhl_gen_native_type($type->getValue()).">";
return "HList<".native_type($type->getValue()).">";
}
//func special case