Look for references in a few more places
This commit is contained in:
parent
ebf62b8d4f
commit
4463077e55
|
@ -12,6 +12,7 @@ module Data.Language.Ruby.AST
|
||||||
, RBlock(..)
|
, RBlock(..)
|
||||||
, Casgn(..)
|
, Casgn(..)
|
||||||
, RArray(..)
|
, RArray(..)
|
||||||
|
, RArgs(..)
|
||||||
, Anything(..)
|
, Anything(..)
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ deriving newtype instance FromJSON Anything
|
||||||
-- end
|
-- end
|
||||||
data RBlock = RBlock
|
data RBlock = RBlock
|
||||||
{ send :: Send
|
{ send :: Send
|
||||||
, args :: Args
|
, args :: RArgs
|
||||||
, block :: Block
|
, block :: Block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +157,19 @@ instance FromJSON RBlock where
|
||||||
<*> parseJSON block
|
<*> parseJSON block
|
||||||
_ -> empty
|
_ -> 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]
|
newtype Namespace = Namespace [Name]
|
||||||
|
|
||||||
deriving newtype instance Semigroup Namespace
|
deriving newtype instance Semigroup Namespace
|
||||||
|
@ -237,18 +251,17 @@ deriving stock instance Generic Function
|
||||||
instance ToJSON Function where
|
instance ToJSON Function where
|
||||||
toEncoding = Aeson.genericToEncoding aesonOptions
|
toEncoding = Aeson.genericToEncoding aesonOptions
|
||||||
|
|
||||||
newtype Args = Args Anything
|
data Args = Args [Statement]
|
||||||
|
|
||||||
deriving stock instance Show Args
|
deriving stock instance Show Args
|
||||||
instance Ord Args where
|
deriving stock instance Ord Args
|
||||||
compare = coerce compareValue
|
|
||||||
deriving stock instance Eq Args
|
deriving stock instance Eq Args
|
||||||
deriving stock instance Generic Args
|
deriving stock instance Generic Args
|
||||||
instance ToJSON Args where
|
instance ToJSON Args where
|
||||||
toEncoding = Aeson.genericToEncoding aesonOptions
|
toEncoding = Aeson.genericToEncoding aesonOptions
|
||||||
|
|
||||||
instance FromJSON Args where
|
instance FromJSON Args where
|
||||||
parseJSON = pure . coerce
|
parseJSON = withArray "Args" $ \xs -> Args <$> traverse parseJSON (toList xs)
|
||||||
|
|
||||||
instance FromJSON Function where
|
instance FromJSON Function where
|
||||||
parseJSON = withArray "Function" $ \case
|
parseJSON = withArray "Function" $ \case
|
||||||
|
|
|
@ -191,13 +191,17 @@ instance References Statement where
|
||||||
StmtArray a -> entries a
|
StmtArray a -> entries a
|
||||||
StmtAnything a -> entries a
|
StmtAnything a -> entries a
|
||||||
|
|
||||||
-- TODO
|
|
||||||
instance References Ruby.RBlock where
|
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 ()
|
entries = const $ pure ()
|
||||||
instance References Ruby.Casgn where
|
instance References Ruby.Casgn where
|
||||||
entries = const $ pure ()
|
entries Casgn{name, statement} = entries statement
|
||||||
instance References Ruby.RArray where
|
instance References Ruby.RArray where
|
||||||
entries = const $ pure ()
|
entries RArray{statements} = traverse_ entries statements
|
||||||
instance References Ruby.Anything where
|
instance References Ruby.Anything where
|
||||||
entries = const $ pure ()
|
entries = const $ pure ()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue