updated nimgrep tool
This commit is contained in:
parent
22fb9db845
commit
63c9c2877e
2 changed files with 7 additions and 7 deletions
|
|
@ -25,7 +25,7 @@ type
|
||||||
CmdLineKind* = enum ## the detected command line token
|
CmdLineKind* = enum ## the detected command line token
|
||||||
cmdEnd, ## end of command line reached
|
cmdEnd, ## end of command line reached
|
||||||
cmdArgument, ## argument detected
|
cmdArgument, ## argument detected
|
||||||
cmdLongoption, ## a long option ``--option`` detected
|
cmdLongOption, ## a long option ``--option`` detected
|
||||||
cmdShortOption ## a short option ``-c`` detected
|
cmdShortOption ## a short option ``-c`` detected
|
||||||
OptParser* =
|
OptParser* =
|
||||||
object of RootObj ## this object implements the command line parser
|
object of RootObj ## this object implements the command line parser
|
||||||
|
|
|
||||||
|
|
@ -81,14 +81,14 @@ proc countLines(s: string, first, last: int): int =
|
||||||
proc beforePattern(s: string, first: int): int =
|
proc beforePattern(s: string, first: int): int =
|
||||||
result = first-1
|
result = first-1
|
||||||
while result >= 0:
|
while result >= 0:
|
||||||
if s[result] in Newlines: break
|
if s[result] in NewLines: break
|
||||||
dec(result)
|
dec(result)
|
||||||
inc(result)
|
inc(result)
|
||||||
|
|
||||||
proc afterPattern(s: string, last: int): int =
|
proc afterPattern(s: string, last: int): int =
|
||||||
result = last+1
|
result = last+1
|
||||||
while result < s.len:
|
while result < s.len:
|
||||||
if s[result] in Newlines: break
|
if s[result] in NewLines: break
|
||||||
inc(result)
|
inc(result)
|
||||||
dec(result)
|
dec(result)
|
||||||
|
|
||||||
|
|
@ -125,12 +125,12 @@ proc processFile(filename: string) =
|
||||||
var buffer: string
|
var buffer: string
|
||||||
try:
|
try:
|
||||||
buffer = system.readFile(filename)
|
buffer = system.readFile(filename)
|
||||||
except EIO:
|
except IOError:
|
||||||
echo "cannot open file: ", filename
|
echo "cannot open file: ", filename
|
||||||
return
|
return
|
||||||
if optVerbose in options: stdout.writeln(filename)
|
if optVerbose in options: stdout.writeln(filename)
|
||||||
var pegp: TPeg
|
var pegp: TPeg
|
||||||
var rep: TRegex
|
var rep: Regex
|
||||||
var result: string
|
var result: string
|
||||||
|
|
||||||
if optRegex in options:
|
if optRegex in options:
|
||||||
|
|
@ -267,7 +267,7 @@ proc checkOptions(subset: TOptions, a, b: string) =
|
||||||
for kind, key, val in getopt():
|
for kind, key, val in getopt():
|
||||||
case kind
|
case kind
|
||||||
of cmdArgument:
|
of cmdArgument:
|
||||||
if options.contains(optStdIn):
|
if options.contains(optStdin):
|
||||||
filenames.add(key)
|
filenames.add(key)
|
||||||
elif pattern.len == 0:
|
elif pattern.len == 0:
|
||||||
pattern = key
|
pattern = key
|
||||||
|
|
@ -275,7 +275,7 @@ for kind, key, val in getopt():
|
||||||
replacement = key
|
replacement = key
|
||||||
else:
|
else:
|
||||||
filenames.add(key)
|
filenames.add(key)
|
||||||
of cmdLongOption, cmdShortOption:
|
of cmdLongoption, cmdShortOption:
|
||||||
case normalize(key)
|
case normalize(key)
|
||||||
of "find", "f": incl(options, optFind)
|
of "find", "f": incl(options, optFind)
|
||||||
of "replace", "r": incl(options, optReplace)
|
of "replace", "r": incl(options, optReplace)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue