diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-12-31 01:37:24 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-12-31 01:38:23 -0800 |
| commit | 6edf6a275574cf8c3cb6a7015e22d0c982e2e489 (patch) | |
| tree | 00626e989a2878501c9bfd340cd3b4db2a07e8e4 /nomsu.lua | |
| parent | 7762c8c45b6f0349d769682b26349fb25a7a8657 (diff) | |
Overhaul of command line argument parsing. Now supports "-abc" as 3
flags, and stores them as .a, .b, .c instead of ."-a", etc. (same for
--args)
Diffstat (limited to 'nomsu.lua')
| -rw-r--r-- | nomsu.lua | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -110,17 +110,25 @@ local parser = re.compile([[ args <- {| (flag %sep)* / {~ '' %sep? -> 'nomsu://tools/repl.nom' ~}) |} :}) {:nomsu_args: {| (nomsu_flag %sep)* {:extras: {| ({[^%sep]+} %sep)* |} :} |} :} |} !. - flag <- - {:optimization: "-O" (%sep? %number)? :} - / ({:check_syntax: "-s" %true:}) - / ({:compile: "-c" %true:}) - / {:verbose: "-v" %true :} - / {:help: ("-h" / "--help") %true :} + + flag <- longflag / shortflag / "-" shortboolflag+ + longflag <- + {:help: "--help" %true :} / {:version: "--version" %true :} / {:no_core: "--no-core" %true :} - / {:debugger: ("-d" %sep? {[^%sep]*}) :} - / {:requested_version: "-V" (%sep? {([0-9.])+})? :} - nomsu_flag <- {| ({:key: ('-' [a-z]) :} {:value: %true :}) / ({:key: ('--' [^%sep=]+) :} {:value: ('=' {[^%sep]+}) / %true :}) |} + shortflag <- + {:optimization: "-O" %sep? %number :} + / {:debugger: ("-d" %sep? {[^%sep]+}) :} + / {:requested_version: "-V" %sep? {([0-9.])+} :} + shortboolflag <- + {:check_syntax: "s" %true:} + / {:compile: "c" %true:} + / {:verbose: "v" %true :} + / {:help: "h" %true :} + + nomsu_flag <- nomsu_longflag / "-" nomsu_shortboolflag+ + nomsu_shortboolflag <- {| {:key: [a-zA-Z] :} {:value: %true :} |} + nomsu_longflag <- '--' {| {:key: [^%sep=]+ :} {:value: ('=' {[^%sep]+}) / %true :} |} ]], { ["true"] = lpeg.Cc(true), number = lpeg.R("09") ^ 1 / tonumber, |
