33# Licensed under terms of MIT license (see LICENSE)
44
55
6- import nre, options, sequtils, os, tables
6+ import nre, options, os, tables
7+ from sequtils import deduplicate, delete, filter_it
78import private/ util
89
910export tables
1819 # # Exit in case user invoked program with incorrect arguments.
1920 usage* : string
2021
21-
2222gen_class:
2323 type
2424 Pattern = ref object of RootObj
8888
8989{.warning [LockLevel ]: off .}
9090
91- method str (self: Pattern ): string =
91+ method str (self: Pattern ): string {. base .} =
9292 assert false
9393
94- method name (self: Pattern ): string =
94+ method name (self: Pattern ): string {. base .} =
9595 self.m_name
96- method `name=` (self: Pattern , name: string ) =
96+ method `name=` (self: Pattern , name: string ) {. base .} =
9797 self.m_name = name
9898
99- method `==` (self, other: Pattern ): bool =
99+ method `==` (self, other: Pattern ): bool {. base .} =
100100 self.str == other.str
101101
102- method flat (self: Pattern , types: varargs [string ]): seq [Pattern ] =
102+ method flat (self: Pattern , types: varargs [string ]): seq [Pattern ] {. base .} =
103103 assert false
104104
105105method match (self: Pattern , left: seq [Pattern ],
106- collected: seq [Pattern ] = @ []): MatchResult =
106+ collected: seq [Pattern ] = @ []): MatchResult {. base .} =
107107 assert false
108108
109- method fix_identities (self: Pattern , uniq: seq [Pattern ]) =
109+ method fix_identities (self: Pattern , uniq: seq [Pattern ]) {. base .} =
110110 # # Make pattern-tree tips point to same object if they are equal.
111111 if self.children.is_nil:
112112 return
@@ -117,10 +117,10 @@ method fix_identities(self: Pattern, uniq: seq[Pattern]) =
117117 else :
118118 child.fix_identities (uniq)
119119
120- method fix_identities (self: Pattern ) =
120+ method fix_identities (self: Pattern ) {. base .} =
121121 self.fix_identities (self.flat ().deduplicate ())
122122
123- method either (self: Pattern ): Either =
123+ method either (self: Pattern ): Either {. base .} =
124124 # # Transform pattern into an equivalent, with only top-level Either.
125125 # Currently the pattern will not be equivalent, but more "narrow",
126126 # although good enough to reason about list arguments.
@@ -150,7 +150,7 @@ method either(self: Pattern): Either =
150150 ret.add children
151151 either (ret.map_it (Pattern , required (it)))
152152
153- method fix_repeating_arguments (self: Pattern ) =
153+ method fix_repeating_arguments (self: Pattern ) {. base .} =
154154 # # Fix elements that should accumulate/increment values.
155155 var either: seq [seq [Pattern ]] = @ []
156156 for child in self.either.children:
@@ -169,7 +169,7 @@ method fix_repeating_arguments(self: Pattern) =
169169 e.class == " Option" and Option (e).argcount == 0 :
170170 e.value = val (0 )
171171
172- method fix (self: Pattern ) =
172+ method fix (self: Pattern ) {. base .} =
173173 self.fix_identities ()
174174 self.fix_repeating_arguments ()
175175
@@ -181,7 +181,7 @@ method flat(self: ChildPattern, types: varargs[string]): seq[Pattern] =
181181 if types.len == 0 or self.class in types: @ [Pattern (self)] else : @ []
182182
183183method single_match (self: ChildPattern ,
184- left: seq [Pattern ]): SingleMatchResult =
184+ left: seq [Pattern ]): SingleMatchResult {. base .} =
185185 assert false
186186
187187method match (self: ChildPattern , left: seq [Pattern ],
@@ -258,7 +258,6 @@ proc option_parse[T](
258258 else :
259259 argcount = 1
260260 if argcount > 0 :
261- var matched = @ [" " ]
262261 var m = description.find (re " (?i)\ [default:\ (.*)\ ]" )
263262 if m.is_some:
264263 value = val (m.get.captures[0 ])
0 commit comments