1
1
mirror of https://github.com/github/semantic.git synced 2025-01-05 14:11:33 +03:00

Move the ToJSONFields instance for Patch into Patch.

This commit is contained in:
Rob Rix 2017-09-09 17:24:56 +01:00
parent 41ecede023
commit 4e3c34d8f7
2 changed files with 8 additions and 6 deletions

View File

@ -11,10 +11,12 @@ module Patch
, mapPatch
) where
import Data.Aeson
import Data.Align
import Data.Functor.Classes.Eq.Generic
import Data.Functor.Classes.Pretty.Generic
import Data.Functor.Classes.Show.Generic
import Data.JSON.Fields
import Data.These
import GHC.Generics
@ -71,3 +73,9 @@ instance Pretty1 Patch where liftPretty = genericLiftPretty
instance Pretty a => Pretty (Patch a) where
pretty = liftPretty pretty prettyList
instance ToJSONFields a => ToJSONFields (Patch a) where
toJSONFields (Insert a) = [ "insert" .= object (toJSONFields a) ]
toJSONFields (Delete a) = [ "delete" .= object (toJSONFields a) ]
toJSONFields (Replace a b) = [ "replace" .= [object (toJSONFields a), object (toJSONFields b)] ]

View File

@ -23,7 +23,6 @@ import Diff
import GHC.Generics
import Info
import Language
import Patch
import Syntax as S
import Term
@ -70,11 +69,6 @@ instance (ToJSONFields a, ToJSONFields (f b), ToJSONFields (f (Term f a))) => To
toJSONFields (Copy a f) = toJSONFields a <> toJSONFields f
toJSONFields (Patch a) = toJSONFields a
instance ToJSONFields a => ToJSONFields (Patch a) where
toJSONFields (Insert a) = [ "insert" .= object (toJSONFields a) ]
toJSONFields (Delete a) = [ "delete" .= object (toJSONFields a) ]
toJSONFields (Replace a b) = [ "replace" .= [object (toJSONFields a), object (toJSONFields b)] ]
instance ToJSON recur => ToJSONFields (Syntax recur) where
toJSONFields syntax = [ "children" .= toList syntax ]