Move files handler back to main

This commit is contained in:
Aoran Zeng 2025-07-16 03:12:05 +08:00
parent 66e5c1f7e0
commit 902a40bed7
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
2 changed files with 31 additions and 29 deletions

View File

@ -161,22 +161,9 @@ class Parser {
#| sections
has Section @!sections;
#| $path
method new($path) {
my $markdown-file;
if $path.IO.d {
$markdown-file = $path.IO.add("rawstr4c.md");
unless $markdown-file.e {
die "Error: No 'rawstr4c.md' file found in directory '$path'\n";
}
}
elsif $path.IO.f {
$markdown-file = $path.IO;
} else {
die "Error: '$path' is neither a file nor a directory\n";
}
self.bless(:input-file($markdown-file.Str));
#| $markdown-file markdown
method new($markdown-file) {
self.bless(:input-file($markdown-file));
}
# 获取根sectionlevel 0

View File

@ -7,43 +7,58 @@
# File Authors : Aoran Zeng <ccmywish@qq.com>
# Contributors : Nul None <nul@none.org>
# Created On : <2025-07-12>
# Last Modified : <2025-07-14>
# Last Modified : <2025-07-16>
#
# rawstr4c:
#
# Raw strings for C programming language
#
# Usage:
# rawstr4c <FILE.md> # 指定具体某文件名
# rawstr4c <DIR> # 使用某一目录寻找 rawstr4c.md 文件
#
# 要注意的是,该程序一次性只能处理唯一一个文件
# ---------------------------------------------------------------
use lib 'lib';
use Parser;
use Generator;
sub MAIN(
Str $input-path,
Bool :$debug = False #= --debug
) {
# 必须声明为可选,否则一直报奇怪的错
Str $input-path?,
Bool :$debug = False, #= --debug
Bool :$help #= --help
)
{
if $help || !$input-path {
print q:to/END/;
Usage: rawstr4c <FILE.md|DIR> [--debug]
Arguments:
FILE.md Process a specific markdown file
DIR Process rawstr4c.md file in the given directory
Options:
--debug Show debug information during processing
--help Show this help message
END
# exit($help ?? 0 !! 1);
exit(0);
}
my $markdown-file;
if $input-path.IO.d {
$markdown-file = $input-path.IO.add("rawstr4c.md");
unless $markdown-file.e {
die "Error: No 'rawstr4c.md' file found in directory '$input-path'\n";
die "Error: No 'rawstr4c.md' file found in directory '$input-path'";
}
}
elsif $input-path.IO.f {
$markdown-file = $input-path.IO;
} else {
die "Error: '$input-path' is neither a file nor a directory\n";
die "Error: '$input-path' is neither a file nor a directory";
}
my $parser = Parser::Parser.new($markdown-file);
my $parser = Parser::Parser.new($markdown-file.Str);
$parser.parse;
$parser.debug if $debug;
$parser.debug-print-summary if $debug;
Generator::Generator.new($parser).generate;
}