Skip to content

Commit

Permalink
Treat no content as empty text
Browse files Browse the repository at this point in the history
  • Loading branch information
EggBaconAndSpam committed Apr 6, 2023
1 parent 0ae2a4c commit 358f5eb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Data/XML/Deserialisation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,17 @@ parseUnorderedElement (UnorderedElementParser p) el = case runStateT p (stripWhi
then Right a
else throwParserError "element not fully consumed" -- todo: better error messages? include unparsed remainder

-- | Expects an element consisting of a single content node. Fails if attributes
-- aren't fully consumed.
-- | Expects an element consisting of a single content node or no child nodes
-- (which is treated as an empty content string). Fails if attributes aren't
-- fully consumed.
parseContentElement ::
(forall m. (AttributeConsumer m, MonadError ParserError m) => Text -> m a) ->
Element ->
Either ParserError a
parseContentElement p el = do
content <- case children el of
[NodeContent c] -> pure c
[] -> throwParserError "Empty content element."
[] -> pure ""
_ -> throwParserError "Content element must contain exactly one content node and no child elements."
let ContentParser p' = p content
case runStateT p' (el {children = []}) of
Expand Down

0 comments on commit 358f5eb

Please sign in to comment.