never executed always true always false
    1 {-|
    2 Module: Flaw.Editor.Entity.Tag
    3 Description: Entity tags.
    4 License: MIT
    5 
    6 Entity tags are special types of entities which could be only attached to other entities.
    7 Each entity may only have zero or one attached tag of any single tag type.
    8 Tags are entities too, but they have unusual entity id: it's concatenation of tag id
    9 and attached entity's id.
   10 -}
   11 
   12 {-# LANGUAGE PatternSynonyms, TemplateHaskell #-}
   13 {-# OPTIONS_GHC -fno-warn-missing-pattern-synonym-signatures #-}
   14 
   15 module Flaw.Editor.Entity.Tag
   16   ( EntityTagId(..)
   17   , pattern ENTITY_TAG_ID_SIZE
   18   , entityTagEntityId
   19   , hashTextToEntityTagId
   20   ) where
   21 
   22 import qualified Data.ByteString.Short as BS
   23 import qualified Data.Text as T
   24 import Language.Haskell.TH
   25 
   26 import Flaw.Editor.Entity
   27 import Flaw.Editor.Entity.Internal
   28 
   29 -- | Entity tag id, used for prefixing entity id of tag entities.
   30 newtype EntityTagId = EntityTagId BS.ShortByteString
   31 
   32 pattern ENTITY_TAG_ID_SIZE = 20
   33 
   34 -- | Combine entity tag id and entity id to get entity tag's entity id.
   35 entityTagEntityId :: EntityTagId -> EntityId -> EntityId
   36 entityTagEntityId (EntityTagId entityTagIdBytes) (EntityId entityIdBytes) =
   37   EntityId $ entityTagIdBytes <> entityIdBytes
   38 
   39 -- | Handy function to generate compile-time entity tag id out of text.
   40 hashTextToEntityTagId :: T.Text -> Q Exp
   41 hashTextToEntityTagId = hashTextDecl "entityTagIdHash_" [t| EntityTagId |] $ \e -> [| EntityTagId (BS.toShort $e) |]