Skip to content

Commit 0aaf814

Browse files
committed
Fix deprecations (use nre)
1 parent fff7155 commit 0aaf814

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

docopt.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ description: "Command line option parser that will make you smile"
66
license: "MIT"
77
srcDir: "src"
88
[Deps]
9-
requires: "nim >= 0.10.0"
9+
requires: "nim >= 0.10.3"

src/docopt.nim

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under terms of MIT license (see LICENSE)
44

55

6-
import re, sequtils, os, tables
6+
import nre, options, sequtils, os, tables
77
import private/util
88

99
export tables
@@ -259,8 +259,9 @@ proc option_parse[T](
259259
argcount = 1
260260
if argcount > 0:
261261
var matched = @[""]
262-
if description.find(re.re"(?i)\[default:\ (.*)\]", matched) >= 0:
263-
value = val(matched[0])
262+
var m = description.find(re"(?i)\[default:\ (.*)\]")
263+
if m.is_some:
264+
value = val(m.get.captures[0])
264265
else:
265266
value = val()
266267
constructor(short, long, argcount, value)
@@ -430,7 +431,7 @@ proc parse_expr(tokens: TokenStream, options: var seq[Option]): seq[Pattern]
430431

431432
proc parse_pattern(source: string, options: var seq[Option]): Required =
432433
var tokens = token_stream(
433-
source.replacef(re"([\[\]\(\)\|]|\.\.\.)", r" $1 "),
434+
source.replace(re"([\[\]\(\)\|]|\.\.\.)", r" $1 "),
434435
new_exception(DocoptLanguageError, "")
435436
)
436437
let ret = parse_expr(tokens, options)
@@ -527,7 +528,7 @@ proc parse_argv(tokens: TokenStream, options: var seq[Option],
527528

528529

529530
proc parse_defaults(doc: string): seq[Option] =
530-
var split = doc.split_inc(re"\n\ *(<\S+?>|-\S+?)")
531+
var split = doc.split(re"\n\ *(<\S+?>|-\S+?)")
531532
result = @[]
532533
for i in 1 .. split.len div 2:
533534
var s = split[i*2-1] & split[i*2]
@@ -536,15 +537,15 @@ proc parse_defaults(doc: string): seq[Option] =
536537

537538

538539
proc printable_usage(doc: string): string =
539-
var usage_split = doc.split_inc(re"([Uu][Ss][Aa][Gg][Ee]:)")
540+
var usage_split = doc.split(re"(?i)(Usage:)")
540541
if usage_split.len < 3:
541542
raise new_exception(DocoptLanguageError,
542543
""""usage:" (case-insensitive) not found.""")
543544
if usage_split.len > 3:
544545
raise new_exception(DocoptLanguageError,
545546
"""More than one "usage:" (case-insensitive).""")
546547
usage_split.delete(0)
547-
usage_split.join().split_inc(re"\n\s*\n")[0].strip()
548+
usage_split.join().split(re"\n\s*\n")[0].strip()
548549

549550

550551
proc formal_usage(printable_usage: string): string =
@@ -662,5 +663,5 @@ proc docopt*(doc: string, argv: seq[string] = nil, help = true,
662663
try:
663664
return docopt_exc(doc, argv, help, version, options_first)
664665
except DocoptExit:
665-
stderr.writeln((ref DocoptExit)(get_current_exception()).usage)
666+
stderr.write_line((ref DocoptExit)(get_current_exception()).usage)
666667
quit()

src/private/util.nim

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under terms of MIT license (see LICENSE)
33

44

5-
import re, sequtils, strutils, macros
5+
import sequtils, strutils, macros
66

77

88
template any_it*(lst, pred: expr): expr =
@@ -23,24 +23,6 @@ proc count*[T](s: openarray[T], it: T): int =
2323
result += 1
2424
2525
26-
iterator split_inc*(s: string, sep: Regex): string =
27-
## Like split, but include matches in parentheses, similar to Python
28-
var start = 0
29-
while true:
30-
var matches: seq[tuple[first, last: int]] = new_seq_with(20, (-1, -1))
31-
var (first, last) = s.find_bounds(sep, matches, start)
32-
if first < 0: break
33-
yield s.substr(start, <first)
34-
for a, b in matches.items:
35-
if a < 0: break
36-
yield s.substr(a, b)
37-
start = last+(if first > last: 2 else: 1)
38-
yield s.substr(start, s.high)
39-
40-
proc split_inc*(s: string, sep: Regex): seq[string] =
41-
accumulate_result(split_inc(s, sep))
42-
43-
4426
proc partition*(s, sep: string): tuple[left, sep, right: string] =
4527
## "a+b".partition("+") == ("a", "+", "b")
4628
## "a+b".partition("-") == ("a+b", "", "")

0 commit comments

Comments
 (0)