From 60445d6bb821cb29f30f54d4ec63830bf4e3bc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Hangh=C3=B8j=20Iversen?= Date: Mon, 14 Oct 2019 20:25:09 +0200 Subject: [PATCH] Rename Definition to Statement --- src/Data/Language/Ruby.hs | 46 +++++++++++++++++++-------------------- src/Rubyhs/References.hs | 12 +++++----- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Data/Language/Ruby.hs b/src/Data/Language/Ruby.hs index 4b87688..31e4b61 100644 --- a/src/Data/Language/Ruby.hs +++ b/src/Data/Language/Ruby.hs @@ -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 diff --git a/src/Rubyhs/References.hs b/src/Rubyhs/References.hs index 938ca38..6699d6b 100644 --- a/src/Rubyhs/References.hs +++ b/src/Rubyhs/References.hs @@ -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