76 lines
1.4 KiB
Haskell
Raw Normal View History

2020-06-09 15:56:11 +04:00
module AST.Find where
2020-08-03 21:31:24 +04:00
import Control.Monad
2020-06-09 15:56:11 +04:00
2020-08-03 21:31:24 +04:00
import Data.Maybe (listToMaybe)
2020-06-09 15:56:11 +04:00
2020-08-03 21:31:24 +04:00
import Duplo.Tree
import Duplo.Pretty
import Duplo.Lattice
2020-06-09 15:56:11 +04:00
2020-08-03 21:31:24 +04:00
import Data.Text (Text)
2020-06-09 15:56:11 +04:00
2020-08-03 21:31:24 +04:00
import AST.Types
import AST.Scope
2020-07-10 16:13:39 +04:00
2020-08-03 21:31:24 +04:00
import Product
import Range
2020-06-09 15:56:11 +04:00
2020-08-03 21:31:24 +04:00
-- import Debug.Trace
2020-06-09 15:56:11 +04:00
2020-08-03 21:31:24 +04:00
type CanSearch xs =
( Contains [ScopedDecl] xs
, Contains Range xs
, Contains (Maybe Category) xs
, Contains [Text] xs
, Pretty (Product xs)
, Eq (Product xs)
)
2020-06-09 15:56:11 +04:00
2020-08-03 21:31:24 +04:00
findScopedDecl
:: CanSearch xs
=> Range
-> LIGO (Product xs)
-> Maybe ScopedDecl
findScopedDecl pos tree = do
pt <- listToMaybe $ spineTo (\i -> pos `leq` getElem i) tree
let info = extract pt
let fullEnv = getElem info
do
categ <- getElem info
let filtered = filter (ofCategory categ) fullEnv
lookupEnv (ppToText $ void pt) filtered
2020-08-03 21:31:24 +04:00
definitionOf
:: CanSearch xs
=> Range
-> LIGO (Product xs)
-> Maybe Range
definitionOf pos tree =
_sdOrigin <$> findScopedDecl pos tree
typeOf
:: CanSearch xs
=> Range
-> LIGO (Product xs)
-> Maybe (Either (LIGO ()) Kind)
typeOf pos tree =
_sdType =<< findScopedDecl pos tree
implementationOf
:: CanSearch xs
=> Range
-> LIGO (Product xs)
-> Maybe Range
implementationOf pos tree =
_sdBody =<< findScopedDecl pos tree
referencesOf
:: CanSearch xs
=> Range
-> LIGO (Product xs)
-> Maybe [Range]
referencesOf pos tree =
_sdRefs <$> findScopedDecl pos tree