Unify the data model between the C runtime and the Haskell binding

This commit is contained in:
krangelov
2021-11-09 02:04:36 +01:00
parent b3ef14c39b
commit 6552bcf909
13 changed files with 118 additions and 140 deletions

View File

@@ -103,13 +103,17 @@ instance Binary Options where
toString (LInt n) = show n
toString (LFlt d) = show d
instance Binary PMCFGCat where
put (PMCFGCat r rs) = put (r,rs)
get = get >>= \(r,rs) -> return (PMCFGCat r rs)
instance Binary LParam where
put (LParam r rs) = put (r,rs)
get = get >>= \(r,rs) -> return (LParam r rs)
instance Binary PMCFGRule where
put (PMCFGRule res args rules) = put (res,args,rules)
get = get >>= \(res,args,rules) -> return (PMCFGRule res args rules)
instance Binary PArg where
put (PArg x y) = put (x,y)
get = get >>= \(x,y) -> return (PArg x y)
instance Binary Production where
put (Production args res rules) = put (args,res,rules)
get = get >>= \(args,res,rules) -> return (Production args res rules)
instance Binary Info where
put (AbsCat x) = putWord8 0 >> put x
@@ -312,8 +316,8 @@ instance Binary Literal where
_ -> decodingError
instance Binary Symbol where
put (SymCat d r rs) = putWord8 0 >> put (d,r,rs)
put (SymLit n l) = putWord8 1 >> put (n,l)
put (SymCat d r) = putWord8 0 >> put (d,r)
put (SymLit d r) = putWord8 1 >> put (d,r)
put (SymVar n l) = putWord8 2 >> put (n,l)
put (SymKS ts) = putWord8 3 >> put ts
put (SymKP d vs) = putWord8 4 >> put (d,vs)
@@ -325,7 +329,7 @@ instance Binary Symbol where
put SymALL_CAPIT = putWord8 10
get = do tag <- getWord8
case tag of
0 -> liftM3 SymCat get get get
0 -> liftM2 SymCat get get
1 -> liftM2 SymLit get get
2 -> liftM2 SymVar get get
3 -> liftM SymKS get