Skip to content

Commit 174ba78

Browse files
committed
Debug Generator
1 parent e039616 commit 174ba78

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

tool/rawstr4c/lib/Generator.rakumod

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ my class CStringConverter {
3939
default { return $char; }
4040
}
4141
}
42-
default { die "Unknown translation mode: $mode"; }
42+
default { die "Unknown translate mode: $mode"; }
4343
}
4444
}
4545

@@ -61,17 +61,7 @@ my class CVariableNameGenerator {
6161
my $config = Config::SectionConfig.new($section);
6262

6363
my $prefix = $config.prefix.string-value;
64-
my $language = $config.language.string-value;
65-
66-
my $postfix;
67-
68-
my $config-postfix = $config.postfix;
69-
if $config-postfix.is-mode() && $config-postfix.mode-value() eq 'use-language' {
70-
$postfix = $language ?? 'in_' ~ $language !! '';
71-
} else {
72-
# 如果不是模式,那就是用户给了一个具体的字符串
73-
$postfix = $config-postfix.string-value();
74-
}
64+
my $postfix = $config.postfix.string-value;
7565

7666
my $keep-prefix = $config.keep-prefix.bool-value;
7767
my $keep-postfix = $config.keep-postfix.bool-value;
@@ -208,6 +198,7 @@ my class CVariableGenerator {
208198

209199
class Generator {
210200

201+
has Bool $!enable-debug = False; # 是否启用调试模式
211202
has Parser::Parser $.parser;
212203
has CStringConverter $.string-converter;
213204
has CVariableNameGenerator $.varname-generator;
@@ -222,6 +213,9 @@ class Generator {
222213
);
223214
}
224215

216+
method debug() {
217+
$!enable-debug = True;
218+
}
225219

226220
method generate-for-section($section) {
227221
my $configblock = $section.configblock;
@@ -230,23 +224,25 @@ class Generator {
230224

231225
my $config = Config::SectionConfig.new($section);
232226

233-
my $debug-config = $config.debug.bool-value;
227+
my $debug-in-config = $config.debug.bool-value;
234228

235229
return unless $rawstr;
236230

237231
my $translate-mode = $config.translate-mode.mode-value;
238232
my $output-mode = $config.output-mode.mode-value;
239-
my $language = $config.language.string-value;
240-
my $prefix = $config.prefix.string-value;
241-
242233
my $varname = $.varname-generator.generate($section);
243234

244-
if $debug-config {
245-
say "--- Section: $title ---";
235+
if $debug-in-config || $!enable-debug {
236+
my $language = $config.language.string-value;
237+
my $prefix = $config.prefix.string-value;
238+
my $postfix = $config.postfix.string-value;
239+
240+
say "------ Section: $title ------";
246241
say "Output mode = $output-mode";
247-
say "Translation mode = $translate-mode";
242+
say "Translate mode = $translate-mode";
248243
say "Language = $language";
249-
say "Prefix = $prefix";
244+
say "Prefix = $prefix";
245+
say "Postfix = $postfix";
250246
say "Variable name = $varname";
251247
say '';
252248
}

tool/rawstr4c/lib/Parser.rakumod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class Parser {
300300

301301
# 调试方法:扁平打印所有sections
302302
method debug-print-sections-flatly() {
303-
say "====== sections ======";
303+
say "====== Sections ======";
304304
for @!sections.kv -> $i, $section {
305305
my $title = $section.title || "(Root)";
306306
my $has-config = $section.configblock.keys ?? "有配置" !! "无配置";
@@ -311,7 +311,7 @@ class Parser {
311311

312312
# 调试方法:层级打印sections
313313
method debug-print-sections-hierarchyly() {
314-
say "====== hierarchy ======";
314+
say "====== Hierarchy ======";
315315

316316
my $indent = 0;
317317

@@ -349,7 +349,7 @@ class Parser {
349349
}
350350

351351
# 调试方法:完整的调试信息打印
352-
method debug-print-summary() {
352+
method debug() {
353353
self.debug-print-sections-flatly();
354354
self.debug-print-sections-hierarchyly();
355355
}

0 commit comments

Comments
 (0)