diff --git a/tool/rawstr4c/lib/Parser.rakumod b/tool/rawstr4c/lib/Parser.rakumod index 9b3d202..c7f7583 100644 --- a/tool/rawstr4c/lib/Parser.rakumod +++ b/tool/rawstr4c/lib/Parser.rakumod @@ -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)); } # 获取根section(level 0) diff --git a/tool/rawstr4c/rawstr4c.raku b/tool/rawstr4c/rawstr4c.raku index d8c7713..1dcf9e7 100644 --- a/tool/rawstr4c/rawstr4c.raku +++ b/tool/rawstr4c/rawstr4c.raku @@ -7,43 +7,58 @@ # File Authors : Aoran Zeng # Contributors : Nul None # Created On : <2025-07-12> -# Last Modified : <2025-07-14> +# Last Modified : <2025-07-16> # # rawstr4c: # # Raw strings for C programming language # -# Usage: -# rawstr4c # 指定具体某文件名 -# rawstr4c # 使用某一目录寻找 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 [--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; }