aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nomsu.lua26
-rwxr-xr-xnomsu.moon26
-rwxr-xr-xtools/find.nom4
-rwxr-xr-xtools/format.nom5
-rwxr-xr-xtools/test.nom6
-rwxr-xr-xtools/upgrade.nom8
6 files changed, 46 insertions, 29 deletions
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,
diff --git a/nomsu.moon b/nomsu.moon
index b8b64a7..6219b7b 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -69,17 +69,25 @@ parser = re.compile([[
/ {~ '' %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, sep:lpeg.P(sep)
})
diff --git a/tools/find.nom b/tools/find.nom
index d07681a..781ca3f 100755
--- a/tools/find.nom
+++ b/tools/find.nom
@@ -21,7 +21,7 @@ use "lib/consolecolor.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-$wildcard = ($(COMMAND LINE ARGS)."--wildcard" or "%*")
+$wildcard = ($(COMMAND LINE ARGS).wildcard or "%*")
$pattern = $(COMMAND LINE ARGS).extras.1
if (any of [not $pattern, $pattern == "*", $pattern == "**"]):
barf ("
@@ -84,7 +84,7 @@ for $filename in $filenames:
if ($sub is syntax tree):
recurse $t on $sub
- if $(COMMAND LINE ARGS)."-l":
+ if $(COMMAND LINE ARGS).l:
if ((#$results) > 0):
say $filename
..else:
diff --git a/tools/format.nom b/tools/format.nom
index 65cc2ca..df89635 100755
--- a/tools/format.nom
+++ b/tools/format.nom
@@ -4,6 +4,7 @@
nomsu -t format [-i] file1 file2...
If the "-i" flag is used, the file will be edited in-place.
+ If the "-q" flag is used and an error occurs, the original file will be printed.
If no files are passed in, this will read from stdin.
use "lib/os.nom"
@@ -26,7 +27,7 @@ for $filename in $filenames:
try:
$tree = ($code parsed)
..and if it barfs $msg:
- if $(COMMAND LINE ARGS)."-q":
+ if $(COMMAND LINE ARGS).q:
$formatted = $file
..else:
say $msg
@@ -36,7 +37,7 @@ for $filename in $filenames:
"\$leading_indent\($tree as nomsu, text, with "\n" -> "\n\$leading_indent")"
if $formatted:
- if $(COMMAND LINE ARGS)."-i":
+ if $(COMMAND LINE ARGS).i:
write $formatted to file $filename
..else:
say $formatted inline
diff --git a/tools/test.nom b/tools/test.nom
index 67afb96..d9e9269 100755
--- a/tools/test.nom
+++ b/tools/test.nom
@@ -33,14 +33,14 @@ for $filename in $(COMMAND LINE ARGS).extras:
sort $file_tests by $ -> $.source
lua> "io.write('[ .. ] ', \$filename); io.flush()"
- if (command line args)."-v": say ""
+ if (command line args).v: say ""
for $ in $file_tests:
- if (command line args)."-v":
+ if (command line args).v:
say " \(yellow ($.test, with "\n" -> "\n "))"
run $.test
- if (command line args)."-v":
+ if (command line args).v:
say (green "PASS")
..else:
say "\r[\(green "PASS")"
diff --git a/tools/upgrade.nom b/tools/upgrade.nom
index ccb12b5..5cf7d60 100755
--- a/tools/upgrade.nom
+++ b/tools/upgrade.nom
@@ -11,10 +11,10 @@ use "lib/consolecolor.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-$inplace = ($(COMMAND LINE ARGS)."-i" or $(COMMAND LINE ARGS)."--inplace")
-$start_version = $(COMMAND LINE ARGS)."--upgrade-from"
-$version = ($(COMMAND LINE ARGS)."--upgrade-to" or (Nomsu version))
-$test = ($(COMMAND LINE ARGS)."-t" or $(COMMAND LINE ARGS)."--test")
+$inplace = ($(COMMAND LINE ARGS).i or $(COMMAND LINE ARGS).inplace)
+$start_version = $(COMMAND LINE ARGS)."upgrade-from"
+$version = ($(COMMAND LINE ARGS)."upgrade-to" or (Nomsu version))
+$test = ($(COMMAND LINE ARGS).t or $(COMMAND LINE ARGS).test)
for $filename in $(COMMAND LINE ARGS).extras:
$file = (read file $filename)
unless $file: