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