1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Parse packages in Task.

This commit is contained in:
Rob Rix 2018-04-04 16:36:12 -04:00
parent 3cc6434db0
commit eb9b9a0e4b
2 changed files with 22 additions and 2 deletions

View File

@ -16,6 +16,9 @@ module Semantic.Task
, time
-- * High-level flow
, parse
, parseModule
, parseModules
, parsePackage
, analyze
, decorate
, diff
@ -55,6 +58,7 @@ import Data.Abstract.Address
import qualified Data.Abstract.Evaluatable as Analysis
import Data.Abstract.FreeVariables
import Data.Abstract.Located
import Data.Abstract.Module
import Data.Abstract.Package as Package
import Data.Abstract.Value (Value)
import Data.Blob
@ -101,6 +105,21 @@ type Renderer i o = i -> o
parse :: Member TaskF effs => Parser term -> Blob -> Eff effs term
parse parser = send . Parse parser
-- | Parse a file into a 'Module'.
parseModule :: Members '[IO.Files, TaskF] effs => Parser term -> Maybe FilePath -> FilePath -> Eff effs (Module term)
parseModule parser rootDir path = do
blob <- head <$> IO.readBlobs (Right [(path, IO.languageForFilePath path)])
moduleForBlob rootDir blob <$> parse parser blob
-- | Parse a list of files into 'Module's.
parseModules :: Parser term -> FilePath -> [FilePath] -> Task [Module term]
parseModules parser rootDir = traverse (parseModule parser (Just rootDir))
-- | Parse a list of files into a 'Package'.
parsePackage :: PackageName -> Parser term -> FilePath -> [FilePath] -> Task (Package term)
parsePackage name parser rootDir paths = Package (PackageInfo name Nothing) . Package.fromModules <$> parseModules parser rootDir paths
-- | A task running some 'Analysis.MonadAnalysis' to completion.
analyze :: Member TaskF effs => Analysis.SomeAnalysis m result -> Eff effs result
analyze = send . Analyze

View File

@ -35,7 +35,8 @@ import Parsing.Parser
import Prologue
import Semantic.Diff (diffTermPair)
import Semantic.IO as IO
import Semantic.Task
import Semantic.Task hiding (parsePackage)
import qualified Semantic.Task as Task
import System.FilePath.Posix
import qualified Language.Go.Assignment as Go
@ -227,7 +228,7 @@ parseFiles :: Parser term -> FilePath -> [FilePath] -> IO [Module term]
parseFiles parser rootDir = traverse (parseFile parser (Just rootDir))
parsePackage :: PackageName -> Parser term -> FilePath -> [FilePath] -> IO (Package term)
parsePackage name parser rootDir files = Package (PackageInfo name Nothing) . Package.fromModules <$> parseFiles parser rootDir files
parsePackage name parser rootDir = runTask . Task.parsePackage name parser rootDir
-- Read a file from the filesystem into a Blob.