Created
January 14, 2020 11:24
-
-
Save ners/c93cdcdf735312004d9747f570b2c9ff to your computer and use it in GitHub Desktop.
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
import System.Environment | |
data Token = Token | |
{ row :: Int | |
, col :: Int | |
, val :: Char | |
} deriving (Ord, Eq, Show) | |
tokenise :: String -> [Token] | |
tokenise = tok 1 1 | |
where | |
tok _ _ [] = [] | |
tok row col ('\n':xs) = Token row col '\n' : tok (row+1) 1 xs | |
tok row col (x:xs) = Token row col x : tok row (col+1) xs | |
unmatchedChars :: [Token] -> Char -> Char -> [Token] | |
unmatchedChars toks val1 val2 = stoks [] ftoks | |
where | |
ftoks = filter (\(Token _ _ v) -> v == val1 || v == val2) toks | |
stoks s [] = s | |
stoks ((Token _ _ val2):xs) ((Token _ _ val1):ts) = stoks xs ts | |
stoks s (t:ts) = stoks (t : s) ts | |
processContents :: String -> String -> IO () | |
processContents fname contents = do | |
if null uB && null uP -- && null uA | |
then return () | |
else putStrLn fname | |
printResult uB | |
printResult uP | |
--printResult uA | |
where | |
match = unmatchedChars $ tokenise contents | |
uB = match '{' '}' | |
uP = match '(' ')' | |
--uA = match '<' '>' | |
printResult [] = return () | |
printResult result = mapM_ print result | |
processFile :: String -> IO () | |
processFile fname = readFile fname >>= processContents fname | |
main :: IO () | |
main = getArgs >>= mapM_ processFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment