45 lines
1.4 KiB
Plaintext
Executable File
45 lines
1.4 KiB
Plaintext
Executable File
#!/usr/bin/env nomsu -V4.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 ...
|
|
|
|
use "lib/os.nom"
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
externally (print tree %t at indent %indent) means:
|
|
if %t.type is:
|
|
"Action":
|
|
say "\(%indent)Action (\(%t.stub)):"
|
|
if %t.target:
|
|
say "\%indent Target:"
|
|
print tree %t.target at indent "\%indent "
|
|
|
|
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:
|
|
when:
|
|
(%arg is syntax tree):
|
|
print tree %arg at indent "\%indent "
|
|
|
|
else:
|
|
say "\%indent \(quote %arg)"
|
|
|
|
for %filename in (command line args).extra_args:
|
|
%file = (read file %filename)
|
|
unless %file:
|
|
barf "File does not exist: \%filename"
|
|
%nomsu = (NomsuCode from (Source %filename 1 (size of %file)) %file)
|
|
%tree = (%nomsu parsed)
|
|
print tree %tree at indent ""
|