Patterns: selectively grab dictionary fields
This commit is contained in:
parent
3e11884a91
commit
0e5637a6c3
|
@ -178,7 +178,7 @@ proc lookup(bindings: openArray[(int, Pattern)]; i: int): Pattern =
|
|||
return drop()
|
||||
|
||||
proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern =
|
||||
## Construct a `Pattern` from type `typ` that selectively captures fields.
|
||||
## Construct a `Pattern` from type `typ` with pattern `bindings` by integer offset.
|
||||
when typ is ptr | ref:
|
||||
grab(pointerBase(typ), bindings)
|
||||
elif typ.hasPreservesRecordPragma:
|
||||
|
@ -198,7 +198,14 @@ proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Patt
|
|||
inc i
|
||||
result = arr.toPattern
|
||||
else:
|
||||
{.error: "grab with bindings not implemented for " & $typ.}
|
||||
{.error: "grab with indexed bindings not implemented for " & $typ.}
|
||||
|
||||
proc grab*(typ: static typedesc; bindings: sink openArray[(Value, Pattern)]): Pattern =
|
||||
## Construct a `Pattern` from type `typ` with dictionary field `bindings`.
|
||||
when typ.hasPreservesDictionaryPragma:
|
||||
DCompoundDict(entries: bindings.toTable).toPattern
|
||||
else:
|
||||
{.error: "grab with dictionary bindings not implemented for " & $typ.}
|
||||
|
||||
proc grabLit*(): Pattern =
|
||||
runnableExamples:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20240108"
|
||||
version = "20240114"
|
||||
author = "Emery Hemingway"
|
||||
description = "Syndicated actors for conversational concurrency"
|
||||
license = "Unlicense"
|
||||
|
|
Loading…
Reference in New Issue