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