Give Unknown if codeblock not specify

This commit is contained in:
Aoran Zeng 2025-07-16 21:02:44 +08:00
parent 2a27fd4fc1
commit 8259a5fd9a
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
2 changed files with 19 additions and 6 deletions

View File

@ -94,10 +94,23 @@ class SectionConfig {
return self.get-inherited-config('keep-postfix', 'true');
}
#| RS4C-String RS4C-Nil
#| RS4C-String
method language() {
return self.get-direct-config('language');
# RS4C-String 或 RS4C-Nil
my $config-language = self.get-direct-config('language');
my Str $lang;
if $config-language.is-nil {
# codeblock 没有写语言,就给 Unknown
$lang = 'Unknown';
} else {
$lang = $config-language.string-value;
}
return Parser::ConfigItem's-Value.new($lang);
}
#| RS4C-String
method name() {

View File

@ -70,22 +70,22 @@ class ConfigItem's-Value {
# 这些函数防止开发者写错类型
method nil-value() {
return self.value if $.type == RS4C-Nil;
die "The config value type is not RS4C-Nil, but: {$.type}";
die "The config value type should be RS4C-Nil, but it is: {$.type}";
}
method string-value() {
return self.value if $.type == RS4C-String;
die "The config value type is not RS4C-String, but: {$.type}";
die "The config value type should be RS4C-String, but it is: {$.type}";
}
method bool-value() {
return self.value if $.type == RS4C-Bool;
die "The config value type is not RS4C-Bool, but: {$.type}";
die "The config value type should be RS4C-Bool, but it is: {$.type}";
}
method mode-value() {
return self.value if $.type == RS4C-Mode;
die "The config value type is not RS4C-Mode, but: {$.type}";
die "The config value type should be RS4C-Mode, but it is: {$.type}";
}