1
Fork 0
simple-sql-parser/tests/Filter.hs
Jake Wheat 45669ed7d3 reorganise
move exe example to examples/
get rid of the second example
move tests to tests/
don't shadow show in Pretty
2024-01-26 15:28:15 +00:00

36 lines
960 B
Haskell

import System.IO
import System.Environment
main :: IO ()
main = do
[a] <- getArgs
r <- readFile a
let ls = lines r
a = noAdjacentBlankLines ls
b = concat $ combineGroups $ group [] a
putStrLn $ unlines b
noAdjacentBlankLines [] = []
noAdjacentBlankLines [a] = [a]
noAdjacentBlankLines ("":xs@("":_)) = noAdjacentBlankLines xs
noAdjacentBlankLines (x:xs) = x:noAdjacentBlankLines xs
group :: [String] -> [String] -> [[String]]
group acc [] = [acc]
group acc ("":xs) = reverse ("":acc) : group [] xs
group acc (x:xs) = group (x : acc) xs
combineGroups :: [[String]] -> [[String]]
combineGroups [] = []
combineGroups (x@(('<':_):_):xs) | gs <- map trim x
, ns <- trim $ unwords gs
, length ns < 80 = [ns ++ "\n"] : combineGroups xs
combineGroups (x:xs) = x:combineGroups xs
trim :: String -> String
trim = x . x
where
x = dropWhile (==' ') . reverse