module Exercise04 where {-WETT-} xmlLight :: String -> Bool xmlLight = xmlHelper [] xmlHelper :: [String] -> String -> Bool xmlHelper stack "" = null stack xmlHelper stack ('<':chs) | null chs = False | head chs == '/' = not ( null stack || null tag) && init tag == head stack && xmlHelper (tail stack) rest | otherwise = tag /= "" && xmlHelper (tag:stack) rest where (tag, rest) = xmlTagger chs "" xmlHelper stack (c:chs) = c `notElem` ">" && xmlHelper stack chs xmlTaggerErr :: (String, String) xmlTaggerErr = ("", "") xmlTagger :: String -> String -> (String, String) xmlTagger "" _ = xmlTaggerErr xmlTagger (c:chs) tag | c == '>' = (last $ words tag, chs) | c `elem` "<" || (c /= ' ' && ' ' `elem` tag) = xmlTaggerErr | otherwise = xmlTagger chs (c:tag) {-TTEW-}