module Exercise04 where import Data.Char (isSpace) import Data.List (dropWhileEnd) {-WETT-} xmlLight :: String -> Bool xmlLight = checkTags [] . getTags getTags :: String -> [String] getTags [] = [] getTags (x:xs) | x == '<' = getTagsOpened xs | x == '>' = pure " " | otherwise = getTags xs getTagsOpened :: String -> [String] getTagsOpened [] = pure " " getTagsOpened s@(x:xs) | x == '>' = getTags xs | otherwise = dropWhileEnd isSpace tag : getTagsOpened rest where (tag, rest) = break (=='>') s checkTags :: [String] -> [String] -> Bool checkTags [] [] = True checkTags os (t:ts) | any isSpace t = False -- tag containes spaces | head t /= '/' = checkTags (t:os) ts -- newly opened tag | otherwise = not (null os) && tail t == head os -- check if tag properly closed opened tag && checkTags (tail os) ts checkTags _ _ = False {-TTEW-}