module Exercise04 where {-WETT-} xmlLight :: String -> Bool xmlLight = check [] . chop chop (char1 : char2 : text) | char1 == '>' || char2 == '<' = [char1] : c : cs | otherwise = (char1 : c) : cs where c : cs = chop $ char2 : text chop text = [text] check tags (bracket : brackets) | elem '<' bracket && elem '>' bracket = isValidTag $ init $ tail bracket | elem '<' bracket || elem '>' bracket = False | otherwise = check tags brackets where isValidTag (h : tag) | elem '/' cleaned || elem ' ' cleaned = False | h /= '/' = check (cleaned : tags) brackets | null tags = False | otherwise = cleaned == head tags && tail tags `check` brackets where cleaned = reverse $ dropWhile (== ' ') $ reverse $ if h == '/' then tag else h : tag isValidTag _ = False check tags _ = null tags {-TTEW-}