Last active
July 6, 2023 07:54
-
-
Save silverweed/81cc24bbc95ec02cd1b6a7fef1c21f56 to your computer and use it in GitHub Desktop.
Counts line indents in code and shows stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @author silverweed, 2016 | |
-- @license WTFPL | |
import System.Environment | |
import System.IO | |
import Data.List | |
showIndents input = header ++ (mkList input) ++ "\n" | |
where | |
header = "indent: occurrences\n" | |
mkList = intercalate "\n" . map (\(o,i) -> (show i) ++ ": " ++ (show o)) . | |
map (\l -> (length l, head l)) . group . sort . buildIndents . | |
filter (\x -> length x > 0) . lines | |
buildIndents = map indents | |
where | |
indents = length . takeWhile (== '\t') | |
printAllIndents [] = return () | |
printAllIndents files = readAll files >>= putStrLn . showIndents | |
where | |
readAll [] = return "" | |
readAll (file:files) = do s <- readFile file | |
ss <- readAll files | |
return $ s ++ ss | |
main = getArgs >>= \x -> case length x of | |
0 -> interact showIndents | |
_ -> printAllIndents x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment