Skip to content

Commit

Permalink
fix #52, now can accept a file as input
Browse files Browse the repository at this point in the history
  • Loading branch information
melrief committed Aug 18, 2013
1 parent 9a56bd4 commit c8106aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/System/Console/Hawk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))"
Expand Down
18 changes: 9 additions & 9 deletions src/System/Console/Hawk/Representable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8106aa

Please sign in to comment.