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 =
|
proc inject(pat: Pattern; bindings: openArray[(int, Pattern)]; offset: var int): Pattern =
|
||||||
case pat.orKind
|
case pat.orKind
|
||||||
of PatternKind.DDiscard:
|
of PatternKind.DDiscard:
|
||||||
var replaced = false
|
result = pat
|
||||||
for (i, injection) in bindings:
|
for (off, injection) in bindings:
|
||||||
if i == offset:
|
if off == offset:
|
||||||
result = injection
|
result = injection
|
||||||
replaced = true
|
|
||||||
break
|
break
|
||||||
if not replaced:
|
|
||||||
result = drop()
|
|
||||||
inc offset
|
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
|
result = pat
|
||||||
of PatternKind.DCompound:
|
of PatternKind.DCompound:
|
||||||
result = pat
|
result = pat
|
||||||
|
|
Loading…
Reference in New Issue