From c48785bf7fe18b34487993f30de9135f1674c7e0 Mon Sep 17 00:00:00 2001 From: Alice BRENON <alice.brenon@ens-lyon.fr> Date: Fri, 12 Feb 2021 18:20:11 +0100 Subject: [PATCH] Make checkout a little bit more elegant: 1 line shorter and remove intermediate variable which name collides with the new error primitives for serialization --- lib/Text/InvisiXML.hs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/Text/InvisiXML.hs b/lib/Text/InvisiXML.hs index f1076c0..8ba68c3 100644 --- a/lib/Text/InvisiXML.hs +++ b/lib/Text/InvisiXML.hs @@ -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 -- GitLab