Attrs are patternable
With syndicate-nim f710419ead4c756261fdb67526936721a1c70a26.
This commit is contained in:
parent
03e7cb258a
commit
0b1058dd7a
|
@ -1 +1,2 @@
|
|||
.tup
|
||||
test_patterns
|
||||
|
|
13
src/svui.nim
13
src/svui.nim
|
@ -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))
|
||||
|
|
2
svui.prs
2
svui.prs
|
@ -1,3 +1,3 @@
|
|||
version 1.
|
||||
|
||||
Svui = <svui @svg string>.
|
||||
Svui = <svui @attrs {symbol: any ...:...} @svg string>.
|
||||
|
|
|
@ -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 <_>>}>"
|
Loading…
Reference in New Issue