diff --git a/rawstr4c/lib/Generator.rakumod b/rawstr4c/lib/Generator.rakumod index 0d24902..6941212 100644 --- a/rawstr4c/lib/Generator.rakumod +++ b/rawstr4c/lib/Generator.rakumod @@ -99,7 +99,10 @@ my class CVariableGenerator { has @.variables; has $.c-header-filename; - method new($c-header-filename = "rawstr4c.h") { + method new() { + + my $c-header-filename = "rawstr4c.h"; + self.bless(:$c-header-filename, :variables([])); } @@ -183,11 +186,11 @@ class Generator { has $.varname-generator; has $.variable-generator; - method new($output-file = 'rawstr4c.h') { + method new() { self.bless( - :cstring-converter(CStringConverter.new()), - :varname-generator(CVariableNameGenerator.new()), - :variable-generator(CVariableGenerator.new($output-file)) + :cstring-converter(CStringConverter.new), + :varname-generator(CVariableNameGenerator.new), + :variable-generator(CVariableGenerator.new) ); } @@ -202,6 +205,7 @@ class Generator { my $section-config = $section; my $title = $section; my $code = $section<raw-string>; + my $debug-parser = $global-config.get('debug', False).as-bool(); return unless $code; @@ -215,13 +219,15 @@ class Generator { my $output-mode = $global-config.get('output', ':terminal').as-mode(); - say "Variable name: $var-name"; - say "Translation mode: $translate-mode"; - say "Output mode: $output-mode"; + if $debug-parser { + say "Variable name: $var-name"; + say "Translation mode: $translate-mode"; + say "Output mode: $output-mode"; - my $language = $section-config.get('language', 'None').as-string(); - say "Language: $language"; - say ''; + my $language = $section-config.get('language', 'None').as-string(); + say "Language: $language"; + say ''; + } my $c-string = $.cstring-converter.convert-string($code, $translate-mode); @@ -243,7 +249,7 @@ class Generator { } - method generate-all($parser) { + method generate($parser) { my $global-config = $parser.global-config; # 这个 generate-for-section() 要么把变量输出到终端,要么累计到 @variabels 中 diff --git a/rawstr4c/lib/Parser.rakumod b/rawstr4c/lib/Parser.rakumod index 8c7aee7..7f172bc 100644 --- a/rawstr4c/lib/Parser.rakumod +++ b/rawstr4c/lib/Parser.rakumod @@ -78,6 +78,8 @@ my class Config { has %.items; + # 如果非要在程序内部中调用,而不是直接从 Markdown 文件中读取出来 + # 一定要记得 $raw-value 用的是 rawstr4c 的语法!也就是说,这里一定是一个字符串 method set($k, $raw-value) { %.items{$k} = ConfigValue.new($raw-value); } @@ -223,7 +225,8 @@ class Parser { } } - method debug-info() { + # 输出 config, 包含 global config 以及 section config + method debug() { say "Global config:"; for $.global-config.keys.sort -> $item { my $value = $.global-config.get($item); @@ -231,6 +234,9 @@ class Parser { } say ""; + # 设置debug标志,后续在 Generator 中根据此信息输出 section config + $.global-config.set('debug', "true"); + say "Found " ~ @.sections.elems ~ " sections:"; for @.sections -> $section { say "Section: " ~ $section<title>; diff --git a/rawstr4c/run.ps1 b/rawstr4c/run.ps1 new file mode 100644 index 0000000..5373e67 --- /dev/null +++ b/rawstr4c/run.ps1 @@ -0,0 +1,20 @@ +# --------------------------------------------------------------- +# File Name : run.ps1 +# File Authors : Aoran Zeng <ccmywish@qq.com> +# Contributors : Nul None <nul@none.org> +# Created On : <2025-07-12> +# Last Modified : <2025-07-13> +# +# Run rawstr4c script +# +# Usage: +# +# 用户必须在代码根目录中运行此文件 +# +# .\rawstr4c\run.ps1 [--debug] <Markdown.md> +# +# .\rawstr4c\run.ps1 [--debug] <Dir> +# --------------------------------------------------------------- + +# -I 选项必须在文件前面 +raku -I .\rawstr4c\lib .\rawstr4c\rawstr4c.raku $args