diff --git a/src/System/Console/Hawk.hs b/src/System/Console/Hawk.hs index aaaf1a8..66461c0 100644 --- a/src/System/Console/Hawk.hs +++ b/src/System/Console/Hawk.hs @@ -122,15 +122,15 @@ hawk config opts expr_str file = do -- eval program based on the existence of a delimiter case (optDelimiter opts,optMap opts) of (Nothing,_) -> - interpret (runExpr [printRows ignoreErrors, expr_str]) + interpret (runExpr file [printRows ignoreErrors, expr_str]) (as :: IO ()) (Just d,False) -> - interpret (runExpr [printRows ignoreErrors, expr_str, parseRows d]) + interpret (runExpr file [printRows ignoreErrors, expr_str, parseRows d]) (as :: IO ()) -- TODO: avoid keep everything in buffer, repr' should output -- as soon as possible (for example each line) (Just d,True) -> - interpret (runExprs [runMap [printRow ignoreErrors, expr_str] + interpret (runExprs file [runMap [printRow ignoreErrors, expr_str] ,parseRows d]) (as :: IO ()) case maybe_f of @@ -140,13 +140,13 @@ hawk config opts expr_str file = do compose :: [String] -> String compose = L.intercalate "." . P.map (printf "(%s)") - runExprs :: [String] -> String - runExprs = printf "(System.Console.Hawk.Representable.runExprs (%s))" - . compose + runExprs :: Maybe FilePath -> [String] -> String + runExprs file = printf "(System.Console.Hawk.Representable.runExprs (%s) (%s))" + (P.show file) . compose - runExpr :: [String] -> String - runExpr = printf "(System.Console.Hawk.Representable.runExpr (%s))" - . compose + runExpr :: Maybe FilePath -> [String] -> String + runExpr file = printf "(System.Console.Hawk.Representable.runExpr (%s) (%s))" + (P.show file) . compose runMap :: [String] -> String runMap = printf "(System.Console.Hawk.Representable.listMap (%s))" diff --git a/src/System/Console/Hawk/Representable.hs b/src/System/Console/Hawk/Representable.hs index c8bac48..c627066 100644 --- a/src/System/Console/Hawk/Representable.hs +++ b/src/System/Console/Hawk/Representable.hs @@ -44,15 +44,15 @@ listMap = L.map parseRows :: StrictBS.ByteString -> C8.ByteString -> [C8.ByteString] parseRows delim str = dropLastIfEmpty $ BS.split delim str -runExpr :: (C8.ByteString -> IO ()) -> IO () -runExpr f = do - stdin <- C8.getContents - f stdin - -runExprs :: (C8.ByteString -> [IO ()]) -> IO () -runExprs f = do - stdin <- C8.getContents - sequence_ (f stdin) +runExpr :: Maybe FilePath -> (C8.ByteString -> IO ()) -> IO () +runExpr fp f = do + input <- maybe C8.getContents C8.readFile fp + f input + +runExprs :: Maybe FilePath -> (C8.ByteString -> [IO ()]) -> IO () +runExprs fp f = do + input <- maybe C8.getContents C8.readFile fp + sequence_ (f input) -- ------------------------ -- Rows class and instances