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 #| sections
has Section @!sections; has Section @!sections;
#| $path #| $markdown-file markdown
method new($path) { method new($markdown-file) {
my $markdown-file; self.bless(:input-file($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));
} }
# 获取根sectionlevel 0 # 获取根sectionlevel 0

View File

@ -7,43 +7,58 @@
# 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-14> # Last Modified : <2025-07-16>
# #
# rawstr4c: # rawstr4c:
# #
# Raw strings for C programming language # Raw strings for C programming language
# #
# Usage:
# rawstr4c <FILE.md> # 指定具体某文件名
# rawstr4c <DIR> # 使用某一目录寻找 rawstr4c.md 文件
#
# 要注意的是,该程序一次性只能处理唯一一个文件
# --------------------------------------------------------------- # ---------------------------------------------------------------
use lib 'lib';
use Parser; use Parser;
use Generator; use Generator;
sub MAIN( 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; my $markdown-file;
if $input-path.IO.d { if $input-path.IO.d {
$markdown-file = $input-path.IO.add("rawstr4c.md"); $markdown-file = $input-path.IO.add("rawstr4c.md");
unless $markdown-file.e { 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 { elsif $input-path.IO.f {
$markdown-file = $input-path.IO; $markdown-file = $input-path.IO;
} else { } 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.parse;
$parser.debug if $debug; $parser.debug-print-summary if $debug;
Generator::Generator.new($parser).generate; Generator::Generator.new($parser).generate;
} }