Rename Definition to Statement
This commit is contained in:
parent
eb93747b2c
commit
60445d6bb8
|
@ -3,7 +3,7 @@
|
||||||
module Data.Language.Ruby
|
module Data.Language.Ruby
|
||||||
( Args(..)
|
( Args(..)
|
||||||
, Block(..)
|
, Block(..)
|
||||||
, Definition(..)
|
, Statement(..)
|
||||||
, Function(..)
|
, Function(..)
|
||||||
, Module(..)
|
, Module(..)
|
||||||
, Name(..)
|
, Name(..)
|
||||||
|
@ -27,7 +27,7 @@ aesonOptions = Aeson.defaultOptions
|
||||||
, Aeson.constructorTagModifier = kebabCase
|
, Aeson.constructorTagModifier = kebabCase
|
||||||
}
|
}
|
||||||
|
|
||||||
newtype Block = Block [Definition]
|
newtype Block = Block [Statement]
|
||||||
|
|
||||||
deriving stock instance Show Block
|
deriving stock instance Show Block
|
||||||
deriving stock instance Ord Block
|
deriving stock instance Ord Block
|
||||||
|
@ -44,35 +44,35 @@ instance FromJSON Block where
|
||||||
_ -> Block . pure <$> parseJSON (Array as)
|
_ -> Block . pure <$> parseJSON (Array as)
|
||||||
|
|
||||||
-- Should be 'expression'
|
-- Should be 'expression'
|
||||||
data Definition
|
data Statement
|
||||||
= DefModule Module
|
= StmtModule Module
|
||||||
| DefFunction Function
|
| StmtFunction Function
|
||||||
| DefSend Send
|
| StmtSend Send
|
||||||
| DefRBlock RBlock
|
| StmtRBlock RBlock
|
||||||
| DefAnything Anything
|
| StmtAnything Anything
|
||||||
|
|
||||||
deriving stock instance Show Definition
|
deriving stock instance Show Statement
|
||||||
deriving stock instance Ord Definition
|
deriving stock instance Ord Statement
|
||||||
deriving stock instance Eq Definition
|
deriving stock instance Eq Statement
|
||||||
deriving stock instance Generic Definition
|
deriving stock instance Generic Statement
|
||||||
instance ToJSON Definition where
|
instance ToJSON Statement where
|
||||||
toEncoding = Aeson.genericToEncoding opts
|
toEncoding = Aeson.genericToEncoding opts
|
||||||
where
|
where
|
||||||
opts = aesonOptions { Aeson.constructorTagModifier = go }
|
opts = aesonOptions { Aeson.constructorTagModifier = go }
|
||||||
go = \case
|
go = \case
|
||||||
"DefModule" -> "module"
|
"StmtModule" -> "module"
|
||||||
"DefFunction" -> "function"
|
"StmtFunction" -> "function"
|
||||||
"DefSend" -> "send"
|
"StmtSend" -> "send"
|
||||||
"DefRBlock" -> "block"
|
"StmtRBlock" -> "block"
|
||||||
x -> x
|
x -> x
|
||||||
|
|
||||||
instance FromJSON Definition where
|
instance FromJSON Statement where
|
||||||
parseJSON v
|
parseJSON v
|
||||||
= (DefModule <$> parseJSON v)
|
= (StmtModule <$> parseJSON v)
|
||||||
<|> (DefFunction <$> parseJSON v)
|
<|> (StmtFunction <$> parseJSON v)
|
||||||
<|> (DefSend <$> parseJSON v)
|
<|> (StmtSend <$> parseJSON v)
|
||||||
<|> (DefRBlock <$> parseJSON v)
|
<|> (StmtRBlock <$> parseJSON v)
|
||||||
<|> (DefAnything <$> parseJSON v)
|
<|> (StmtAnything <$> parseJSON v)
|
||||||
|
|
||||||
newtype Anything = Anything Value
|
newtype Anything = Anything Value
|
||||||
|
|
||||||
|
|
|
@ -155,14 +155,14 @@ instance References Block where
|
||||||
entries :: forall m . MyMonad m => Block -> m ()
|
entries :: forall m . MyMonad m => Block -> m ()
|
||||||
entries (Block defs) = traverse_ (locally . entries) defs
|
entries (Block defs) = traverse_ (locally . entries) defs
|
||||||
|
|
||||||
instance References Definition where
|
instance References Statement where
|
||||||
entries = \case
|
entries = \case
|
||||||
DefModule m -> entries m
|
StmtModule m -> entries m
|
||||||
DefFunction f -> entries f
|
StmtFunction f -> entries f
|
||||||
DefSend s -> entries s
|
StmtSend s -> entries s
|
||||||
-- TODO:
|
-- TODO:
|
||||||
DefRBlock{} -> pure ()
|
StmtRBlock{} -> pure ()
|
||||||
DefAnything{} -> pure ()
|
StmtAnything{} -> pure ()
|
||||||
|
|
||||||
instance References Module where
|
instance References Module where
|
||||||
entries Module{name, block} = do
|
entries Module{name, block} = do
|
||||||
|
|
Loading…
Reference in a new issue