diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-07-25 12:59:09 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-07-27 14:01:28 +0200 |
commit | b9c15371a3278cafa962c09693d126ae388dca2b (patch) | |
tree | ae6bfb54517a7c8c1ac48af552336450adc44eec /tools/nimgrep.nim | |
parent | f7c99838e25742fede0532b695a0e899c253e035 (diff) | |
download | Nim-b9c15371a3278cafa962c09693d126ae388dca2b.tar.gz |
nimgrep: introduce the --rex option
Diffstat (limited to 'tools/nimgrep.nim')
-rw-r--r-- | tools/nimgrep.nim | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/nimgrep.nim b/tools/nimgrep.nim index e79b32377..57a34f4c2 100644 --- a/tools/nimgrep.nim +++ b/tools/nimgrep.nim @@ -11,7 +11,7 @@ import os, strutils, parseopt, pegs, re, terminal const - Version = "1.3" + Version = "1.4" Usage = "nimgrep - Nim Grep Utility Version " & Version & """ (c) 2012 Andreas Rumpf @@ -21,8 +21,9 @@ Options: --find, -f find the pattern (default) --replace, -r replace the pattern --peg pattern is a peg - --re pattern is a regular expression (default); extended - syntax for the regular expression is always turned on + --re pattern is a regular expression (default) + --rex, -x use the "extended" syntax for the regular expression + so that whitespace is not significant --recursive process directories recursively --confirm confirm each occurrence/replacement; there is a chance to abort any time without touching the file @@ -44,7 +45,8 @@ Options: type TOption = enum optFind, optReplace, optPeg, optRegex, optRecursive, optConfirm, optStdin, - optWord, optIgnoreCase, optIgnoreStyle, optVerbose, optFilenames + optWord, optIgnoreCase, optIgnoreStyle, optVerbose, optFilenames, + optRex TOptions = set[TOption] TConfirmEnum = enum ceAbort, ceYes, ceAll, ceNo, ceNone @@ -290,6 +292,10 @@ for kind, key, val in getopt(): of "re": incl(options, optRegex) excl(options, optPeg) + of "rex", "x": + incl(options, optRex) + incl(options, optRegex) + excl(options, optPeg) of "recursive": incl(options, optRecursive) of "confirm": incl(options, optConfirm) of "stdin": incl(options, optStdin) @@ -345,7 +351,8 @@ else: pattern = r"\b(:?" & pattern & r")\b" if {optIgnoreCase, optIgnoreStyle} * options != {}: reflags.incl reIgnoreCase - let rep = re(pattern, reflags) + let rep = if optRex in options: rex(pattern, reflags) + else: re(pattern, reflags) for f in items(filenames): walker(rep, f, counter) stdout.write($counter & " matches\n") |