diff --git a/src/Data/Syntax.hs b/src/Data/Syntax.hs index 4c6047687..547ba2746 100644 --- a/src/Data/Syntax.hs +++ b/src/Data/Syntax.hs @@ -289,7 +289,7 @@ instance Ord ErrorStack where data Context a = Context { contextTerms :: NonEmpty a, contextSubject :: a } - deriving (Declarations1, Eq, Foldable, FreeVariables1, Functor, Generic1, Message1, Named1, Ord, Show, ToJSONFields1, Traversable, NFData1) + deriving (Eq, Foldable, FreeVariables1, Functor, Generic1, Message1, Named1, Ord, Show, ToJSONFields1, Traversable, NFData1) instance Diffable Context where subalgorithmFor blur focus (Context n s) = Context <$> traverse blur n <*> focus s @@ -307,3 +307,6 @@ instance Evaluatable Context where instance Tokenize Context where tokenize Context{..} = sequenceA_ (sepTrailing contextTerms) *> contextSubject + +instance Declarations1 Context where + liftDeclaredName declaredName = declaredName . contextSubject diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index ff10c4685..79d9d9e3d 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -16,6 +16,7 @@ import qualified Data.Reprinting.Scope as Scope import Diffing.Algorithm hiding (Delete) import Reprinting.Tokenize import qualified Data.Reprinting.Token as Token +import qualified Data.List.NonEmpty as NonEmpty -- | Typical prefix function application, like `f(x)` in many languages, or `f x` in Haskell. data Call a = Call { callContext :: ![a], callFunction :: !a, callParams :: ![a], callBlock :: !a } @@ -503,7 +504,7 @@ instance Evaluatable InstanceOf -- | ScopeResolution (e.g. import a.b in Python or a::b in C++) newtype ScopeResolution a = ScopeResolution { scopes :: NonEmpty a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1, NFData1) + deriving (Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1, NFData1) instance Hashable1 ScopeResolution where liftHashWithSalt = foldl instance Eq1 ScopeResolution where liftEq = genericLiftEq @@ -514,6 +515,8 @@ instance Evaluatable ScopeResolution where eval eval (ScopeResolution xs) = Rval <$> foldl1 f (fmap (eval >=> address) xs) where f ns id = ns >>= flip evaluateInScopedEnv id +instance Declarations1 ScopeResolution where + liftDeclaredName declaredName = declaredName . NonEmpty.last . scopes -- | A non-null expression such as Typescript or Swift's ! expression. newtype NonNullExpression a = NonNullExpression { nonNullExpression :: a }