From b20a85c2f35375daa002076eebefaa7f6cd96529 Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Sun, 4 Feb 2024 14:43:01 +0300 Subject: [PATCH 1/2] Remove redundant extension --- eo-phi-normalizer/app/Main.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/eo-phi-normalizer/app/Main.hs b/eo-phi-normalizer/app/Main.hs index 3cbec37d5..0d686bd7c 100644 --- a/eo-phi-normalizer/app/Main.hs +++ b/eo-phi-normalizer/app/Main.hs @@ -1,6 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} From c5a71b696c0ae3ea1fd36755b24ecf9feec2343a Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Sun, 4 Feb 2024 14:43:39 +0300 Subject: [PATCH 2/2] Add support for `outPath` CLI parameter --- eo-phi-normalizer/app/Main.hs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/eo-phi-normalizer/app/Main.hs b/eo-phi-normalizer/app/Main.hs index 0d686bd7c..df4cef5ac 100644 --- a/eo-phi-normalizer/app/Main.hs +++ b/eo-phi-normalizer/app/Main.hs @@ -15,6 +15,7 @@ import Language.EO.Phi (Object (Formation), Program (Program), defaultMain, pars import Language.EO.Phi.Rules.Common (Context (..), applyRules, applyRulesChain) import Language.EO.Phi.Rules.Yaml import Options.Generic +import System.IO (IOMode (WriteMode), hClose, hPutStr, hPutStrLn, openFile, stdout) data CLINamedParams = CLINamedParams { chain :: Bool @@ -40,8 +41,11 @@ main = do let (CLINamedParams{..}) = params case rulesYaml of Just path -> do + handle <- maybe (pure stdout) (`openFile` WriteMode) outPath + let logStr = hPutStr handle + let logStrLn = hPutStrLn handle ruleSet <- parseRuleSetFromFile path - putStrLn ruleSet.title + logStrLn ruleSet.title src <- maybe getContents readFile inPath let progOrError = parseProgram src case progOrError of @@ -52,18 +56,18 @@ main = do | otherwise = pure <$> applyRules (Context (convertRule <$> ruleSet.rules)) (Formation bindings) uniqueResults = nub results totalResults = length uniqueResults - -- TODO #48:15m use outPath to output to file if provided - putStrLn "Input:" - putStrLn (printTree input) - putStrLn "====================================================" + logStrLn "Input:" + logStrLn (printTree input) + logStrLn "====================================================" forM_ (zip [1 ..] uniqueResults) $ \(i, steps) -> do - putStrLn $ + logStrLn $ "Result " <> show i <> " out of " <> show totalResults <> ":" let n = length steps forM_ (zip [1 ..] steps) $ \(k, step) -> do - Control.Monad.when chain $ do - putStr ("[ " <> show k <> " / " <> show n <> " ]") - putStrLn (printTree step) - putStrLn "----------------------------------------------------" + Control.Monad.when chain $ + logStr ("[ " <> show k <> " / " <> show n <> " ]") + logStrLn (printTree step) + logStrLn "----------------------------------------------------" + hClose handle -- TODO #48:15m still need to consider `chain` (should rewrite/change defaultMain to mainWithOptions) Nothing -> defaultMain