mirror of
https://github.com/RubyMetric/chsrc
synced 2025-07-19 06:09:37 +08:00
Add run.ps1
This commit is contained in:
parent
a63af77e02
commit
2c2befd950
@ -99,7 +99,10 @@ my class CVariableGenerator {
|
|||||||
has @.variables;
|
has @.variables;
|
||||||
has $.c-header-filename;
|
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([]));
|
self.bless(:$c-header-filename, :variables([]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,11 +186,11 @@ class Generator {
|
|||||||
has $.varname-generator;
|
has $.varname-generator;
|
||||||
has $.variable-generator;
|
has $.variable-generator;
|
||||||
|
|
||||||
method new($output-file = 'rawstr4c.h') {
|
method new() {
|
||||||
self.bless(
|
self.bless(
|
||||||
:cstring-converter(CStringConverter.new()),
|
:cstring-converter(CStringConverter.new),
|
||||||
:varname-generator(CVariableNameGenerator.new()),
|
:varname-generator(CVariableNameGenerator.new),
|
||||||
:variable-generator(CVariableGenerator.new($output-file))
|
:variable-generator(CVariableGenerator.new)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +205,7 @@ class Generator {
|
|||||||
my $section-config = $section<config>;
|
my $section-config = $section<config>;
|
||||||
my $title = $section<title>;
|
my $title = $section<title>;
|
||||||
my $code = $section<raw-string>;
|
my $code = $section<raw-string>;
|
||||||
|
my $debug-parser = $global-config.get('debug', False).as-bool();
|
||||||
|
|
||||||
return unless $code;
|
return unless $code;
|
||||||
|
|
||||||
@ -215,13 +219,15 @@ class Generator {
|
|||||||
|
|
||||||
my $output-mode = $global-config.get('output', ':terminal').as-mode();
|
my $output-mode = $global-config.get('output', ':terminal').as-mode();
|
||||||
|
|
||||||
say "Variable name: $var-name";
|
if $debug-parser {
|
||||||
say "Translation mode: $translate-mode";
|
say "Variable name: $var-name";
|
||||||
say "Output mode: $output-mode";
|
say "Translation mode: $translate-mode";
|
||||||
|
say "Output mode: $output-mode";
|
||||||
|
|
||||||
my $language = $section-config.get('language', 'None').as-string();
|
my $language = $section-config.get('language', 'None').as-string();
|
||||||
say "Language: $language";
|
say "Language: $language";
|
||||||
say '';
|
say '';
|
||||||
|
}
|
||||||
|
|
||||||
my $c-string = $.cstring-converter.convert-string($code, $translate-mode);
|
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;
|
my $global-config = $parser.global-config;
|
||||||
|
|
||||||
# 这个 generate-for-section() 要么把变量输出到终端,要么累计到 @variabels 中
|
# 这个 generate-for-section() 要么把变量输出到终端,要么累计到 @variabels 中
|
||||||
|
@ -78,6 +78,8 @@ my class Config {
|
|||||||
|
|
||||||
has %.items;
|
has %.items;
|
||||||
|
|
||||||
|
# 如果非要在程序内部中调用,而不是直接从 Markdown 文件中读取出来
|
||||||
|
# 一定要记得 $raw-value 用的是 rawstr4c 的语法!也就是说,这里一定是一个字符串
|
||||||
method set($k, $raw-value) {
|
method set($k, $raw-value) {
|
||||||
%.items{$k} = ConfigValue.new($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:";
|
say "Global config:";
|
||||||
for $.global-config.keys.sort -> $item {
|
for $.global-config.keys.sort -> $item {
|
||||||
my $value = $.global-config.get($item);
|
my $value = $.global-config.get($item);
|
||||||
@ -231,6 +234,9 @@ class Parser {
|
|||||||
}
|
}
|
||||||
say "";
|
say "";
|
||||||
|
|
||||||
|
# 设置debug标志,后续在 Generator 中根据此信息输出 section config
|
||||||
|
$.global-config.set('debug', "true");
|
||||||
|
|
||||||
say "Found " ~ @.sections.elems ~ " sections:";
|
say "Found " ~ @.sections.elems ~ " sections:";
|
||||||
for @.sections -> $section {
|
for @.sections -> $section {
|
||||||
say "Section: " ~ $section<title>;
|
say "Section: " ~ $section<title>;
|
||||||
|
20
rawstr4c/run.ps1
Normal file
20
rawstr4c/run.ps1
Normal 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
|
Loading…
x
Reference in New Issue
Block a user