mirror of
https://github.com/RubyMetric/chsrc
synced 2025-07-22 16:19:34 +08:00
Little update
This commit is contained in:
parent
c4d0d1eb0e
commit
c3657b44ef
@ -13,13 +13,13 @@
|
|||||||
unit module Parser;
|
unit module Parser;
|
||||||
|
|
||||||
#| 不能用 Bool,只能用 Boolean
|
#| 不能用 Bool,只能用 Boolean
|
||||||
my enum ConfigValueType <String Mode Boolean>;
|
my enum ConfigItemValueType <String Mode Boolean>;
|
||||||
|
|
||||||
#| 配置项的值
|
#| 配置项的值
|
||||||
my class ConfigValue {
|
my class ConfigItemValue {
|
||||||
has ConfigValueType $.type;
|
has ConfigItemValueType $.type;
|
||||||
has Str $.raw-value;
|
has Str $.raw-value;
|
||||||
has Any $.parsed-value;
|
has Any $.parsed-value;
|
||||||
|
|
||||||
method new($raw-text) {
|
method new($raw-text) {
|
||||||
my $type;
|
my $type;
|
||||||
@ -77,32 +77,32 @@ my class ConfigValue {
|
|||||||
#| 包含所有 config items 的容器
|
#| 包含所有 config items 的容器
|
||||||
my class Config {
|
my class Config {
|
||||||
|
|
||||||
has %.items;
|
has %!items;
|
||||||
|
|
||||||
# 如果非要在程序内部中调用,而不是直接从 Markdown 文件中读取出来
|
# 如果非要在程序内部中调用,而不是直接从 Markdown 文件中读取出来
|
||||||
# 一定要记得 $raw-value 用的是 rawstr4c 的语法!也就是说,这里一定是一个字符串
|
# 一定要记得 $raw-value 用的是 rawstr4c 的语法!也就是说,这里一定是一个字符串
|
||||||
method set($k, $raw-value) {
|
method set($k, $raw-value) {
|
||||||
%.items{$k} = ConfigValue.new($raw-value);
|
%!items{$k} = ConfigItemValue.new($raw-value);
|
||||||
}
|
}
|
||||||
|
|
||||||
method get($k, $default = Nil) {
|
method get($k, $default = Nil) {
|
||||||
return %.items{$k} // ($default ?? ConfigValue.new($default) !! ConfigValue.new(''));
|
return %!items{$k} // ($default ?? ConfigItemValue.new($default) !! ConfigItemValue.new(''));
|
||||||
}
|
}
|
||||||
|
|
||||||
method exist($k) {
|
method exist($k) {
|
||||||
return %.items{$k}:exists;
|
return %!items{$k}:exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
# 配置项名称
|
# 配置项名称
|
||||||
# @danger: 把这个函数命名为 items,会让我的机器蓝屏.....
|
# @danger: 把这个函数命名为 items,会让我的机器蓝屏.....
|
||||||
method keys() {
|
method keys() {
|
||||||
return %.items.keys;
|
return %!items.keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#| 表示一个 section
|
#| 表示一个 section
|
||||||
class Section {
|
my class Section {
|
||||||
|
|
||||||
has Str $.title;
|
has Str $.title;
|
||||||
has Int $.level;
|
has Int $.level;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user