Attrs are patternable

With syndicate-nim f710419ead4c756261fdb67526936721a1c70a26.
This commit is contained in:
Emery Hemingway 2021-12-11 18:37:55 +00:00
parent 03e7cb258a
commit 0b1058dd7a
4 changed files with 20 additions and 7 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.tup
test_patterns

View File

@ -1,13 +1,14 @@
import
std/typetraits, preserves
std/typetraits, preserves, std/tables
type
Svui* {.preservesRecord: "svui".} = object
Svui*[E] {.preservesRecord: "svui".} = ref object
`attrs`*: Table[string, Preserve[E]]
`svg`*: string
proc `$`*(x: Svui): string =
`$`(toPreserve(x))
proc `$`*[E](x: Svui[E]): string =
`$`(toPreserve(x, E))
proc encode*(x: Svui): seq[byte] =
encode(toPreserve(x))
proc encode*[E](x: Svui[E]): seq[byte] =
encode(toPreserve(x, E))

View File

@ -1,3 +1,3 @@
version 1.
Svui = <svui @svg string>.
Svui = <svui @attrs {symbol: any ...:...} @svg string>.

11
tests/test_patterns.nim Normal file
View File

@ -0,0 +1,11 @@
import std/[typetraits, unittest]
import preserves
import syndicate/patterns
import svui
type Svui = svui.Svui[void]
suite "patterns":
test "grab-all":
let pat = Svui ? {0: grab(), 1: grab()}
check $pat == "<compound <rec svui 2> {0: <bind <_>>, 1: <bind <_>>}>"