You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeBar=object
shared: intcase kind: Fruit ofBanana:
bad: float
banana: int ofApple: apple: stringlet s =newStringStream("""{"kind":"Apple","apple":"world"}""")
let a = s.jsonTo(Bar)
procinitFromJson(dst: varBar, p: varJsonParser) =eat(p, tkCurlyLe)
while p.tok != tkCurlyRi:
if p.tok != tkString:
raiseParseErr(p, "string literal as key")
case p.a
of"shared":
discardgetTok(p)
eat(p, tkColon)
initFromJson(dst.apple, p)
of"kind":
discardgetTok(p)
eat(p, tkColon)
var kindTmp`gensym0: FruitinitFromJson(kindTmp`gensym0, p)
if dst.kind != kindTmp`gensym0:
case dst.kind
ofBanana:
if onceBad or onceBanana:
raiseParseErr(p, "valid object field")
if onceShared:
dst = (typeof dst)(kind: kindTmp`gensym0, shared: dst.shared)
ofApple:
if onceApple:
raiseParseErr(p, "valid object field")
if onceShared:
dst = (typeof dst)(kind: kindTmp`gensym0, shared: dst.shared)
else: discard of"bad":
if dst.kind !=Banana: # not sharedraiseParseErr(p, "valid object field")
discardgetTok(p)
eat(p, tkColon)
initFromJson(dst.bad, p)
of"banana":
if dst.kind !=Banana:
if onceApple:
raiseParseErr(p, "valid object field")
if onceShared:
dst = (typeof dst)(kind: Banana, shared: dst.shared)
discardgetTok(p)
eat(p, tkColon)
initFromJson(dst.banana, p)
of"apple":
if dst.kind !=Apple:
if onceBad or onceBanana:
raiseParseErr(p, "valid object field")
if onceShared:
dst = (typeof dst)(kind: Apple, shared: dst.shared)
discardgetTok(p)
eat(p, tkColon)
initFromJson(dst.apple, p)
else:
raiseParseErr(p, "valid object field")
if p.tok != tkComma:
breakdiscardgetTok(p)
eat(p, tkCurlyRi)
The text was updated successfully, but these errors were encountered:
Requires #12 to be implemented.
The text was updated successfully, but these errors were encountered: