3
3
# Licensed under terms of MIT license (see LICENSE)
4
4
5
5
6
- import re , sequtils, os, tables
6
+ import nre, options , sequtils, os, tables
7
7
import private/ util
8
8
9
9
export tables
@@ -259,8 +259,9 @@ proc option_parse[T](
259
259
argcount = 1
260
260
if argcount > 0:
261
261
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 ])
264
265
else :
265
266
value = val()
266
267
constructor(short, long, argcount, value)
@@ -430,7 +431,7 @@ proc parse_expr(tokens: TokenStream, options: var seq[Option]): seq[Pattern]
430
431
431
432
proc parse_pattern(source: string , options: var seq [Option]) : Required =
432
433
var tokens = token_stream(
433
- source.replacef (re" ([\ [\ ]\ (\ )\ |]|\ .\ .\ .)" , r " $1 " ),
434
+ source.replace (re" ([\ [\ ]\ (\ )\ |]|\ .\ .\ .)" , r " $1 " ),
434
435
new_exception(DocoptLanguageError, " " )
435
436
)
436
437
let ret = parse_expr(tokens, options)
@@ -527,7 +528,7 @@ proc parse_argv(tokens: TokenStream, options: var seq[Option],
527
528
528
529
529
530
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+?)" )
531
532
result = @ []
532
533
for i in 1 .. split.len div 2 :
533
534
var s = split[i* 2 - 1 ] & split[i* 2 ]
@@ -536,15 +537,15 @@ proc parse_defaults(doc: string): seq[Option] =
536
537
537
538
538
539
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 :)" )
540
541
if usage_split.len < 3 :
541
542
raise new_exception(DocoptLanguageError,
542
543
""" "usage:" (case-insensitive) not found. """ )
543
544
if usage_split.len > 3 :
544
545
raise new_exception(DocoptLanguageError,
545
546
""" More than one "usage:" (case-insensitive). """ )
546
547
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()
548
549
549
550
550
551
proc formal_usage(printable_usage: string ): string =
@@ -662,5 +663,5 @@ proc docopt*(doc: string, argv: seq[string] = nil, help = true,
662
663
try :
663
664
return docopt_exc(doc, argv, help, version, options_first)
664
665
except DocoptExit:
665
- stderr.writeln ((ref DocoptExit)(get_current_exception()).usage)
666
+ stderr.write_line ((ref DocoptExit)(get_current_exception()).usage)
666
667
quit()
0 commit comments