-- | A 'Builder' for an 'EntityDecl'.
buildEntityDecl :: EntityDecl -> Builder
buildEntityDecl d = pbracket $ fromText "ENTITY " <> pct <> name <> val
  where
    name = fromText (entityDeclName d) <> space
    (pct, val) = case d of
      InternalGeneralEntityDecl   _ val    -> (mempty, buildEntityValue val)
      ExternalGeneralEntityDecl   _ eid nt -> (mempty, ege eid nt)
      InternalParameterEntityDecl _ val    -> (pctBld, buildEntityValue val)
      ExternalParameterEntityDecl _ eid    -> (pctBld, buildExternalID eid)
    pctBld = fromText "% "
    ege eid nt = buildExternalID eid <>
      buildMaybe ((fromText " NDATA " <>) . quote . fromText) nt

-- | A 'Builder' for an 'ExternalID'.
buildEntityDecl :: EntityDecl -> Builder
buildEntityDecl d = pbracket $ fromText "ENTITY " <> pct <> name <> val
  where
    name = fromText (entityDeclName d) <> space
    (pct, val) = case d of
      InternalGeneralEntityDecl   _ val    -> (mempty, buildEntityValue val)
      ExternalGeneralEntityDecl   _ eid nt -> (mempty, ege eid nt)
      InternalParameterEntityDecl _ val    -> (pctBld, buildEntityValue val)
      ExternalParameterEntityDecl _ eid    -> (pctBld, buildExternalID eid)
    pctBld = fromText "% "
    ege eid nt = buildExternalID eid <>
      buildMaybe ((fromText " NDATA " <>) . quote . fromText) nt

-- | A 'Builder' for an 'ExternalID'.
buildEntityDecl d = pbracket $ fromText "ENTITY " <> pct <> name <> val
  where
    name = fromText (entityDeclName d) <> space
    (pct, val) = case d of
      InternalGeneralEntityDecl   _ val    -> (mempty, buildEntityValue val)
      ExternalGeneralEntityDecl   _ eid nt -> (mempty, ege eid nt)
      InternalParameterEntityDecl _ val    -> (pctBld, buildEntityValue val)
      ExternalParameterEntityDecl _ eid    -> (pctBld, buildExternalID eid)
    pctBld = fromText "% "
    ege eid nt = buildExternalID eid <>
      buildMaybe ((fromText " NDATA " <>) . quote . fromText) nt

-- | A 'Builder' for an 'ExternalID'.