Stderr output pre-GhcModT for stack cradle
This commit is contained in:
@@ -25,25 +25,25 @@ inter _ [] = id
|
||||
inter c bs = foldr1 (\x y -> x . (c:) . y) bs
|
||||
|
||||
convert' :: (ToString a, IOish m, GmEnv m) => a -> m String
|
||||
convert' x = flip convert x <$> options
|
||||
convert' x = flip convert x . outputOpts <$> options
|
||||
|
||||
convert :: ToString a => Options -> a -> String
|
||||
convert opt@Options { outputStyle = LispStyle } x = toLisp opt x "\n"
|
||||
convert opt@Options { outputStyle = PlainStyle } x
|
||||
convert :: ToString a => OutputOpts -> a -> String
|
||||
convert opt@OutputOpts { outputStyle = LispStyle } x = toLisp opt x "\n"
|
||||
convert opt@OutputOpts { outputStyle = PlainStyle } x
|
||||
| str == "\n" = ""
|
||||
| otherwise = str
|
||||
where
|
||||
str = toPlain opt x "\n"
|
||||
|
||||
class ToString a where
|
||||
toLisp :: Options -> a -> Builder
|
||||
toPlain :: Options -> a -> Builder
|
||||
toLisp :: OutputOpts -> a -> Builder
|
||||
toPlain :: OutputOpts -> a -> Builder
|
||||
|
||||
lineSep :: Options -> String
|
||||
lineSep opt = interpret lsep
|
||||
lineSep :: OutputOpts -> String
|
||||
lineSep oopts = interpret lsep
|
||||
where
|
||||
interpret s = read $ "\"" ++ s ++ "\""
|
||||
LineSeparator lsep = lineSeparator opt
|
||||
LineSeparator lsep = lineSeparator oopts
|
||||
|
||||
-- |
|
||||
--
|
||||
@@ -52,8 +52,8 @@ lineSep opt = interpret lsep
|
||||
-- >>> toPlain defaultOptions "foo" ""
|
||||
-- "foo"
|
||||
instance ToString String where
|
||||
toLisp opt = quote opt
|
||||
toPlain opt = replace '\n' (lineSep opt)
|
||||
toLisp oopts = quote oopts
|
||||
toPlain oopts = replace '\n' (lineSep oopts)
|
||||
|
||||
-- |
|
||||
--
|
||||
@@ -62,12 +62,12 @@ instance ToString String where
|
||||
-- >>> toPlain defaultOptions ["foo", "bar", "baz"] ""
|
||||
-- "foo\nbar\nbaz"
|
||||
instance ToString [String] where
|
||||
toLisp opt = toSexp1 opt
|
||||
toPlain opt = inter '\n' . map (toPlain opt)
|
||||
toLisp oopts = toSexp1 oopts
|
||||
toPlain oopts = inter '\n' . map (toPlain oopts)
|
||||
|
||||
instance ToString [ModuleString] where
|
||||
toLisp opt = toLisp opt . map getModuleString
|
||||
toPlain opt = toPlain opt . map getModuleString
|
||||
toLisp oopts = toLisp oopts . map getModuleString
|
||||
toPlain oopts = toPlain oopts . map getModuleString
|
||||
|
||||
-- |
|
||||
--
|
||||
@@ -77,47 +77,47 @@ instance ToString [ModuleString] where
|
||||
-- >>> toPlain defaultOptions inp ""
|
||||
-- "1 2 3 4 \"foo\"\n5 6 7 8 \"bar\""
|
||||
instance ToString [((Int,Int,Int,Int),String)] where
|
||||
toLisp opt = toSexp2 . map toS
|
||||
toLisp oopts = toSexp2 . map toS
|
||||
where
|
||||
toS x = ('(' :) . tupToString opt x . (')' :)
|
||||
toPlain opt = inter '\n' . map (tupToString opt)
|
||||
toS x = ('(' :) . tupToString oopts x . (')' :)
|
||||
toPlain oopts = inter '\n' . map (tupToString oopts)
|
||||
|
||||
instance ToString ((Int,Int,Int,Int),String) where
|
||||
toLisp opt x = ('(' :) . tupToString opt x . (')' :)
|
||||
toPlain opt x = tupToString opt x
|
||||
toLisp oopts x = ('(' :) . tupToString oopts x . (')' :)
|
||||
toPlain oopts x = tupToString oopts x
|
||||
|
||||
instance ToString ((Int,Int,Int,Int),[String]) where
|
||||
toLisp opt (x,s) = ('(' :) . fourIntsToString opt x .
|
||||
(' ' :) . toLisp opt s . (')' :)
|
||||
toPlain opt (x,s) = fourIntsToString opt x . ('\n' :) . toPlain opt s
|
||||
toLisp oopts (x,s) = ('(' :) . fourIntsToString x .
|
||||
(' ' :) . toLisp oopts s . (')' :)
|
||||
toPlain oopts (x,s) = fourIntsToString x . ('\n' :) . toPlain oopts s
|
||||
|
||||
instance ToString (String, (Int,Int,Int,Int),[String]) where
|
||||
toLisp opt (s,x,y) = toSexp2 [toLisp opt s, ('(' :) . fourIntsToString opt x . (')' :), toLisp opt y]
|
||||
toPlain opt (s,x,y) = inter '\n' [toPlain opt s, fourIntsToString opt x, toPlain opt y]
|
||||
toLisp oopts (s,x,y) = toSexp2 [toLisp oopts s, ('(' :) . fourIntsToString x . (')' :), toLisp oopts y]
|
||||
toPlain oopts (s,x,y) = inter '\n' [toPlain oopts s, fourIntsToString x, toPlain oopts y]
|
||||
|
||||
toSexp1 :: Options -> [String] -> Builder
|
||||
toSexp1 opt ss = ('(' :) . inter ' ' (map (quote opt) ss) . (')' :)
|
||||
toSexp1 :: OutputOpts -> [String] -> Builder
|
||||
toSexp1 oopts ss = ('(' :) . inter ' ' (map (quote oopts) ss) . (')' :)
|
||||
|
||||
toSexp2 :: [Builder] -> Builder
|
||||
toSexp2 ss = ('(' :) . inter ' ' ss . (')' :)
|
||||
|
||||
fourIntsToString :: Options -> (Int,Int,Int,Int) -> Builder
|
||||
fourIntsToString _ (a,b,c,d) = (show a ++) . (' ' :)
|
||||
. (show b ++) . (' ' :)
|
||||
. (show c ++) . (' ' :)
|
||||
. (show d ++)
|
||||
fourIntsToString :: (Int,Int,Int,Int) -> Builder
|
||||
fourIntsToString (a,b,c,d) = (show a ++) . (' ' :)
|
||||
. (show b ++) . (' ' :)
|
||||
. (show c ++) . (' ' :)
|
||||
. (show d ++)
|
||||
|
||||
tupToString :: Options -> ((Int,Int,Int,Int),String) -> Builder
|
||||
tupToString opt ((a,b,c,d),s) = (show a ++) . (' ' :)
|
||||
. (show b ++) . (' ' :)
|
||||
. (show c ++) . (' ' :)
|
||||
. (show d ++) . (' ' :)
|
||||
. quote opt s -- fixme: quote is not necessary
|
||||
tupToString :: OutputOpts -> ((Int,Int,Int,Int),String) -> Builder
|
||||
tupToString oopts ((a,b,c,d),s) = (show a ++) . (' ' :)
|
||||
. (show b ++) . (' ' :)
|
||||
. (show c ++) . (' ' :)
|
||||
. (show d ++) . (' ' :)
|
||||
. quote oopts s -- fixme: quote is not necessary
|
||||
|
||||
quote :: Options -> String -> Builder
|
||||
quote opt str = ("\"" ++) . (quote' str ++) . ("\"" ++)
|
||||
quote :: OutputOpts -> String -> Builder
|
||||
quote oopts str = ("\"" ++) . (quote' str ++) . ("\"" ++)
|
||||
where
|
||||
lsep = lineSep opt
|
||||
lsep = lineSep oopts
|
||||
quote' [] = []
|
||||
quote' (x:xs)
|
||||
| x == '\n' = lsep ++ quote' xs
|
||||
@@ -128,13 +128,13 @@ quote opt str = ("\"" ++) . (quote' str ++) . ("\"" ++)
|
||||
----------------------------------------------------------------
|
||||
|
||||
-- Empty result to be returned when no info can be gathered
|
||||
emptyResult :: Monad m => Options -> m String
|
||||
emptyResult opt = return $ convert opt ([] :: [String])
|
||||
emptyResult :: Monad m => OutputOpts -> m String
|
||||
emptyResult oopts = return $ convert oopts ([] :: [String])
|
||||
|
||||
-- Return an emptyResult when Nothing
|
||||
whenFound :: (Monad m, ToString b) => Options -> m (Maybe a) -> (a -> b) -> m String
|
||||
whenFound opt from f = maybe (emptyResult opt) (return . convert opt . f) =<< from
|
||||
whenFound :: (Monad m, ToString b) => OutputOpts -> m (Maybe a) -> (a -> b) -> m String
|
||||
whenFound oopts from f = maybe (emptyResult oopts) (return . convert oopts . f) =<< from
|
||||
|
||||
-- Return an emptyResult when Nothing, inside a monad
|
||||
whenFound' :: (Monad m, ToString b) => Options -> m (Maybe a) -> (a -> m b) -> m String
|
||||
whenFound' opt from f = maybe (emptyResult opt) (\x -> do y <- f x ; return (convert opt y)) =<< from
|
||||
whenFound' :: (Monad m, ToString b) => OutputOpts -> m (Maybe a) -> (a -> m b) -> m String
|
||||
whenFound' oopts from f = maybe (emptyResult oopts) (\x -> do y <- f x ; return (convert oopts y)) =<< from
|
||||
|
||||
Reference in New Issue
Block a user