mirror of
https://github.com/RubyMetric/chsrc
synced 2025-07-21 23:59:33 +08:00
Debug Generator
This commit is contained in:
parent
e0396164ac
commit
174ba78f0d
@ -39,7 +39,7 @@ my class CStringConverter {
|
|||||||
default { return $char; }
|
default { return $char; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default { die "Unknown translation mode: $mode"; }
|
default { die "Unknown translate mode: $mode"; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,17 +61,7 @@ my class CVariableNameGenerator {
|
|||||||
my $config = Config::SectionConfig.new($section);
|
my $config = Config::SectionConfig.new($section);
|
||||||
|
|
||||||
my $prefix = $config.prefix.string-value;
|
my $prefix = $config.prefix.string-value;
|
||||||
my $language = $config.language.string-value;
|
my $postfix = $config.postfix.string-value;
|
||||||
|
|
||||||
my $postfix;
|
|
||||||
|
|
||||||
my $config-postfix = $config.postfix;
|
|
||||||
if $config-postfix.is-mode() && $config-postfix.mode-value() eq 'use-language' {
|
|
||||||
$postfix = $language ?? 'in_' ~ $language !! '';
|
|
||||||
} else {
|
|
||||||
# 如果不是模式,那就是用户给了一个具体的字符串
|
|
||||||
$postfix = $config-postfix.string-value();
|
|
||||||
}
|
|
||||||
|
|
||||||
my $keep-prefix = $config.keep-prefix.bool-value;
|
my $keep-prefix = $config.keep-prefix.bool-value;
|
||||||
my $keep-postfix = $config.keep-postfix.bool-value;
|
my $keep-postfix = $config.keep-postfix.bool-value;
|
||||||
@ -208,6 +198,7 @@ my class CVariableGenerator {
|
|||||||
|
|
||||||
class Generator {
|
class Generator {
|
||||||
|
|
||||||
|
has Bool $!enable-debug = False; # 是否启用调试模式
|
||||||
has Parser::Parser $.parser;
|
has Parser::Parser $.parser;
|
||||||
has CStringConverter $.string-converter;
|
has CStringConverter $.string-converter;
|
||||||
has CVariableNameGenerator $.varname-generator;
|
has CVariableNameGenerator $.varname-generator;
|
||||||
@ -222,6 +213,9 @@ class Generator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
method debug() {
|
||||||
|
$!enable-debug = True;
|
||||||
|
}
|
||||||
|
|
||||||
method generate-for-section($section) {
|
method generate-for-section($section) {
|
||||||
my $configblock = $section.configblock;
|
my $configblock = $section.configblock;
|
||||||
@ -230,23 +224,25 @@ class Generator {
|
|||||||
|
|
||||||
my $config = Config::SectionConfig.new($section);
|
my $config = Config::SectionConfig.new($section);
|
||||||
|
|
||||||
my $debug-config = $config.debug.bool-value;
|
my $debug-in-config = $config.debug.bool-value;
|
||||||
|
|
||||||
return unless $rawstr;
|
return unless $rawstr;
|
||||||
|
|
||||||
my $translate-mode = $config.translate-mode.mode-value;
|
my $translate-mode = $config.translate-mode.mode-value;
|
||||||
my $output-mode = $config.output-mode.mode-value;
|
my $output-mode = $config.output-mode.mode-value;
|
||||||
my $language = $config.language.string-value;
|
|
||||||
my $prefix = $config.prefix.string-value;
|
|
||||||
|
|
||||||
my $varname = $.varname-generator.generate($section);
|
my $varname = $.varname-generator.generate($section);
|
||||||
|
|
||||||
if $debug-config {
|
if $debug-in-config || $!enable-debug {
|
||||||
say "--- Section: $title ---";
|
my $language = $config.language.string-value;
|
||||||
|
my $prefix = $config.prefix.string-value;
|
||||||
|
my $postfix = $config.postfix.string-value;
|
||||||
|
|
||||||
|
say "------ Section: $title ------";
|
||||||
say "Output mode = $output-mode";
|
say "Output mode = $output-mode";
|
||||||
say "Translation mode = $translate-mode";
|
say "Translate mode = $translate-mode";
|
||||||
say "Language = $language";
|
say "Language = $language";
|
||||||
say "Prefix = $prefix";
|
say "Prefix = $prefix";
|
||||||
|
say "Postfix = $postfix";
|
||||||
say "Variable name = $varname";
|
say "Variable name = $varname";
|
||||||
say '';
|
say '';
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ class Parser {
|
|||||||
|
|
||||||
# 调试方法:扁平打印所有sections
|
# 调试方法:扁平打印所有sections
|
||||||
method debug-print-sections-flatly() {
|
method debug-print-sections-flatly() {
|
||||||
say "====== sections ======";
|
say "====== Sections ======";
|
||||||
for @!sections.kv -> $i, $section {
|
for @!sections.kv -> $i, $section {
|
||||||
my $title = $section.title || "(Root)";
|
my $title = $section.title || "(Root)";
|
||||||
my $has-config = $section.configblock.keys ?? "有配置" !! "无配置";
|
my $has-config = $section.configblock.keys ?? "有配置" !! "无配置";
|
||||||
@ -311,7 +311,7 @@ class Parser {
|
|||||||
|
|
||||||
# 调试方法:层级打印sections
|
# 调试方法:层级打印sections
|
||||||
method debug-print-sections-hierarchyly() {
|
method debug-print-sections-hierarchyly() {
|
||||||
say "====== hierarchy ======";
|
say "====== Hierarchy ======";
|
||||||
|
|
||||||
my $indent = 0;
|
my $indent = 0;
|
||||||
|
|
||||||
@ -349,7 +349,7 @@ class Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 调试方法:完整的调试信息打印
|
# 调试方法:完整的调试信息打印
|
||||||
method debug-print-summary() {
|
method debug() {
|
||||||
self.debug-print-sections-flatly();
|
self.debug-print-sections-flatly();
|
||||||
self.debug-print-sections-hierarchyly();
|
self.debug-print-sections-hierarchyly();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user