1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 18:36:27 +03:00

Pick out delcarations for ScopeResolution and through Context better

This commit is contained in:
Timothy Clem 2018-11-26 13:43:20 -08:00
parent e2ac46ae69
commit 14600029fd
2 changed files with 8 additions and 2 deletions

View File

@ -289,7 +289,7 @@ instance Ord ErrorStack where
data Context a = Context { contextTerms :: NonEmpty a, contextSubject :: a } 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 instance Diffable Context where
subalgorithmFor blur focus (Context n s) = Context <$> traverse blur n <*> focus s subalgorithmFor blur focus (Context n s) = Context <$> traverse blur n <*> focus s
@ -307,3 +307,6 @@ instance Evaluatable Context where
instance Tokenize Context where instance Tokenize Context where
tokenize Context{..} = sequenceA_ (sepTrailing contextTerms) *> contextSubject tokenize Context{..} = sequenceA_ (sepTrailing contextTerms) *> contextSubject
instance Declarations1 Context where
liftDeclaredName declaredName = declaredName . contextSubject

View File

@ -16,6 +16,7 @@ import qualified Data.Reprinting.Scope as Scope
import Diffing.Algorithm hiding (Delete) import Diffing.Algorithm hiding (Delete)
import Reprinting.Tokenize import Reprinting.Tokenize
import qualified Data.Reprinting.Token as Token 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. -- | 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 } 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++) -- | ScopeResolution (e.g. import a.b in Python or a::b in C++)
newtype ScopeResolution a = ScopeResolution { scopes :: NonEmpty a } 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 Hashable1 ScopeResolution where liftHashWithSalt = foldl
instance Eq1 ScopeResolution where liftEq = genericLiftEq 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) eval eval (ScopeResolution xs) = Rval <$> foldl1 f (fmap (eval >=> address) xs)
where f ns id = ns >>= flip evaluateInScopedEnv id 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. -- | A non-null expression such as Typescript or Swift's ! expression.
newtype NonNullExpression a = NonNullExpression { nonNullExpression :: a } newtype NonNullExpression a = NonNullExpression { nonNullExpression :: a }