mirror of
https://github.com/RubyMetric/chsrc
synced 2025-07-15 19:58:07 +08:00
Fix generated files destination
This commit is contained in:
parent
64513e8d15
commit
bd45eff13c
@ -4,7 +4,7 @@
|
||||
# File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
# Contributors : Nul None <nul@none.org>
|
||||
# Created On : <2025-07-12>
|
||||
# Last Modified : <2025-07-13>
|
||||
# Last Modified : <2025-07-14>
|
||||
#
|
||||
# Generates C code from raw string
|
||||
# ---------------------------------------------------------------
|
||||
@ -121,7 +121,7 @@ my class CVariableGenerator {
|
||||
/**
|
||||
* Generated by rawstr4c
|
||||
*
|
||||
* Date: {DateTime.now.Str}
|
||||
* Date: {DateTime.now.Str}
|
||||
*/
|
||||
|
||||
EOF
|
||||
@ -146,14 +146,14 @@ my class CVariableGenerator {
|
||||
|
||||
method generate-c-source-file() {
|
||||
my $source = qq:to/EOF/;
|
||||
#include "{$.c-header-filename}"
|
||||
|
||||
/**
|
||||
* Generated by rawstr4c
|
||||
*
|
||||
* Date: {DateTime.now.Str}
|
||||
* Date: {DateTime.now.Str}
|
||||
*/
|
||||
|
||||
#include "{$.c-header-filename}"
|
||||
|
||||
EOF
|
||||
|
||||
for @.variables -> $var {
|
||||
@ -165,16 +165,21 @@ my class CVariableGenerator {
|
||||
return $source;
|
||||
}
|
||||
|
||||
method save-files($output-mode) {
|
||||
$.c-header-filename.IO.spurt(self.generate-c-header-file($output-mode));
|
||||
say "Generated C header file: $.c-header-filename";
|
||||
|
||||
method save-files($output-mode, $dest-dir) {
|
||||
|
||||
my $c-header-file = $dest-dir.IO.child($.c-header-filename).Str;
|
||||
|
||||
$c-header-file.IO.spurt(self.generate-c-header-file($output-mode));
|
||||
say "Generated C header file: $c-header-file";
|
||||
|
||||
if $output-mode eq 'global-variable' {
|
||||
my $has-globals = @.variables.grep({ $_<type> eq 'global-variable' }).elems > 0;
|
||||
if $has-globals {
|
||||
my $c-source-filename = $.c-header-filename.subst(/'.h'$/, '.c');
|
||||
$c-source-filename.IO.spurt(self.generate-c-source-file());
|
||||
say "Generated C source file: $c-source-filename";
|
||||
my $c-source-file = $dest-dir.IO.child($c-source-filename).Str;
|
||||
$c-source-file.IO.spurt(self.generate-c-source-file());
|
||||
say "Generated C source file: $c-source-file";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -261,7 +266,8 @@ class Generator {
|
||||
|
||||
# 最后把累计到 @variables 的内容输出到文件
|
||||
if $output-mode ne 'terminal' {
|
||||
$.variable-generator.save-files($output-mode);
|
||||
my $dest-dir = $parser.input-file.dirname.Str;
|
||||
$.variable-generator.save-files($output-mode, $dest-dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
# File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
# Contributors : Nul None <nul@none.org>
|
||||
# Created On : <2025-07-12>
|
||||
# Last Modified : <2025-07-13>
|
||||
# Last Modified : <2025-07-14>
|
||||
#
|
||||
# rawstr4c.md parsing
|
||||
# ---------------------------------------------------------------
|
||||
@ -107,8 +107,9 @@ my class Config {
|
||||
我们要求,在 Global dom 里,只存在配置,不存在 code block. 而 code block 只能在 Section dom 中存在。
|
||||
|
||||
因此,Parser 解析完毕后将包含:
|
||||
- $global-config
|
||||
- @sections (多个 $section)
|
||||
- IO::Path $input-file
|
||||
- Hash $global-config
|
||||
- @sections is Array[Hash] (多个 $section)
|
||||
|
||||
一个 $section 是 Hash,其包含:
|
||||
- title
|
||||
@ -117,11 +118,13 @@ my class Config {
|
||||
- config
|
||||
)
|
||||
class Parser {
|
||||
has $.input-file is rw;
|
||||
has $.global-config;
|
||||
has @.sections;
|
||||
|
||||
method new() {
|
||||
method new(:$input-file) {
|
||||
self.bless(
|
||||
:$input-file,
|
||||
global-config => Config.new(),
|
||||
sections => []
|
||||
);
|
||||
@ -139,7 +142,8 @@ class Parser {
|
||||
return False;
|
||||
}
|
||||
|
||||
method parse($content) {
|
||||
method parse() {
|
||||
my $content = $.input-file.slurp;
|
||||
my @lines = $content.lines;
|
||||
|
||||
my $current-section;
|
||||
|
@ -7,7 +7,7 @@
|
||||
# File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
# Contributors : Nul None <nul@none.org>
|
||||
# Created On : <2025-07-12>
|
||||
# Last Modified : <2025-07-13>
|
||||
# Last Modified : <2025-07-14>
|
||||
#
|
||||
# rawstr4c:
|
||||
#
|
||||
@ -41,11 +41,8 @@ sub MAIN(
|
||||
die "Error: '$input-path' is neither a file nor a directory\n";
|
||||
}
|
||||
|
||||
my $content = $markdown-file.IO.slurp;
|
||||
|
||||
my $parser = Parser::Parser.new();
|
||||
|
||||
$parser.parse($content);
|
||||
my $parser = Parser::Parser.new(input-file=>$markdown-file);
|
||||
$parser.parse;
|
||||
$parser.debug if $debug;
|
||||
|
||||
Generator::Generator.new.generate($parser);
|
||||
|
Loading…
x
Reference in New Issue
Block a user