Debug Generator

This commit is contained in:
Aoran Zeng 2025-07-16 22:35:09 +08:00
parent e0396164ac
commit 174ba78f0d
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
2 changed files with 19 additions and 23 deletions

View File

@ -39,7 +39,7 @@ my class CStringConverter {
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 $prefix = $config.prefix.string-value;
my $language = $config.language.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 $postfix = $config.postfix.string-value;
my $keep-prefix = $config.keep-prefix.bool-value;
my $keep-postfix = $config.keep-postfix.bool-value;
@ -208,6 +198,7 @@ my class CVariableGenerator {
class Generator {
has Bool $!enable-debug = False; # 是否启用调试模式
has Parser::Parser $.parser;
has CStringConverter $.string-converter;
has CVariableNameGenerator $.varname-generator;
@ -222,6 +213,9 @@ class Generator {
);
}
method debug() {
$!enable-debug = True;
}
method generate-for-section($section) {
my $configblock = $section.configblock;
@ -230,23 +224,25 @@ class Generator {
my $config = Config::SectionConfig.new($section);
my $debug-config = $config.debug.bool-value;
my $debug-in-config = $config.debug.bool-value;
return unless $rawstr;
my $translate-mode = $config.translate-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);
if $debug-config {
say "--- Section: $title ---";
if $debug-in-config || $!enable-debug {
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 "Translation mode = $translate-mode";
say "Translate mode = $translate-mode";
say "Language = $language";
say "Prefix = $prefix";
say "Postfix = $postfix";
say "Variable name = $varname";
say '';
}

View File

@ -300,7 +300,7 @@ class Parser {
# 调试方法扁平打印所有sections
method debug-print-sections-flatly() {
say "====== sections ======";
say "====== Sections ======";
for @!sections.kv -> $i, $section {
my $title = $section.title || "(Root)";
my $has-config = $section.configblock.keys ?? "" !! "";
@ -311,7 +311,7 @@ class Parser {
# 调试方法层级打印sections
method debug-print-sections-hierarchyly() {
say "====== hierarchy ======";
say "====== Hierarchy ======";
my $indent = 0;
@ -349,7 +349,7 @@ class Parser {
}
# 调试方法:完整的调试信息打印
method debug-print-summary() {
method debug() {
self.debug-print-sections-flatly();
self.debug-print-sections-hierarchyly();
}