Merge branch 'awkure/collect-errors' into 'tooling'

[LIGO-39] Parse whole directory

See merge request serokell/ligo/ligo!10
This commit is contained in:
Anton Myasnikov 2020-09-03 06:26:51 +00:00
commit b48b461c28
2 changed files with 34 additions and 0 deletions

View File

@ -32,8 +32,15 @@ import Duplo.Tree (collect)
import AST hiding (def) import AST hiding (def)
import qualified AST.Find as Find import qualified AST.Find as Find
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Extension
import Parser
import Product import Product
import Range import Range
import System.Directory
import System.FilePath
import System.Posix.Files
-- import Error -- import Error
main :: IO () main :: IO ()
@ -283,6 +290,31 @@ collectErrors funs uri path version = do
Nothing -> error "TODO: implement URI file loading" Nothing -> error "TODO: implement URI file loading"
data ParsedContract = ParsedContract
{ cPath :: FilePath
, cTree :: LIGO Info
, cErr :: [Msg]
}
-- | Parse whole directory for ligo contracts and collect the results.
-- This ignores every other file which is not a contract.
parseContracts :: FilePath -> IO [ParsedContract]
parseContracts top = let
exclude p = p /= "." && p /= ".." in do
ds <- getDirectoryContents top
contracts <- forM (filter exclude ds) $ \d -> do
let p = top </> d
s <- getFileStatus p
if isDirectory s
then parseContracts p
else do
putStrLn $ "parsing: " ++ show p
contract <- try @UnsupportedExtension $ parse (Path p)
case contract of
Right (tree, errs) -> return $ [ParsedContract p tree errs]
Left _ -> return []
return (concat contracts)
errorToDiag :: (Range, Err Text a) -> J.Diagnostic errorToDiag :: (Range, Err Text a) -> J.Diagnostic
errorToDiag (getRange -> (Range (sl, sc, _) (el, ec, _) _), Err what) = errorToDiag (getRange -> (Range (sl, sc, _) (el, ec, _) _), Err what) =
J.Diagnostic J.Diagnostic

View File

@ -76,6 +76,8 @@ executables:
- interpolate - interpolate
- lens - lens
- ligo-squirrel - ligo-squirrel
- directory
- unix
- stm - stm
main: Main.hs main: Main.hs