-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not parse seq of Components #11
Comments
possible "solution": create a complicated macro that can understand object hierarchy: type Component = ref object of RootObj
type Move = ref object of Component
speed: float32
s.jsonTo(Component < Move | (Transform < Hierarchy)) Generates code that will recreate type
ObjHierarchy = enum
Component
Move
Transform
Hierarchy
var
runtimeType: set[ObjHierarchy] = {Component}
eat(p, tkCurlyLe)
while p.tok != tkCurlyRi:
if p.tok != tkString:
raiseParseErr(p, "string literal as key")
case p.a
of "speed":
discard getTok(p)
eat(p, tkColon)
if runtimeType * {Move} != {Move}:
if Transform in runtimeType:
when defined(emiLenient):
skipJson(p)
else: raiseParseErr(p, "invalid object hierarchy")
dst = Move(field1: dst.field1, ...) # Recreate dst
initFromJson(dst.speed, p)
else:
raiseParseErr(p, "valid object field")
if p.tok != tkComma:
break
discard getTok(p)
eat(p, tkCurlyRi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From the marshal module docs:
The text was updated successfully, but these errors were encountered: