1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Clean up some instances

This commit is contained in:
Patrick Thomson 2020-01-14 15:28:04 -05:00
parent ae4ca650e8
commit 760c52e04f
2 changed files with 10 additions and 15 deletions

View File

@ -94,8 +94,7 @@ instance ToScopeGraph Py.DictionarySplat where scopeGraph = todo
deriving instance ToScopeGraph Py.Expression deriving instance ToScopeGraph Py.Expression
instance ToScopeGraph Py.ElseClause where instance ToScopeGraph Py.ElseClause where scopeGraph = onField @"body"
scopeGraph (Py.ElseClause _ elc) = scopeGraph elc
instance ToScopeGraph Py.ElifClause where instance ToScopeGraph Py.ElifClause where
scopeGraph (Py.ElifClause _ body condition) = mappend <$> scopeGraph condition <*> scopeGraph body scopeGraph (Py.ElifClause _ body condition) = mappend <$> scopeGraph condition <*> scopeGraph body
@ -110,11 +109,9 @@ instance ToScopeGraph Py.ExpressionStatement where scopeGraph = onChildren
instance ToScopeGraph Py.ExpressionList where scopeGraph = onChildren instance ToScopeGraph Py.ExpressionList where scopeGraph = onChildren
instance ToScopeGraph Py.False where instance ToScopeGraph Py.False where scopeGraph _ = pure mempty
scopeGraph _ = pure mempty
instance ToScopeGraph Py.FinallyClause where instance ToScopeGraph Py.FinallyClause where scopeGraph = onField @"extraChildren"
scopeGraph (Py.FinallyClause _ block) = scopeGraph block
instance ToScopeGraph Py.Float where scopeGraph = const (pure mempty) instance ToScopeGraph Py.Float where scopeGraph = const (pure mempty)
@ -167,14 +164,12 @@ instance ToScopeGraph Py.ReturnStatement where
instance ToScopeGraph Py.True where instance ToScopeGraph Py.True where
scopeGraph _ = pure mempty scopeGraph _ = pure mempty
instance ToScopeGraph Py.NotOperator where instance ToScopeGraph Py.NotOperator where scopeGraph = onField @"argument"
scopeGraph (Py.NotOperator _ arg) = scopeGraph arg
instance ToScopeGraph Py.Pair where instance ToScopeGraph Py.Pair where
scopeGraph (Py.Pair _ value key) = mappend <$> scopeGraph key <*> scopeGraph value scopeGraph (Py.Pair _ value key) = mappend <$> scopeGraph key <*> scopeGraph value
instance ToScopeGraph Py.ParenthesizedExpression where instance ToScopeGraph Py.ParenthesizedExpression where scopeGraph = onField "extraChildren"
scopeGraph (Py.ParenthesizedExpression _ e) = scopeGraph e
instance ToScopeGraph Py.PassStatement where scopeGraph _ = pure mempty instance ToScopeGraph Py.PassStatement where scopeGraph _ = pure mempty
@ -185,8 +180,7 @@ deriving instance ToScopeGraph Py.PrimaryExpression
deriving instance ToScopeGraph Py.SimpleStatement deriving instance ToScopeGraph Py.SimpleStatement
instance ToScopeGraph Py.RaiseStatement where instance ToScopeGraph Py.RaiseStatement where scopeGraph = todo
scopeGraph = todo
instance ToScopeGraph Py.Set where scopeGraph = onChildren instance ToScopeGraph Py.Set where scopeGraph = onChildren
@ -204,8 +198,7 @@ instance ToScopeGraph Py.TryStatement where
els <- traverse scopeGraph elseClauses els <- traverse scopeGraph elseClauses
pure (fold (NonEmpty.cons bod els)) pure (fold (NonEmpty.cons bod els))
instance ToScopeGraph Py.UnaryOperator where instance ToScopeGraph Py.UnaryOperator where scopeGraph = onField @"argument"
scopeGraph (Py.UnaryOperator _ _ arg) = scopeGraph arg
instance ToScopeGraph Py.WhileStatement where instance ToScopeGraph Py.WhileStatement where
scopeGraph Py.WhileStatement{ alternative, body, condition } = do scopeGraph Py.WhileStatement{ alternative, body, condition } = do

View File

@ -2,6 +2,7 @@
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
@ -19,6 +20,7 @@ import Data.Name (Name)
import Data.Typeable import Data.Typeable
import GHC.Generics import GHC.Generics
import GHC.Records import GHC.Records
import GHC.TypeLits
import Source.Loc import Source.Loc
class Typeable t => ToScopeGraph t where class Typeable t => ToScopeGraph t where
@ -46,7 +48,7 @@ instance (ToScopeGraph l, ToScopeGraph r) => ToScopeGraph (l :+: r) where
scopeGraph (R1 r) = scopeGraph r scopeGraph (R1 r) = scopeGraph r
onField :: onField ::
forall field syn sig m r . forall (field :: Symbol) syn sig m r .
( Has (Sketch Name) sig m ( Has (Sketch Name) sig m
, HasField field (r Loc) (syn Loc) , HasField field (r Loc) (syn Loc)
, ToScopeGraph syn , ToScopeGraph syn