patterns: inject into <bind …>
This commit is contained in:
parent
aff3061506
commit
209ae51580
|
@ -221,16 +221,22 @@ proc inject*(pat: Pattern; bindings: openArray[(int, Pattern)]): Pattern =
|
|||
proc inject(pat: Pattern; bindings: openArray[(int, Pattern)]; offset: var int): Pattern =
|
||||
case pat.orKind
|
||||
of PatternKind.DDiscard:
|
||||
var replaced = false
|
||||
for (i, injection) in bindings:
|
||||
if i == offset:
|
||||
result = pat
|
||||
for (off, injection) in bindings:
|
||||
if off == offset:
|
||||
result = injection
|
||||
replaced = true
|
||||
break
|
||||
if not replaced:
|
||||
result = drop()
|
||||
inc offset
|
||||
of PatternKind.DBind, PatternKind.DLit:
|
||||
of PatternKind.DBind:
|
||||
let bindOff = offset
|
||||
result = pat
|
||||
result.dbind.pattern = inject(pat.dbind.pattern, bindings, offset)
|
||||
if result.orKind == PatternKind.DBind:
|
||||
for (off, injection) in bindings:
|
||||
if (off == bindOff) and (result.dbind.pattern == injection):
|
||||
result = result.dbind.pattern
|
||||
break # promote the injected pattern over the bind
|
||||
of PatternKind.DLit:
|
||||
result = pat
|
||||
of PatternKind.DCompound:
|
||||
result = pat
|
||||
|
|
Loading…
Reference in New Issue