2020-06-09 15:56:11 +04:00
|
|
|
|
|
|
|
module AST.Find where
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- import Control.Monad
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- import AST.Types
|
|
|
|
-- import AST.Scope
|
|
|
|
-- import AST.Parser
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- import Tree
|
|
|
|
-- import Range
|
|
|
|
-- import Pretty
|
|
|
|
-- import Product
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- import Data.Text (Text)
|
|
|
|
-- -- import Debug.Trace
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- type CanSearch xs =
|
|
|
|
-- ( Contains [ScopedDecl] xs
|
|
|
|
-- , Contains Range xs
|
|
|
|
-- , Contains (Maybe Category) xs
|
|
|
|
-- , Contains [Text] xs
|
|
|
|
-- , Pretty (Product xs)
|
|
|
|
-- )
|
2020-07-10 16:13:39 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- findScopedDecl
|
|
|
|
-- :: CanSearch xs
|
|
|
|
-- => Range
|
|
|
|
-- -> Pascal (Product xs)
|
|
|
|
-- -> Maybe ScopedDecl
|
|
|
|
-- findScopedDecl pos tree = do
|
|
|
|
-- pt <- lookupTree pos tree
|
|
|
|
-- let info = infoOf pt
|
|
|
|
-- let fullEnv = getElem info
|
|
|
|
-- do
|
|
|
|
-- categ <- getElem info
|
|
|
|
-- let filtered = filter (ofCategory categ) fullEnv
|
|
|
|
-- lookupEnv (ppToText $ void pt) filtered
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- definitionOf
|
|
|
|
-- :: CanSearch xs
|
|
|
|
-- => Range
|
|
|
|
-- -> Pascal (Product xs)
|
|
|
|
-- -> Maybe Range
|
|
|
|
-- definitionOf pos tree =
|
|
|
|
-- _sdOrigin <$> findScopedDecl pos tree
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- typeOf
|
|
|
|
-- :: CanSearch xs
|
|
|
|
-- => Range
|
|
|
|
-- -> Pascal (Product xs)
|
|
|
|
-- -> Maybe (Either (Pascal ()) Kind)
|
|
|
|
-- typeOf pos tree =
|
|
|
|
-- _sdType =<< findScopedDecl pos tree
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- implementationOf
|
|
|
|
-- :: CanSearch xs
|
|
|
|
-- => Range
|
|
|
|
-- -> Pascal (Product xs)
|
|
|
|
-- -> Maybe Range
|
|
|
|
-- implementationOf pos tree =
|
|
|
|
-- _sdBody =<< findScopedDecl pos tree
|
2020-06-10 22:37:02 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
-- referencesOf
|
|
|
|
-- :: CanSearch xs
|
|
|
|
-- => Range
|
|
|
|
-- -> Pascal (Product xs)
|
|
|
|
-- -> Maybe [Range]
|
|
|
|
-- referencesOf pos tree =
|
|
|
|
-- _sdRefs <$> findScopedDecl pos tree
|