aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-22 13:59:08 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-22 13:59:08 -0700
commitdfd39f0b14794b360fd6c961c65ab45d229e00b1 (patch)
tree51f0c30ef3a32c969c63321da8164436a3ba8b31 /tools
parent01d5f810ed7fd6e9b261b1fe793f8666970b2068 (diff)
Shifting further towards having inline tests. Also added a helper
function for directly extracting source lines from a Source or AST.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/find_action.nom21
-rwxr-xr-xtools/parse.nom27
-rwxr-xr-xtools/test.nom31
3 files changed, 79 insertions, 0 deletions
diff --git a/tools/find_action.nom b/tools/find_action.nom
new file mode 100755
index 0000000..03bae54
--- /dev/null
+++ b/tools/find_action.nom
@@ -0,0 +1,21 @@
+#!/usr/bin/env nomsu -V2.5.4.3
+use "core"
+use "lib/os.nom"
+use "lib/consolecolor.nom"
+
+%stub = (command line args).1
+say "Looking for stub: \%stub (from \(command line args))"
+%files = ((command line args).% for % in 2 to (|| (command line args) ||))
+for %path in %files:
+ for file %filename in %path:
+ unless (%filename matches "%.nom$") (do next %filename)
+ %file = (read file %filename)
+ %tree = (parse %file from %filename)
+ for %t in recursive %tree:
+ if (%t is "Action" syntax tree) (..)
+ if (%t.stub is %stub):
+ %line_num = (line number of %t.source.start in %file)
+ say (blue "\%filename:\%line_num:")
+ say (yellow (source lines of %t))
+
+ if (%t is syntax tree) (for %sub in %t (recurse %t on %sub))
diff --git a/tools/parse.nom b/tools/parse.nom
new file mode 100755
index 0000000..68be3a8
--- /dev/null
+++ b/tools/parse.nom
@@ -0,0 +1,27 @@
+#!/usr/bin/env nomsu -V2.4.4.3
+use "core"
+use "lib/os.nom"
+action [print tree %t at indent %indent]:
+ if %t.type is:
+ "Action":
+ say "\(%indent)Action (\(%t.stub)):"
+ for %arg in %t:
+ if (%arg is syntax tree):
+ print tree %arg at indent "\%indent "
+ "Number":
+ say "\(%indent)\(%t.1)"
+ "Var":
+ say "\(%indent)%\(%t.1)"
+ else:
+ say "\(%indent)\(%t.type):"
+ for %arg in %t:
+ if:
+ (%arg is syntax tree):
+ print tree %arg at indent "\%indent "
+ else:
+ say "\%indent \(quote %arg)"
+
+for %path in (=lua "arg"):
+ for file %filename in %path:
+ unless (%filename matches "%.nom$"): do next %filename
+ print tree (parse (read file %filename) from %filename) at indent ""
diff --git a/tools/test.nom b/tools/test.nom
new file mode 100755
index 0000000..3d3329f
--- /dev/null
+++ b/tools/test.nom
@@ -0,0 +1,31 @@
+#!/usr/bin/env nomsu -V2.5.4.3
+use "core"
+use "lib/os.nom"
+use "lib/consolecolor.nom"
+
+%args = (command line args)
+if (%args.1 == "-v"):
+ remove index 1 from %args
+ %verbose = (yes)
+
+%tests = ((=lua "Source:from_string(\%s)") = %t for %s = %t in (tests))
+for %path in (command line args):
+ if (%path is "-i"): %inplace = (yes)
+ for file %filename in %path:
+ unless (%filename matches "%.nom$"): do next %filename
+ %file_tests = []
+ for %src = %test in %tests:
+ if (%src.filename == %filename):
+ add {test:%test, source:%src} to %file_tests
+ unless (%file_tests is empty):
+ sort %file_tests by % -> %.source
+ lua> "io.write('[ .. ] ', \%filename); io.flush()"
+ if %verbose: say ""
+ for % in %file_tests:
+ if %verbose:
+ say " \(yellow (%.test with "\n" replaced by "\n "))"
+ run %.test
+ if %verbose:
+ say (green "PASS")
+ ..else:
+ say "\r[\(green "PASS")"