ehaskell 0.3 → 0.4
raw patch · 2 files changed
+25/−12 lines, 2 filesdep +utf8-string
Dependencies added: utf8-string
Files
- Main.hs +23/−10
- ehaskell.cabal +2/−2
Main.hs view
@@ -5,14 +5,21 @@ import System.Directory.Tools (doesNotExistOrOldThan) import System.Process (runProcess, waitForProcess) import System.FilePath (takeDirectory, takeFileName)+import System.Exit (ExitCode(ExitSuccess), exitWith)+import Control.Monad (when) import Control.Monad.Tools (whenM, unlessM, skipRet) import Control.Applicative ((<$>)) import Text.RegexPR (gsubRegexPR) import Text.ParserCombinators.MTLParse+ (Parse, runParse, ParseT, evalParseT,+ spot, token, tokenBack, tokens, parseNot,+ still, greedyList, list, neList, greedyNeList,+ mplus, endOfInput, lift) import YJTools.Tribial (ghcMake) import Data.Char (isSpace)-import Data.Maybe (maybeToList) import Data.Function.Tools (applyUnless)+import Prelude hiding (readFile, writeFile)+import System.IO.UTF8 (readFile, writeFile) ehaskellDir, haskellSffx, ehsHandleStr, putStrStr :: String ehaskellDir = "_ehs/"@@ -35,11 +42,15 @@ copyRequiredFile edir cont whenM (doesNotExistOrOldThan srcFile infile) $ writeFile srcFile $ fst $ head $ runParse parseAll ("", cont)- whenM (doesNotExistOrOldThan exeFile srcFile) $- ghcMake exeName edir >> return ()- runProcess exeFile (maybeToList outfile) Nothing Nothing Nothing Nothing Nothing- >>= waitForProcess- return ()+ whenM (doesNotExistOrOldThan exeFile srcFile) $ do+ ec <- ghcMake exeName edir+ when (ec /= ExitSuccess) $ exitWith ec+ case outfile of+ Nothing -> do runProcess exeFile [] Nothing Nothing Nothing Nothing Nothing >>= waitForProcess+ return ()+ Just fn -> whenM (doesNotExistOrOldThan fn exeFile) $ do+ runProcess exeFile [fn] Nothing Nothing Nothing Nothing Nothing >>= waitForProcess+ return () copyRequiredFile :: FilePath -> String -> IO () copyRequiredFile dir src = evalParseT (copyRequiredFileParse dir) ("",src) >> return ()@@ -78,7 +89,7 @@ :: Parse Char (Bool, String) parseApplyBegin, parseApplyContinue, parseApplyEnd :: Parse Char String-mkOutputText, mkOutputHere,+mkOutputText, mkOutputTop, mkOutputHere, mkOutputCode, mkOutputShowCode, mkOutputReturnCode, mkOutputReturnShowCode :: String -> String getHandleStr :: String@@ -86,7 +97,8 @@ parseAll = ( myConcat . ((False, "main = do {\n"++getHandleStr):) . (++[(False, " hClose " ++ ehsHandleStr ++ " }\n")])- . ((True, "import System.IO (stdout, hPutStr, openFile, IOMode(WriteMode), hClose)\n"):)+ . ((True, "import System.IO (stdout, openFile, IOMode(WriteMode), hClose)\n"):)+ . ((True, "import System.IO.UTF8 (hPutStr)\n"):) . ((True, "import System.Environment (getArgs)\n"):) ) <$> parse >>= endOfInput @@ -158,7 +170,7 @@ tokens "<%%" code <- parseInner tokens "%%>"- return $ (True, code ++ ";\n")+ return $ (True, mkOutputTop code) parseApply = do b <- parseApplyBegin@@ -197,7 +209,8 @@ spot (const True) mkOutputText txt = " " ++ putStrStr ++ " $ " ++ show txt ++ ";\n"-mkOutputHere code = " (" ++ code ++ ")" ++ ";\n"+mkOutputTop code = code ++ ";\n"+mkOutputHere code = " " ++ code ++ ";\n" mkOutputCode code = " (" ++ code ++ ") >>= " ++ putStrStr ++ ";\n" mkOutputShowCode code = " (" ++ code ++ ") >>= " ++ putStrStr ++ ". show ;\n" mkOutputReturnCode code = " " ++ putStrStr ++ " $ (" ++ code ++ ") ;\n"
ehaskell.cabal view
@@ -1,5 +1,5 @@ Name: ehaskell-Version: 0.3+Version: 0.4 Cabal-Version: >= 1.2 Build-Type: Simple License: GPL@@ -44,5 +44,5 @@ Executable ehs Main-Is: Main.hs- Build-Depends: base, mtlparse >= 0.0.1, yjtools >= 0.8, directory, regexpr >= 0.3.3, process, filepath+ Build-Depends: base, mtlparse >= 0.0.1, yjtools >= 0.8, directory, regexpr >= 0.3.3, process, filepath, utf8-string GHC-Options: -Wall