From 760c52e04f0f1595e06d898e4d01d922bb3da2ae Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Tue, 14 Jan 2020 15:28:04 -0500 Subject: [PATCH] Clean up some instances --- semantic-python/src/Language/Python.hs | 21 +++++++------------ .../src/Convert/ToScopeGraph.hs | 4 +++- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/semantic-python/src/Language/Python.hs b/semantic-python/src/Language/Python.hs index d6c885e55..684816f2a 100644 --- a/semantic-python/src/Language/Python.hs +++ b/semantic-python/src/Language/Python.hs @@ -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 diff --git a/semantic-scope-graph/src/Convert/ToScopeGraph.hs b/semantic-scope-graph/src/Convert/ToScopeGraph.hs index 689a9eb3f..b7caaecbb 100644 --- a/semantic-scope-graph/src/Convert/ToScopeGraph.hs +++ b/semantic-scope-graph/src/Convert/ToScopeGraph.hs @@ -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