Patterns: selectively grab dictionary fields

This commit is contained in:
Emery Hemingway 2024-01-14 12:10:58 +02:00
parent 3e11884a91
commit 0e5637a6c3
2 changed files with 10 additions and 3 deletions

View File

@ -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:

View File

@ -1,6 +1,6 @@
# Package
version = "20240108"
version = "20240114"
author = "Emery Hemingway"
description = "Syndicated actors for conversational concurrency"
license = "Unlicense"