aboutsummaryrefslogtreecommitdiff
path: root/tools/parse.nom
blob: 9e43c8823f706db3ad92c56178543af6d9df53ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env nomsu -V4.11.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 %path in (command line args):
    for %filename in (files for %path):
        if (%filename == "-"):
            %filename = "stdin"
        
        unless ((%filename == "stdin") or (%filename::matches "%.nom$")):
            do next %filename
        
        %text = (read file %filename)
        %nomsu = (NomsuCode from (Source %filename 1 (size of %text)) %text)
        %tree = (%nomsu parsed)
        print tree %tree at indent ""