Generic ToJSON for Statements
This commit is contained in:
parent
fa3093e61c
commit
b28555b0f4
|
@ -27,12 +27,13 @@ module Data.Language.Ruby.AST
|
|||
) where
|
||||
|
||||
import Data.Aeson (parseJSON, Value(Null,Object,Number,Bool), withArray)
|
||||
import Prelude (Bounded)
|
||||
import Prelude (Bounded, drop)
|
||||
import Frelude hiding (String, Int)
|
||||
import qualified Frelude
|
||||
import qualified Data.Aeson.Types as Aeson
|
||||
import qualified Data.Vector as Vector
|
||||
import qualified Data.Scientific as Scientific
|
||||
import Data.Char (toLower)
|
||||
|
||||
kebabCase :: Frelude.String -> Frelude.String
|
||||
kebabCase = Aeson.camelTo2 '-'
|
||||
|
@ -89,25 +90,7 @@ instance ToJSON Statement where
|
|||
toEncoding = Aeson.genericToEncoding opts
|
||||
where
|
||||
opts = aesonOptions { Aeson.constructorTagModifier = go }
|
||||
go = \case
|
||||
"StmtModule" -> "module"
|
||||
"StmtDef" -> "def"
|
||||
"StmtDefs" -> "defs"
|
||||
"StmtSend" -> "send"
|
||||
"StmtBlock" -> "block"
|
||||
"StmtConst" -> "const"
|
||||
"StmtCasgn" -> "casgn"
|
||||
"StmtArray" -> "array"
|
||||
"StmtSym" -> "sym"
|
||||
"StmtStr" -> "str"
|
||||
"StmtLvasgn" -> "lvasgn"
|
||||
"StmtLvar" -> "lvar"
|
||||
"StmtIvar" -> "ivar"
|
||||
"StmtSelf" -> "self"
|
||||
"StmtNil" -> "nil"
|
||||
"StmtInt" -> "int"
|
||||
"StmtCbase" -> "cbase"
|
||||
x -> x
|
||||
go s = toLower <$> drop 4 s
|
||||
|
||||
instance FromJSON Statement where
|
||||
parseJSON v
|
||||
|
|
Loading…
Reference in a new issue