module Exercise04 where import Data.List import Data.Maybe {-WETT-} xmlLight' :: String -> [String] -> Bool xmlLight' [] stack = null stack xmlLight' (s : ss) stack | s == '>' = False | s == '<' = let close = head ss == '/' newStr = if close then tail ss else ss closingTagIdx = elemIndex '>' newStr r = splitAt (fromMaybe 0 closingTagIdx) newStr tagContent = words $ fst r tagId = head tagContent restStr = tail $ snd r in not (null ss) && isJust closingTagIdx && length tagContent == 1 && head (fst r) /= ' ' && notElem '/' tagId && notElem '<' tagId && if close then not (null stack) && head stack == tagId && xmlLight' restStr (tail stack) else xmlLight' restStr (tagId : stack) | otherwise = xmlLight' ss stack xmlLight :: String -> Bool xmlLight s = xmlLight' s [] {-TTEW-}