3
3
# Licensed under terms of MIT license (see LICENSE)
4
4
5
5
6
- import nre, options, sequtils, os, tables
6
+ import nre, options, os, tables
7
+ from sequtils import deduplicate, delete, filter_it
7
8
import private/ util
8
9
9
10
export tables
18
19
# # Exit in case user invoked program with incorrect arguments.
19
20
usage* : string
20
21
21
-
22
22
gen_class:
23
23
type
24
24
Pattern = ref object of RootObj
88
88
89
89
{.warning[LockLevel]: off .}
90
90
91
- method str(self: Pattern): string =
91
+ method str(self: Pattern): string {.base.} =
92
92
assert false
93
93
94
- method name(self: Pattern): string =
94
+ method name(self: Pattern): string {.base.} =
95
95
self.m_name
96
- method `name=` (self: Pattern, name: string ) =
96
+ method `name=` (self: Pattern, name: string ) {.base.} =
97
97
self.m_name = name
98
98
99
- method `==` (self, other: Pattern): bool =
99
+ method `==` (self, other: Pattern): bool {.base.} =
100
100
self.str == other.str
101
101
102
- method flat(self: Pattern, types: varargs [string ]): seq [Pattern] =
102
+ method flat(self: Pattern, types: varargs [string ]): seq [Pattern] {.base.} =
103
103
assert false
104
104
105
105
method match(self: Pattern, left: seq [Pattern],
106
- collected: seq [Pattern] = @ []) : MatchResult =
106
+ collected: seq [Pattern] = @ []) : MatchResult {.base.} =
107
107
assert false
108
108
109
- method fix_identities(self: Pattern, uniq: seq [Pattern]) =
109
+ method fix_identities(self: Pattern, uniq: seq [Pattern]) {.base.} =
110
110
# # Make pattern-tree tips point to same object if they are equal.
111
111
if self.children.is_nil:
112
112
return
@@ -117,10 +117,10 @@ method fix_identities(self: Pattern, uniq: seq[Pattern]) =
117
117
else :
118
118
child.fix_identities(uniq)
119
119
120
- method fix_identities(self: Pattern) =
120
+ method fix_identities(self: Pattern) {.base.} =
121
121
self.fix_identities(self.flat().deduplicate())
122
122
123
- method either(self: Pattern): Either =
123
+ method either(self: Pattern): Either {.base.} =
124
124
# # Transform pattern into an equivalent, with only top-level Either.
125
125
# Currently the pattern will not be equivalent, but more "narrow",
126
126
# although good enough to reason about list arguments.
@@ -150,7 +150,7 @@ method either(self: Pattern): Either =
150
150
ret.add children
151
151
either(ret.map_it(Pattern, required(it)))
152
152
153
- method fix_repeating_arguments(self: Pattern) =
153
+ method fix_repeating_arguments(self: Pattern) {.base.} =
154
154
# # Fix elements that should accumulate/increment values.
155
155
var either: seq [seq [Pattern]] = @ []
156
156
for child in self.either.children:
@@ -169,7 +169,7 @@ method fix_repeating_arguments(self: Pattern) =
169
169
e.class == " Option" and Option(e).argcount == 0 :
170
170
e.value = val(0 )
171
171
172
- method fix(self: Pattern) =
172
+ method fix(self: Pattern) {.base.} =
173
173
self.fix_identities()
174
174
self.fix_repeating_arguments()
175
175
@@ -181,7 +181,7 @@ method flat(self: ChildPattern, types: varargs[string]): seq[Pattern] =
181
181
if types.len == 0 or self.class in types: @ [Pattern(self)] else : @ []
182
182
183
183
method single_match(self: ChildPattern,
184
- left: seq [Pattern]) : SingleMatchResult =
184
+ left: seq [Pattern]) : SingleMatchResult {.base.} =
185
185
assert false
186
186
187
187
method match(self: ChildPattern, left: seq [Pattern],
@@ -258,7 +258,6 @@ proc option_parse[T](
258
258
else:
259
259
argcount = 1
260
260
if argcount > 0:
261
- var matched = @[" " ]
262
261
var m = description.find(re"(?i)\[default:\ (.*) \ ]" )
263
262
if m.is_some:
264
263
value = val(m.get.captures[0 ])
0 commit comments