aboutsummaryrefslogtreecommitdiff
path: root/tools/replace.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-12-31 01:52:46 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-12-31 01:52:46 -0800
commit811aefd0dfdb0bc93ffa8e2c6283c372159ff4ea (patch)
treef469bc9713787da8490db893799ac6b3d8b8b8cf /tools/replace.nom
parent0ae59c5a90c19bc562af23969b014c368540c241 (diff)
Added replace -q and chmod +x'd two tools.
Diffstat (limited to 'tools/replace.nom')
-rwxr-xr-x[-rw-r--r--]tools/replace.nom15
1 files changed, 8 insertions, 7 deletions
diff --git a/tools/replace.nom b/tools/replace.nom
index 2737ce0..7abe960 100644..100755
--- a/tools/replace.nom
+++ b/tools/replace.nom
@@ -3,7 +3,7 @@
This is a tool to replace syntax trees with something new.
Usage:
- nomsu -t replace [-i] [--literal="$v1 $v2..."] <pattern> <replacement> file1 file2...
+ nomsu -t replace [-i] [-f] [-q] [--literal="$v1 $v2..."] <pattern> <replacement> file1 file2...
Example:
nomsu -t replace "($1 and $2) and $3" "all of [$1, $2, $3]" my_file.nom
@@ -11,6 +11,8 @@
If the "-i" flag is used, the file(s) will be edited in-place.
When editing in-place, if the "-f" flag is not used, each change will be
run past the user first.
+ If the "-q" flag is used and a file fails to parse, the original file
+ contents will be output.
If no files are passed in, this will read from stdin.
use "lib/os.nom"
@@ -89,12 +91,11 @@ for $filename in $filenames:
try:
$tree = ($code parsed)
..and if it barfs $msg:
- say
- red ("
- \$filename failed to parse:
- \$msg
- ")
- $tree = (nil)
+ if $(COMMAND LINE ARGS).q:
+ unless $(COMMAND LINE ARGS).i:
+ say $code
+ ..else:
+ say $msg
unless $tree:
do next $filename