patterns: grabRecord, grabDictionary
This commit is contained in:
parent
ce8e800187
commit
8fc9608199
|
@ -277,15 +277,26 @@ proc inject*(pat: Pattern; bindings: openArray[(Preserve[Cap], Pattern)]): Patte
|
|||
for (key, val) in bindings:
|
||||
result.dcompound.dict.entries[key] = val
|
||||
|
||||
proc recordPattern*(label: Preserve[Cap], fields: varargs[Pattern]): Pattern =
|
||||
proc grabRecord*(label: Preserve[Cap], fields: varargs[Pattern]): Pattern =
|
||||
runnableExamples:
|
||||
from std/unittest import check
|
||||
import syndicate/actors, preserves
|
||||
check:
|
||||
$recordPattern("Says".toSymbol(Cap), grab(), grab()) ==
|
||||
$grabRecord("Says".toSymbol(Cap), grab(), grab()) ==
|
||||
"""<rec Says [<bind <_>> <bind <_>>]>"""
|
||||
DCompoundRec(label: label, fields: fields.toSeq).toPattern
|
||||
|
||||
proc grabDictionary*(bindings: sink openArray[(Value, Pattern)]): Pattern =
|
||||
## Construct a pattern that grabs some dictionary pairs.
|
||||
DCompoundDict(entries: bindings.toTable).toPattern
|
||||
|
||||
proc grabDictionary*(bindings: sink openArray[(string, Pattern)]): Pattern =
|
||||
## Construct a pattern that grabs some dictionary pairs.
|
||||
## Keys are converted from strings to symbols.
|
||||
result = DCompoundDict().toPattern
|
||||
for (key, val) in bindings.items:
|
||||
result.dcompound.dict.entries[key.toSymbol(Cap)] = val
|
||||
|
||||
type
|
||||
Path* = seq[Value]
|
||||
Paths* = seq[Path]
|
||||
|
|
Loading…
Reference in New Issue