Skip to content

Commit

Permalink
remove dependency on ghc-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
hexwell committed Jul 7, 2022
1 parent ab7d1a7 commit 2ee9243
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions hs/Vflow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import Control.Category ((>>>))
import Control.Monad (foldM_)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Except (ExceptT, except, runExceptT)
import Data.Composition ((.:))
import Data.Function ((&))
import Data.List (intercalate)
import GHC.Utils.Misc (split)
import GHC.Utils.Monad (concatMapM)
import System.Environment (getArgs)
import System.Info (os)
import Text.Parsec (ParseError, Parsec, runParser)
Expand All @@ -30,6 +29,12 @@ parse parser state filename = do
parseVflow :: String -> Parser [Block]
parseVflow "bash" = fmap (NewFile:) . parse V.parser (V.ParserState "#" 1 2)

split :: Char -> String -> [String]
split c s = case rest of
[] -> [chunk]
_:rest -> chunk : split c rest
where (chunk, rest) = break (==c) s

base :: Char -> Filename -> Path
base c f = split c f & init & intercalate [c]

Expand All @@ -40,6 +45,9 @@ parseBash = flip (parse B.parser) <*> (base sep >>> (B.ParserState sep))
"linux" -> '/'
"mingw32" -> '\\'

concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM = fmap concat .: mapM

parseRoot :: String -> Filename -> IO (Either ParseError [Block])
parseRoot l@"bash" rootFile = allFiles >>= concatMapM (parseVflow l) & runExceptT
where
Expand Down

0 comments on commit 2ee9243

Please sign in to comment.