aboutsummaryrefslogtreecommitdiff
path: root/lib/tools/parse.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-14 15:42:48 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-14 15:43:24 -0800
commitc1c32688a4afc43f6addb99b8b5fa878944a70e3 (patch)
treec886f21b5b08a9053aa74fcba4b241dae5ede76d /lib/tools/parse.nom
parent2309b696fc34b24f05f6658b94f9105ca8ee76e4 (diff)
Overhaul in progress, mostly working. Moved all the nomsu packages into
lib/, including core/*. Changes to how nomsu environments and importing work.
Diffstat (limited to 'lib/tools/parse.nom')
-rwxr-xr-xlib/tools/parse.nom47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/tools/parse.nom b/lib/tools/parse.nom
new file mode 100755
index 0000000..63cc247
--- /dev/null
+++ b/lib/tools/parse.nom
@@ -0,0 +1,47 @@
+#!/usr/bin/env nomsu -V6.14
+#
+ Tool to print out a parse tree of files in an easy-to-read format. Usage:
+ nomsu tools/parse.nom file1 file2 directory1 ...
+
+use "filesystem"
+use "commandline"
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+externally (print tree $t at indent $indent) means:
+ 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 "
+
+ "MethodCall":
+ say "\($indent)MethodCall on:"
+ print tree $t.1 at indent "\$indent "
+ print tree $t.2 at indent "\$indent "
+
+ "Number":
+ say "\$indent\($t.1)"
+
+ "Var":
+ say "\($indent)$\($t.1)"
+
+ else:
+ say "\$indent\($t.type):"
+ for $arg in $t:
+ when:
+ ($arg is syntax tree):
+ print tree $arg at indent "\$indent "
+
+ else:
+ say "\$indent \(quote $arg)"
+
+command line program with $args:
+ for $filename in $args.extras:
+ $file = (read file $filename)
+ unless $file:
+ fail "File does not exist: \$filename"
+ $nomsu = (NomsuCode from (Source $filename 1 (size of $file)) $file)
+ $tree = ($nomsu parsed)
+ print tree $tree at indent ""