never executed always true always false
    1 {-# LANGUAGE DeriveGeneric #-}
    2 module ElmFormat.AST.PublicAST.Comment (Comment(..), mkComment, fromComment, CommentDisplay(..), CommentType(..)) where
    3 
    4 import ElmFormat.AST.PublicAST.Core
    5 import qualified AST.V0_16 as AST
    6 import qualified Data.List as List
    7 import Data.Text (Text)
    8 import qualified Data.Text as Text
    9 
   10 
   11 data Comment
   12     = Comment
   13         { text :: Text
   14         , display :: CommentDisplay
   15         }
   16     deriving (Show)
   17 
   18 mkComment :: AST.Comment -> Comment
   19 mkComment = \case
   20     AST.BlockComment lines ->
   21         Comment
   22             (Text.pack $ List.intercalate "\n" lines)
   23             (CommentDisplay BlockComment)
   24 
   25     AST.LineComment string ->
   26         Comment
   27             (Text.pack string)
   28             (CommentDisplay LineComment)
   29 
   30     AST.CommentTrickOpener ->
   31         error "TODO: CommentTrickOpener"
   32 
   33     AST.CommentTrickCloser ->
   34         error "TODO: CommentTrickCloser"
   35 
   36     AST.CommentTrickBlock _ ->
   37         error "TODO: CommentTrickCloser"
   38 
   39 fromComment :: Comment -> AST.Comment
   40 fromComment = \case
   41     Comment text (CommentDisplay BlockComment) ->
   42         AST.BlockComment (Text.unpack <$> Text.splitOn "\n" text)
   43 
   44     Comment text (CommentDisplay LineComment) ->
   45         AST.LineComment (Text.unpack text)
   46 
   47 
   48 instance ToJSON Comment where
   49     toJSON = undefined
   50     toEncoding = pairs . toPairs
   51 
   52 instance ToPairs Comment where
   53     toPairs = \case
   54         Comment text display ->
   55             mconcat
   56                 [ type_ "Comment"
   57                 , "text" .= text
   58                 , "display" .= display
   59                 ]
   60 
   61 instance FromJSON Comment where
   62     parseJSON = withObject "Comment" $ \obj ->
   63         Comment
   64             <$> obj .: "text"
   65             <*> obj .:? "display" .!= CommentDisplay LineComment
   66 
   67 
   68 newtype CommentDisplay =
   69     CommentDisplay
   70         { commentType :: CommentType
   71         }
   72     deriving (Show, Generic)
   73 
   74 instance ToJSON CommentDisplay where
   75     toEncoding = genericToEncoding defaultOptions
   76 
   77 instance FromJSON CommentDisplay
   78 
   79 
   80 data CommentType
   81     = BlockComment
   82     | LineComment
   83     deriving (Show, Generic)
   84 
   85 instance ToJSON CommentType where
   86     toEncoding = genericToEncoding defaultOptions
   87 
   88 instance FromJSON CommentType