Rename Definition to Statement

This commit is contained in:
Frederik Hanghøj Iversen 2019-10-14 20:25:09 +02:00
parent eb93747b2c
commit 60445d6bb8
2 changed files with 29 additions and 29 deletions

View file

@ -3,7 +3,7 @@
module Data.Language.Ruby
( Args(..)
, Block(..)
, Definition(..)
, Statement(..)
, Function(..)
, Module(..)
, Name(..)
@ -27,7 +27,7 @@ aesonOptions = Aeson.defaultOptions
, Aeson.constructorTagModifier = kebabCase
}
newtype Block = Block [Definition]
newtype Block = Block [Statement]
deriving stock instance Show Block
deriving stock instance Ord Block
@ -44,35 +44,35 @@ instance FromJSON Block where
_ -> Block . pure <$> parseJSON (Array as)
-- Should be 'expression'
data Definition
= DefModule Module
| DefFunction Function
| DefSend Send
| DefRBlock RBlock
| DefAnything Anything
data Statement
= StmtModule Module
| StmtFunction Function
| StmtSend Send
| StmtRBlock RBlock
| StmtAnything Anything
deriving stock instance Show Definition
deriving stock instance Ord Definition
deriving stock instance Eq Definition
deriving stock instance Generic Definition
instance ToJSON Definition where
deriving stock instance Show Statement
deriving stock instance Ord Statement
deriving stock instance Eq Statement
deriving stock instance Generic Statement
instance ToJSON Statement where
toEncoding = Aeson.genericToEncoding opts
where
opts = aesonOptions { Aeson.constructorTagModifier = go }
go = \case
"DefModule" -> "module"
"DefFunction" -> "function"
"DefSend" -> "send"
"DefRBlock" -> "block"
"StmtModule" -> "module"
"StmtFunction" -> "function"
"StmtSend" -> "send"
"StmtRBlock" -> "block"
x -> x
instance FromJSON Definition where
instance FromJSON Statement where
parseJSON v
= (DefModule <$> parseJSON v)
<|> (DefFunction <$> parseJSON v)
<|> (DefSend <$> parseJSON v)
<|> (DefRBlock <$> parseJSON v)
<|> (DefAnything <$> parseJSON v)
= (StmtModule <$> parseJSON v)
<|> (StmtFunction <$> parseJSON v)
<|> (StmtSend <$> parseJSON v)
<|> (StmtRBlock <$> parseJSON v)
<|> (StmtAnything <$> parseJSON v)
newtype Anything = Anything Value

View file

@ -155,14 +155,14 @@ instance References Block where
entries :: forall m . MyMonad m => Block -> m ()
entries (Block defs) = traverse_ (locally . entries) defs
instance References Definition where
instance References Statement where
entries = \case
DefModule m -> entries m
DefFunction f -> entries f
DefSend s -> entries s
StmtModule m -> entries m
StmtFunction f -> entries f
StmtSend s -> entries s
-- TODO:
DefRBlock{} -> pure ()
DefAnything{} -> pure ()
StmtRBlock{} -> pure ()
StmtAnything{} -> pure ()
instance References Module where
entries Module{name, block} = do