Look for references in a few more places

This commit is contained in:
Frederik Hanghøj Iversen 2019-10-16 22:35:15 +02:00
parent ebf62b8d4f
commit 4463077e55
2 changed files with 25 additions and 8 deletions

View File

@ -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

View File

@ -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 ()