Created
June 13, 2017 14:24
-
-
Save fredcy/3c6465f875f9218142e81072c4bba4a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Michelson exposing (..) | |
import Json.Decode as Decode | |
import Json.Decode.Pipeline as Decode | |
type alias Script = | |
{ code : Code | |
, storage : Storage | |
} | |
type alias Code = | |
{ code : Program | |
, argType : String | |
, retType : String | |
, storageType : Decode.Value | |
} | |
type alias Storage = | |
{ storage : Decode.Value | |
, storageType : Decode.Value | |
} | |
type alias Program = | |
AST | |
type AST | |
= IntT String --TODO | |
| StringT String | |
| SeqT (List AST) | |
| PrimT String | |
decodeScript : Decode.Decoder Script | |
decodeScript = | |
Decode.succeed Script | |
|> Decode.required "code" decodeCode | |
|> Decode.required "storage" decodeStorage | |
decodeCode : Decode.Decoder Code | |
decodeCode = | |
Decode.succeed Code | |
|> Decode.required "code" decodeProgram | |
|> Decode.required "argType" Decode.string | |
|> Decode.required "retType" Decode.string | |
|> Decode.required "storageType" Decode.value | |
decodeStorage : Decode.Decoder Storage | |
decodeStorage = | |
Decode.succeed Storage | |
|> Decode.required "storage" Decode.value | |
|> Decode.required "storageType" Decode.value | |
decodeProgram : Decode.Decoder Program | |
decodeProgram = | |
decodeSeqT | |
decodeAST : Decode.Decoder AST | |
decodeAST = | |
Decode.oneOf | |
[ decodeIntT, decodeStringT, decodeSeqT, decodePrimT ] | |
decodeSeqT : Decode.Decoder AST | |
decodeSeqT = | |
Decode.list | |
(Decode.lazy (\_ -> decodeAST)) | |
|> Decode.map SeqT | |
decodeStringT : Decode.Decoder AST | |
decodeStringT = | |
Decode.field "string" Decode.string |> Decode.map StringT | |
decodeIntT : Decode.Decoder AST | |
decodeIntT = | |
Decode.field "int" Decode.string |> Decode.map IntT | |
decodePrimT : Decode.Decoder AST | |
decodePrimT = | |
Decode.string |> Decode.map PrimT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment