Patterns: some bad casting

This commit is contained in:
Emery Hemingway 2022-12-07 22:43:36 -06:00
parent 49b58f5ce1
commit a43a723bb1
1 changed files with 7 additions and 3 deletions

View File

@ -74,7 +74,7 @@ proc `?`*[T](pr: Preserve[T]): Pattern =
of pkSymbol: ?pr.symbol
of pkRecord:
?DCompoundRec(
label: pr.label,
label: cast[Preserve[Ref]](pr.label), # TODO: don't cast like this
fields: map[Preserve[T], Pattern](pr.fields, `?`))
of pkSequence:
?DCompoundArr(items: map(pr.sequence, `?`))
@ -82,7 +82,7 @@ proc `?`*[T](pr: Preserve[T]): Pattern =
ValueError, "cannot construct a pattern over a set literal")
of pkDictionary:
var dict = DCompoundDict()
for key, val in pr.pairs: dict.entries[key] = ?val
for key, val in pr.pairs: dict.entries[cast[Preserve[Ref]](key)] = ?val
?dict
of pkEmbedded:
raiseAssert "cannot construct a pattern over a embedded literal"
@ -467,7 +467,11 @@ func capture*(pat: Pattern; pr: Value): seq[Value] =
if v.isNone: return @[]
result.add(get v)
when isMainModule:
let txt = readAll stdin
if txt != "":
stdout.writeLine(? parsePreserves(txt, Ref))
let
v = parsePreserves(txt)
pat = ?v
stdout.writeLine(pat)