From 4463077e55ce935c632c0ffd6620babd1b8a74eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Hangh=C3=B8j=20Iversen?= Date: Wed, 16 Oct 2019 22:35:15 +0200 Subject: [PATCH] Look for references in a few more places --- src/Data/Language/Ruby/AST.hs | 23 ++++++++++++++++++----- src/Rubyhs/References.hs | 10 +++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Data/Language/Ruby/AST.hs b/src/Data/Language/Ruby/AST.hs index 64d1ed0..3bac700 100644 --- a/src/Data/Language/Ruby/AST.hs +++ b/src/Data/Language/Ruby/AST.hs @@ -12,6 +12,7 @@ module Data.Language.Ruby.AST , RBlock(..) , Casgn(..) , RArray(..) + , RArgs(..) , Anything(..) ) where @@ -137,7 +138,7 @@ deriving newtype instance FromJSON Anything -- end data RBlock = RBlock { send :: Send - , args :: Args + , args :: RArgs , block :: Block } @@ -156,6 +157,19 @@ instance FromJSON RBlock where <*> parseJSON block _ -> empty +-- | It's super confusing that I've already defined a node in my AST +-- called args. This one correspond to the AST node with the label +-- "args" as reported by `ruby-parse`. +newtype RArgs = RArgs Anything + +deriving stock instance Show RArgs +deriving stock instance Ord RArgs +deriving stock instance Eq RArgs +deriving stock instance Generic RArgs +instance ToJSON RArgs where + toEncoding = Aeson.genericToEncoding aesonOptions +deriving newtype instance FromJSON RArgs + newtype Namespace = Namespace [Name] deriving newtype instance Semigroup Namespace @@ -237,18 +251,17 @@ deriving stock instance Generic Function instance ToJSON Function where toEncoding = Aeson.genericToEncoding aesonOptions -newtype Args = Args Anything +data Args = Args [Statement] deriving stock instance Show Args -instance Ord Args where - compare = coerce compareValue +deriving stock instance Ord Args deriving stock instance Eq Args deriving stock instance Generic Args instance ToJSON Args where toEncoding = Aeson.genericToEncoding aesonOptions instance FromJSON Args where - parseJSON = pure . coerce + parseJSON = withArray "Args" $ \xs -> Args <$> traverse parseJSON (toList xs) instance FromJSON Function where parseJSON = withArray "Function" $ \case diff --git a/src/Rubyhs/References.hs b/src/Rubyhs/References.hs index 1376ec9..014ed98 100644 --- a/src/Rubyhs/References.hs +++ b/src/Rubyhs/References.hs @@ -191,13 +191,17 @@ instance References Statement where StmtArray a -> entries a StmtAnything a -> entries a --- TODO instance References Ruby.RBlock where + entries RBlock{send,args,block} = do + entries send + entries args + entries block +instance References Ruby.RArgs where entries = const $ pure () instance References Ruby.Casgn where - entries = const $ pure () + entries Casgn{name, statement} = entries statement instance References Ruby.RArray where - entries = const $ pure () + entries RArray{statements} = traverse_ entries statements instance References Ruby.Anything where entries = const $ pure ()