import typetraits import edn, chronicles import ../types/[sticker] # FIXME: there should be no type deps # forward declaration: proc parseNode[T](node: EdnNode, searchName: string): T proc parseMap[T](map: HMap, searchName: string,): T proc getValueFromNode[T](node: EdnNode): T = if node.kind == EdnSymbol: when T is string: result = node.symbol.name elif node.kind == EdnKeyword: when T is string: result = node.keyword.name elif node.kind == EdnString: when T is string: result = node.str elif node.kind == EdnCharacter: when T is string: result = node.character elif node.kind == EdnBool: when T is bool: result = node.boolVal elif node.kind == EdnInt: when T is int: try: result = cast[int](node.num) except: warn "Returned 0 value for node, when value should have been ", val = $node.num result = 0 else: raise newException(ValueError, "couldn't get '" & T.type.name & "'value from node: " & repr(node)) proc parseVector[T: seq[Sticker]](node: EdnNode, searchName: string): seq[Sticker] = # TODO: make this generic to accept any seq[T]. Issue is that instantiating result # like `result = T()` is not allowed when T is `seq[Sticker]` # because seq[Sticker] isn't an object, whereas it works when T is # an object type (like Sticker). IOW, Sticker is an object type, but seq[Sticker] # is not result = newSeq[Sticker]() for i in 0.. 0: for iChild in 0..