aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-12-30 19:04:34 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-12-30 19:04:45 -0800
commit8a3c32408733a2f5e14f8a2dbafa3f980b2f73a1 (patch)
tree68f1e8a8b956c33ed24cc7a6a369fd97b8849321 /tools
parent359152da1772ce501609edd8f84b4985ed3e42f2 (diff)
Update to new syntax.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/find.nom74
-rwxr-xr-xtools/format.nom14
-rwxr-xr-xtools/parse.nom2
-rw-r--r--tools/repl.nom20
-rwxr-xr-xtools/test.nom15
-rwxr-xr-xtools/upgrade.nom12
6 files changed, 66 insertions, 71 deletions
diff --git a/tools/find.nom b/tools/find.nom
index 4d0c29e..d2678d2 100755
--- a/tools/find.nom
+++ b/tools/find.nom
@@ -1,20 +1,20 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
This is a tool to find syntax trees matching a pattern. "*" is a wildcard
that will match any subtree, and "**" is a wildcard that will match any
0 or more subtrees. "**" is greedy, so extra arguments after it will
not match.
-
- nomsu -t find [flags] "* squared" file1 file2...
-
+
+ nomsu -t find [flags] "* squared" file1 file2...
+
Flags:
- -l List only the names of the files with matches
- --wildcard=<wildcard> Specify a custom wildcard (in case you need to
- match an action with a "*" in the name)
-
+ -l List only the names of the files with matches
+ --wildcard=<wildcard> Specify a custom wildcard (in case you need to
+ match an action with a "*" in the name)
+
Output:
- <filename>:<line number>:
- <matching lines>
+ <filename>:<line number>:
+ <matching lines>
use "lib/os.nom"
use "lib/consolecolor.nom"
@@ -25,48 +25,32 @@ $wildcard = ($(COMMAND LINE ARGS)."--wildcard" or "%*")
$pattern = $(COMMAND LINE ARGS).extras.1
if (any of [not $pattern, $pattern == "*", $pattern == "**"]):
barf "Usage: nomsu -t find [-l] [--wildcard=<wildcard>] <pattern>, where <pattern> is valid Nomsu code"
-
-$pattern = ($pattern|with "\$wildcard\$wildcard" -> "$multi_wildcard")
-$pattern = ($pattern|with $wildcard -> "$wildcard")
+$pattern = ($pattern, with "\$wildcard\$wildcard" -> "$multi_wildcard")
+$pattern = ($pattern, with $wildcard -> "$wildcard")
$pattern_tree = ($pattern parsed)
-
($tree matches $patt) means:
when:
- (not ($tree is syntax tree)):
- return (no)
-
- (($patt.type == "Var") and ($patt.1 == "wildcard")):
- return (yes)
-
- ($tree.type != $patt.type):
- return (no)
-
+ (not ($tree is syntax tree)): return (no)
+ (($patt.type == "Var") and ($patt.1 == "wildcard")): return (yes)
+ ($tree.type != $patt.type): return (no)
($tree.type == "Action"):
- if (($tree|get stub) != ($patt|get stub)):
- return (no)
-
+ if (($tree, get stub) != ($patt, get stub)): return (no)
+
for $ in 1 to (#$patt):
if ($patt.$ is syntax tree):
- if ($patt.$ == \$multi_wildcard):
- return (yes)
-
- unless ($tree.$ matches $patt.$):
- return (no)
+ if ($patt.$ == \$multi_wildcard): return (yes)
+ unless ($tree.$ matches $patt.$): return (no)
..else:
- unless ($tree.$ == $patt.$):
- return (no)
-
- if ((#$tree) != (#$patt)):
- return (no)
-
+ unless ($tree.$ == $patt.$): return (no)
+
+ if ((#$tree) != (#$patt)): return (no)
return (yes)
-
-$filenames = ($(COMMAND LINE ARGS).extras|from 2 to -1)
+$filenames = ($(COMMAND LINE ARGS).extras, from 2 to -1)
if ((#$filenames) == 0):
say "Warning: searching stdin (ctrl-d to abort). To avoid this message, use nomsu -t find -"
$filenames = ["stdin"]
-for $filename in ($filenames):
+for $filename in $filenames:
$file = (read file $filename)
unless $file:
barf "File does not exist: \$filename"
@@ -83,15 +67,15 @@ for $filename in ($filenames):
$results = []
for $t in recursive $tree:
if ($t matches $pattern_tree):
- $line_num = ($file|line number at $t.source.start)
- $results|
- add {line: $line_num, text: "\(blue "\$filename:\$line_num:")\n\(source lines of $t)"}
+ $line_num = ($file, line number at $t.source.start)
+ $results,
+ add {.line = $line_num, .text = "\(blue "\$filename:\$line_num:")\n\(source lines of $t)"}
for $sub in $t:
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 0f09834..76c4981 100755
--- a/tools/format.nom
+++ b/tools/format.nom
@@ -1,8 +1,8 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
Auto-format Nomsu code. Usage:
- nomsu -t format [-i] file1 file2...
-
+ nomsu -t format [-i] file1 file2...
+
If the "-i" flag is used, the file will be edited in-place.
If no files are passed in, this will read from stdin.
@@ -19,7 +19,7 @@ for $filename in $filenames:
$file = (read file $filename)
unless $file:
barf "File does not exist: \$filename"
- $leading_indent = ($file|matching "[\n]*([ ]*)")
+ $leading_indent = ($file, matching "[\n]*([ ]*)")
$code = (NomsuCode from ($Source $filename 1 (size of $file)) $file)
try:
$tree = ($code parsed)
@@ -28,10 +28,10 @@ for $filename in $filenames:
$formatted = $file
..else:
say $msg
-
+
if ($tree and (not $formatted)):
- $formatted = "
- \$leading_indent\((($tree as nomsu)|text)|with "\n" -> "\n\$leading_indent")"
+ $formatted =
+ .."\$leading_indent\($tree as nomsu, text, with "\n" -> "\n\$leading_indent")"
if $formatted:
if $(COMMAND LINE ARGS)."-i":
diff --git a/tools/parse.nom b/tools/parse.nom
index 1005983..1f87bab 100755
--- a/tools/parse.nom
+++ b/tools/parse.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
Tool to print out a parse tree of files in an easy-to-read format. Usage:
nomsu tools/parse.nom file1 file2 directory1 ...
diff --git a/tools/repl.nom b/tools/repl.nom
index 3f1eff3..49a4d3d 100644
--- a/tools/repl.nom
+++ b/tools/repl.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
This file defines a Read-Evaluate-Print-Loop (REPL) for Nomsu
@@ -9,16 +9,18 @@ use "lib/os.nom"
externally [quit, exit] all mean: lua> "os.exit(0)"
externally (help) means:
- say "
+ say ("
This is the Nomsu v\(Nomsu version) interactive console.
You can type in Nomsu code here and hit 'enter' twice to run it.
- To exit, type 'exit' or 'quit' and hit enter twice."
+ To exit, type 'exit' or 'quit' and hit enter twice.
+ ")
-say "
+say ("
\(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\(reset color)
press 'enter' twice to run a command
- "
+
+")
repeat:
say (bright (yellow ">> ")) inline
@@ -32,11 +34,13 @@ repeat:
# clear the line
say "\027[1A\027[2K" inline
go to (run buffer)
- $buff|add ($line|with "\t" -> " ")
+ $buff, add ($line, with "\t" -> " ")
say (dim (yellow ".. ")) inline
+
--- (run buffer) ---
+
if ((size of $buff) == 0): stop
- $buff = ($buff|joined)
+ $buff = ($buff, joined)
# TODO: support local variables
spoof file $buff
@@ -53,7 +57,7 @@ repeat:
"table":
if $ret.as_nomsu:
- say "= \($ret|as nomsu)"
+ say "= \($ret, as nomsu)"
..else:
say "= \$ret"
diff --git a/tools/test.nom b/tools/test.nom
index 7b5842c..0202675 100755
--- a/tools/test.nom
+++ b/tools/test.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
Tool to run all tests in a file (i.e. the code block inside a call to 'test %'). Usage:
nomsu tools/test.nom file1 file2 directory1 ...
@@ -13,21 +13,26 @@ for $filename in $(COMMAND LINE ARGS).extras: use $filename
$tests = {: for $s = $t in $TESTS: add (=lua "Source:from_string(\$s)") = $t}
for $filename in $(COMMAND LINE ARGS).extras:
$file = (read file $filename)
- $version = ($file|matching "#![^\n]* nomsu %-V[ ]*([^\n]*)")
+ $version = ($file, matching "#![^\n]* nomsu %-V[ ]*([^\n]*)")
$file_tests = []
for $src = $test in $tests:
if ($src.filename == $filename):
if $version:
- $test = "#!/usr/bin/env nomsu -V\$version\n\$test"
- $file_tests|add {test: $test, source: $src}
+ $test = ("
+ #!/usr/bin/env nomsu -V\$version
+ \$test
+ ")
+ $file_tests, add {.test = $test, .source = $src}
unless ($file_tests is empty):
sort $file_tests by $ -> $.source
lua> "io.write('[ .. ] ', \$filename); io.flush()"
+
if (command line args)."-v": say ""
+
for $ in $file_tests:
if (command line args)."-v":
- say " \(yellow ($.test|with "\n" -> "\n "))"
+ say " \(yellow ($.test, with "\n" -> "\n "))"
run $.test
if (command line args)."-v":
diff --git a/tools/upgrade.nom b/tools/upgrade.nom
index 96a1312..f335dc0 100755
--- a/tools/upgrade.nom
+++ b/tools/upgrade.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
Tool to automatically update code from old versions of Nomsu. Usage:
nomsu tools/upgrade.nom [-i] file1 file2 directory1 ...
@@ -19,13 +19,15 @@ for $filename in $(COMMAND LINE ARGS).extras:
$file = (read file $filename)
unless $file:
barf "File does not exist: \$filename"
- $leading_indent = ($file|matching "[\n]*([ ]*)")
+ $leading_indent = ($file, matching "[\n]*([ ]*)")
$code = (NomsuCode from (Source $filename 1 (size of $file)) $file)
$tree = ($code parsed $start_version)
- $uptree = (..)
- $tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to \
+ $uptree =
+ $tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to
..$version
- $text = "\$leading_indent\((($uptree as nomsu)|text)|with "\n" -> "\n\$leading_indent")"
+
+ $text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")"
+
when:
$inplace:
say "Upgraded \$filename"