1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 00:42:33 +03:00

parseFilePath.

This commit is contained in:
Patrick Thomson 2019-09-20 11:52:39 -04:00
parent aebbfc4706
commit a5d9367906
2 changed files with 5 additions and 6 deletions

View File

@ -45,7 +45,7 @@ testForExample = \case
("parses " <> Path.toString parseOutput)
(\ref new -> ["git", "diff", ref, new])
(Path.toString parseOutput)
(parseFilePath ?session (Path.toString file) >>= either throw (pure . BL.fromStrict))
(parseFilePath ?session file >>= either throw (pure . BL.fromStrict))
-- | Return all the examples from the given directory. Examples are expected to

View File

@ -76,7 +76,6 @@ import Semantic.Api hiding (File, Blob, BlobPair)
import System.Exit (die)
import Control.Exception (displayException)
import qualified System.Path as Path
import qualified System.Path.PartClass as Part
runBuilder :: Builder -> ByteString
runBuilder = toStrict . toLazyByteString
@ -90,10 +89,10 @@ instance IsString Name where
diffFilePaths :: TaskSession -> Both FilePath -> IO ByteString
diffFilePaths session paths = readFilePathPair paths >>= runTask session . parseDiffBuilder @[] DiffSExpression . pure >>= either (die . displayException) (pure . runBuilder)
-- | Returns an s-expression parse tree for the specified FilePath.
parseFilePath :: TaskSession -> FilePath -> IO (Either SomeException ByteString)
-- | Returns an s-expression parse tree for the specified path.
parseFilePath :: TaskSession -> Path.RelFile -> IO (Either SomeException ByteString)
parseFilePath session path = do
blob <- readBlobFromFile (fileForPath path)
blob <- readBlobFromFile (fileForPath (Path.toString path))
res <- runTask session $ parseTermBuilder TermSExpression (toList blob)
pure (runBuilder <$> res)
@ -102,7 +101,7 @@ readFilePathPair :: Both FilePath -> IO BlobPair
readFilePathPair paths = let paths' = fmap fileForPath paths in
runBothWith readFilePair paths'
parseTestFile :: Part.AbsRel ar => Parser term -> Path.File ar -> IO (Blob, term)
parseTestFile :: Parser term -> Path.RelFile -> IO (Blob, term)
parseTestFile parser path = runTaskOrDie $ do
blob <- readBlob (fileForPath (Path.toString path))
term <- parse parser blob