Add run.ps1

This commit is contained in:
Aoran Zeng 2025-07-13 19:08:55 +08:00
parent a63af77e02
commit 2c2befd950
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
3 changed files with 45 additions and 13 deletions

View File

@ -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<config>;
my $title = $section<title>;
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 中

View File

@ -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>;

20
rawstr4c/run.ps1 Normal file
View File

@ -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