aboutsummaryrefslogtreecommitdiff
path: root/tools/find_action.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-20 14:52:59 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-20 14:54:40 -0800
commit2bbc035f5dcc3ecd62724b9d1de0e7e3ea902379 (patch)
tree34a83497f7570946b6252183b3e8fe0ce2010595 /tools/find_action.nom
parentf30413853063483147d941ffccc4b663b71bc943 (diff)
Simplifying the filesystem code (no longer entangled with nomsupath) and
using that to simplify the tools. Now the tools directly take lists of file paths rather than things that might go through nomsupath or directories or get processed by filetype. Use your shell for globbing stuff like `nomsu tools/test.nom core/*.nom`
Diffstat (limited to 'tools/find_action.nom')
-rwxr-xr-xtools/find_action.nom60
1 files changed, 28 insertions, 32 deletions
diff --git a/tools/find_action.nom b/tools/find_action.nom
index c6cbe36..6b85ad3 100755
--- a/tools/find_action.nom
+++ b/tools/find_action.nom
@@ -9,37 +9,33 @@ use "lib/consolecolor.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-%stub = (command line args).1
+%stub = (command line args).extra_args.1
say "Looking for stub: \%stub..."
-for % in 2 to (size of (command line args)):
- for %filename in (files for (command line args).%):
- if (%filename == "-"):
- %filename = "stdin"
-
- unless ((%filename == "stdin") or (%filename::matches "%.nom$")):
- do next %filename
-
- %file = (read file %filename)
- %code = (NomsuCode from (%Source %filename 1 (size of %file)) %file)
- try:
- %tree = (%code parsed)
- ..and if it barfs %msg:
- say (red "\%filename failed to parse:\n\%msg")
- %tree = (nil)
-
- unless %tree:
- do next %filename
+for % in 2 to (size of (command line args).extra_args):
+ %filename = (command line args).extra_args.%
+ %file = (read file %filename)
+ unless %file:
+ barf "File does not exist: \%filename"
+ %code = (NomsuCode from (%Source %filename 1 (size of %file)) %file)
+ try:
+ %tree = (%code parsed)
+ ..and if it barfs %msg:
+ say (red "\%filename failed to parse:\n\%msg")
+ %tree = (nil)
+
+ unless %tree:
+ do next %filename
+
+ %results = []
+ for %t in recursive %tree:
+ if ((%t is "Action" syntax tree) and (%t.stub is %stub)):
+ %line_num = (%file::line number at %t.source.start)
+ %results::add {..}
+ line: %line_num, text: "\(blue "\%filename:\%line_num:")\n\(yellow (source lines of %t))"
- %results = []
- for %t in recursive %tree:
- if ((%t is "Action" syntax tree) and (%t.stub is %stub)):
- %line_num = (%file::line number at %t.source.start)
- %results::add {..}
- line: %line_num, text: "\(blue "\%filename:\%line_num:")\n\(yellow (source lines of %t))"
-
- if (%t is syntax tree):
- for %sub in %t:
- recurse %t on %sub
- sort %results by % -> %.line
- for % in %results:
- say %.text
+ if (%t is syntax tree):
+ for %sub in %t:
+ recurse %t on %sub
+ sort %results by % -> %.line
+ for % in %results:
+ say %.text