Skip to content
Snippets Groups Projects
Commit c48785bf authored by Alice Brenon's avatar Alice Brenon
Browse files

Make checkout a little bit more elegant: 1 line shorter and remove...

Make checkout a little bit more elegant: 1 line shorter and remove intermediate variable which name collides with the new error primitives for serialization
parent d40e4994
No related branches found
No related tags found
No related merge requests found
......@@ -128,17 +128,16 @@ restore (context, subStructure) = state $ \parsingState ->
(at parsingState, parsingState {context, subStructure})
checkout :: MonadError XMLError m => Context -> Parser m ()
checkout actual = do
expected <- gets context
case (expected, actual) of
(Nothing, Just (TagOccurrence {tag, openLine})) ->
checkout actual = gets context >>= compareWith actual
where
compareWith (Just (TagOccurrence {tag, openLine})) Nothing =
throwError . ClosingUnopen tag $ Line openLine
(Just (TagOccurrence {tag, openLine}), Nothing) ->
compareWith Nothing (Just (TagOccurrence {tag, openLine})) =
throwError . Unclosed tag $ Line openLine
(Just tO0, Just tO1)
| tag tO0 /= tag tO1 ->
throwError $ ClosingDoesntMatch (tag tO0) (tag tO1) (Line $ openLine tO1)
_ -> return ()
compareWith (Just tO0) (Just tO1)
| tag tO0 /= tag tO1 =
throwError $ ClosingDoesntMatch (tag tO0) (tag tO1) (Line $ openLine tO0)
compareWith _ _ = return ()
parse :: (XmlSource s, MonadError XMLError m) => s -> m InvisiXML
parse = fmap collectState . execStateT fillStructure . openStream . tokens
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment