1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +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
instance ToScopeGraph Py.ElseClause where
scopeGraph (Py.ElseClause _ elc) = scopeGraph elc
instance ToScopeGraph Py.ElseClause where scopeGraph = onField @"body"
instance ToScopeGraph Py.ElifClause where
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.False where
scopeGraph _ = pure mempty
instance ToScopeGraph Py.False where scopeGraph _ = pure mempty
instance ToScopeGraph Py.FinallyClause where
scopeGraph (Py.FinallyClause _ block) = scopeGraph block
instance ToScopeGraph Py.FinallyClause where scopeGraph = onField @"extraChildren"
instance ToScopeGraph Py.Float where scopeGraph = const (pure mempty)
@ -167,14 +164,12 @@ instance ToScopeGraph Py.ReturnStatement where
instance ToScopeGraph Py.True where
scopeGraph _ = pure mempty
instance ToScopeGraph Py.NotOperator where
scopeGraph (Py.NotOperator _ arg) = scopeGraph arg
instance ToScopeGraph Py.NotOperator where scopeGraph = onField @"argument"
instance ToScopeGraph Py.Pair where
scopeGraph (Py.Pair _ value key) = mappend <$> scopeGraph key <*> scopeGraph value
instance ToScopeGraph Py.ParenthesizedExpression where
scopeGraph (Py.ParenthesizedExpression _ e) = scopeGraph e
instance ToScopeGraph Py.ParenthesizedExpression where scopeGraph = onField "extraChildren"
instance ToScopeGraph Py.PassStatement where scopeGraph _ = pure mempty
@ -185,8 +180,7 @@ deriving instance ToScopeGraph Py.PrimaryExpression
deriving instance ToScopeGraph Py.SimpleStatement
instance ToScopeGraph Py.RaiseStatement where
scopeGraph = todo
instance ToScopeGraph Py.RaiseStatement where scopeGraph = todo
instance ToScopeGraph Py.Set where scopeGraph = onChildren
@ -204,8 +198,7 @@ instance ToScopeGraph Py.TryStatement where
els <- traverse scopeGraph elseClauses
pure (fold (NonEmpty.cons bod els))
instance ToScopeGraph Py.UnaryOperator where
scopeGraph (Py.UnaryOperator _ _ arg) = scopeGraph arg
instance ToScopeGraph Py.UnaryOperator where scopeGraph = onField @"argument"
instance ToScopeGraph Py.WhileStatement where
scopeGraph Py.WhileStatement{ alternative, body, condition } = do

View File

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