mirror of
https://github.com/RubyMetric/chsrc
synced 2025-07-21 15:49:35 +08:00
Implement namespace
This commit is contained in:
parent
a8c82a7476
commit
f26817f433
@ -62,9 +62,7 @@ class SectionConfig {
|
|||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
# 返回当前 section 的 各种配置
|
# 返回当前 section 的 各种配置
|
||||||
# 注意,这些函数仅仅忠实地要么返回层次化值,要么返回自己configblock的值,要么返回一个默认值
|
# 注意,这些函数全部都返回 ConfigValue's-Value 实例
|
||||||
# 从不考虑 section 其他部分对配置的影响
|
|
||||||
# 对 section 其他部分的考虑是 Generator 的职责
|
|
||||||
|
|
||||||
#| RS4C-Mode
|
#| RS4C-Mode
|
||||||
method translate-mode() {
|
method translate-mode() {
|
||||||
@ -111,6 +109,28 @@ class SectionConfig {
|
|||||||
return self.get-direct-config('name-literally', 'false');
|
return self.get-direct-config('name-literally', 'false');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# RS4C-String
|
||||||
|
method namespace() {
|
||||||
|
my $config-namespace = self.get-direct-config('namespace', '');
|
||||||
|
|
||||||
|
my $current-namespace = $config-namespace.string-value;
|
||||||
|
|
||||||
|
# 嵌套增加
|
||||||
|
my $parent = $.section.parent;
|
||||||
|
while $parent {
|
||||||
|
if $parent.configblock.exist('namespace') {
|
||||||
|
$current-namespace = $parent.configblock.get('namespace').string-value ~ $current-namespace;
|
||||||
|
} else {
|
||||||
|
# 空字符串
|
||||||
|
$current-namespace = '' ~ $current-namespace;
|
||||||
|
}
|
||||||
|
$parent = $parent.parent;
|
||||||
|
}
|
||||||
|
return Parser::ConfigItem's-Value.new($current-namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#| RS4C-Bool
|
#| RS4C-Bool
|
||||||
method debug() {
|
method debug() {
|
||||||
return self.get-inherited-config('debug', 'false');
|
return self.get-inherited-config('debug', 'false');
|
||||||
|
@ -85,6 +85,7 @@ my class CVariableNameGenerator {
|
|||||||
$name = $config-name.string-value;
|
$name = $config-name.string-value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $namespace = $config.namespace.string-value;
|
||||||
my $name-literally = $config.name-literally.bool-value;
|
my $name-literally = $config.name-literally.bool-value;
|
||||||
|
|
||||||
# 替换非法字符
|
# 替换非法字符
|
||||||
@ -102,8 +103,13 @@ my class CVariableNameGenerator {
|
|||||||
} else {
|
} else {
|
||||||
# 否则,按照规则组装变量名
|
# 否则,按照规则组装变量名
|
||||||
$varname ~= $prefix if $keep-prefix && $prefix;
|
$varname ~= $prefix if $keep-prefix && $prefix;
|
||||||
|
|
||||||
|
$varname ~= "_" if $varname && $namespace;
|
||||||
|
$varname ~= $namespace if $namespace;
|
||||||
|
|
||||||
$varname ~= "_" if $varname && $name;
|
$varname ~= "_" if $varname && $name;
|
||||||
$varname ~= $name if $name;
|
$varname ~= $name if $name;
|
||||||
|
|
||||||
$varname ~= "_" if $varname && $postfix && $keep-postfix;
|
$varname ~= "_" if $varname && $postfix && $keep-postfix;
|
||||||
$varname ~= $postfix if $postfix && $keep-postfix;
|
$varname ~= $postfix if $postfix && $keep-postfix;
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,7 @@ class ConfigItem's-Value {
|
|||||||
|
|
||||||
|
|
||||||
#| 包含所有 config items 的容器
|
#| 包含所有 config items 的容器
|
||||||
|
#| 所有 get 出的值一定是 ConfigItem's-Value 实例
|
||||||
my class ConfigBlock {
|
my class ConfigBlock {
|
||||||
|
|
||||||
has %!items;
|
has %!items;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user