From 6edf6a275574cf8c3cb6a7015e22d0c982e2e489 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 31 Dec 2018 01:37:24 -0800 Subject: 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) --- nomsu.lua | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'nomsu.lua') diff --git a/nomsu.lua b/nomsu.lua index 266a4a4..e410bec 100644 --- a/nomsu.lua +++ b/nomsu.lua @@ -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, -- cgit v1.2.3