aboutsummaryrefslogtreecommitdiff
path: root/tools/find_action.nom
blob: 0d7ac4fa11d6f42dcc4476e725b9812c5b1d771a (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
#!/usr/bin/env nomsu -V2.5.4.3
#
    Find an action by its stub. Usage:
        nomsu tools/find_action.nom "foo %" file1 file2 directory1 ...
    Will print all the code locations and code that uses the stub.

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