1
1
mirror of https://github.com/github/semantic.git synced 2024-12-14 08:25:32 +03:00

Simplify in terms of an insertReference helper.

This commit is contained in:
Rob Rix 2018-12-06 11:14:35 -05:00
parent b3ef26f301
commit 9375a82be2

View File

@ -146,7 +146,7 @@ reference ref decl@Declaration{..} currentAddress g = fromMaybe g $ do
go currentScope' currentAddress id
where
go currentScope address path
= flip (insertScope currentAddress) g . modifyReferences currentScope . Map.insert ref . path . DPath decl . snd <$> lookupDeclaration unDeclaration address g
= flip (insertScope currentAddress) g . flip (insertReference ref) currentScope . path . DPath decl . snd <$> lookupDeclaration unDeclaration address g
<|> traverseEdges' Superclass <|> traverseEdges' Import <|> traverseEdges' Lexical
where traverseEdges' edge = linksOfScope address g >>= Map.lookup edge >>= traverseEdges path (go currentScope) edge
@ -155,7 +155,7 @@ insertImportReference :: Ord address => Reference -> Declaration -> address -> S
insertImportReference ref decl@Declaration{..} currentAddress g scope = go currentAddress (EPath Import currentAddress)
where
go address path
= modifyReferences scope . Map.insert ref . path . DPath decl . snd <$> lookupDeclaration unDeclaration address g
= flip (insertReference ref) scope . path . DPath decl . snd <$> lookupDeclaration unDeclaration address g
<|> traverseEdges' Superclass <|> traverseEdges' Export <|> traverseEdges' Import <|> traverseEdges' Lexical
where traverseEdges' edge = linksOfScope address g >>= Map.lookup edge >>= traverseEdges path go edge
@ -168,8 +168,8 @@ lookupScopePath declaration currentAddress g = go currentAddress id
<|> traverseEdges' Superclass <|> traverseEdges' Export <|> traverseEdges' Import <|> traverseEdges' Lexical
where traverseEdges' edge = linksOfScope address g >>= Map.lookup edge >>= traverseEdges path go edge
modifyReferences :: Scope scopeAddress -> (Map Reference (Path scopeAddress) -> Map Reference (Path scopeAddress)) -> Scope scopeAddress
modifyReferences scope f = scope { references = f (references scope) }
insertReference :: Reference -> Path scopeAddress -> Scope scopeAddress -> Scope scopeAddress
insertReference ref path scope = scope { references = Map.insert ref path (references scope) }
traverseEdges :: Foldable t => (Path scopeAddress -> Path scopeAddress) -> (scopeAddress -> (Path scopeAddress -> Path scopeAddress) -> Maybe a) -> EdgeLabel -> t scopeAddress -> Maybe a
-- Return the first path to the declaration through the scopes.