module Exercise04 where import Data.List {-WETT-} xmlLight :: String -> Bool xmlLight s = fst $ xmlParse False s xmlParse :: Bool -> String -> (Bool,String) xmlParse recCall "" = (True,"") xmlParse recCall ('<':'/':s) = (recCall,s) xmlParse recCall (a:s) | a == '>' = (False,s) | a == '<' = (openTag /= "" && intersect "/ <>" openTag == "" && innerSuccess && openTag == closeTag && take 1 restSclosed == ">" && nextSuccess, returnS) | otherwise = xmlParse recCall s where openTag = takeID s (innerSuccess,restS) = xmlParse True $ skipID s closeTag = takeID restS restSclosed = dropWhile (/= '>') restS (nextSuccess,returnS) = xmlParse recCall $ skipID restSclosed skipID :: String -> String skipID = drop 1 . dropWhile (/= '>') takeID :: String -> String takeID = reverse . dropWhile (== ' ') . reverse . takeWhile (/= '>') {-TTEW-}