Patterns sugar

This commit is contained in:
Emery Hemingway 2023-07-26 11:01:47 +01:00
parent 8fc9608199
commit 9c5e26e8f1
3 changed files with 9 additions and 1 deletions

View File

@ -31,6 +31,9 @@ proc `?`*(typ: static typedesc): Pattern {.inline.} =
proc `?`*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern {.inline.} =
patterns.grab(typ, bindings)
proc `?`*(typ: static typedesc; bindings: sink openArray[(Assertion, Pattern)]): Pattern {.inline.} =
patterns.grab(typ, bindings)
proc `??`*(pat: Pattern; bindings: openArray[(int, Pattern)]): Pattern {.inline.} =
patterns.inject(pat, bindings)

View File

@ -286,6 +286,11 @@ proc grabRecord*(label: Preserve[Cap], fields: varargs[Pattern]): Pattern =
"""<rec Says [<bind <_>> <bind <_>>]>"""
DCompoundRec(label: label, fields: fields.toSeq).toPattern
proc grabRecord*(label: string, fields: varargs[Pattern]): Pattern =
## Sugar for creating record patterns.
## `label` is converted to a symbol value.
grabRecord(label.toSymbol(Cap), fields)
proc grabDictionary*(bindings: sink openArray[(Value, Pattern)]): Pattern =
## Construct a pattern that grabs some dictionary pairs.
DCompoundDict(entries: bindings.toTable).toPattern

View File

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