From 5eed1746e23f09b3d700b421399d65c405b6db5e Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Mon, 3 Jun 2024 13:41:42 +0300 Subject: [PATCH] wip --- fixme-new/lib/Fixme/State.hs | 13 +---------- fixme-new/lib/Fixme/Types.hs | 43 +++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/fixme-new/lib/Fixme/State.hs b/fixme-new/lib/Fixme/State.hs index 5245e778..be0f0edd 100644 --- a/fixme-new/lib/Fixme/State.hs +++ b/fixme-new/lib/Fixme/State.hs @@ -25,7 +25,7 @@ module Fixme.State ) where import Fixme.Prelude -import Fixme.Types hiding (mkstr, mksym) +import Fixme.Types import Fixme.Config import HBS2.System.Dir @@ -367,17 +367,6 @@ instance IsContext c => HasPredicate [Syntax c] where ListVal [x] -> x x -> x -mklist :: IsContext c => [Syntax c] -> Syntax c -mklist ss = List noContext ss - -mksym :: IsContext c => Id -> Syntax c -mksym = Symbol noContext - -mkint :: (IsContext c, Integral a) => a -> Syntax c -mkint = Literal noContext . LitInt . fromIntegral - -mkstr :: IsContext c => Text -> Syntax c -mkstr = Literal noContext . LitStr {- HLINT ignore "Functor law" -} {- HLINT ignore "Eta reduce" -} diff --git a/fixme-new/lib/Fixme/Types.hs b/fixme-new/lib/Fixme/Types.hs index 37f6fad6..fbc29b2a 100644 --- a/fixme-new/lib/Fixme/Types.hs +++ b/fixme-new/lib/Fixme/Types.hs @@ -44,6 +44,31 @@ pattern FixmeHashLike e <- (fixmeHashFromSyn -> Just e) pattern TimeStampLike :: forall {c} . FixmeTimestamp -> Syntax c pattern TimeStampLike e <- (tsFromFromSyn -> Just e) + +mklist :: IsContext c => [Syntax c] -> Syntax c +mklist = List noContext + +mkint :: (IsContext c, Integral a) => a -> Syntax c +mkint = Literal noContext . LitInt . fromIntegral + +mksym :: IsContext c => Id -> Syntax c +mksym = Symbol noContext + +class MkId a where + mkId :: a -> Id + +instance MkId FixmeAttrName where + mkId (k :: FixmeAttrName) = Id ("$" <> coerce k) + +class IsContext c => MkStr c a where + mkstr :: a -> Syntax c + +instance IsContext c => MkStr c FixmeAttrVal where + mkstr (s :: FixmeAttrVal) = Literal (noContext @c) (LitStr (coerce s)) + +instance IsContext c => MkStr c Text where + mkstr = Literal noContext . LitStr + stringLike :: Syntax c -> Maybe String stringLike = \case LitStrVal s -> Just $ Text.unpack s @@ -150,6 +175,16 @@ data CatAction = CatAction { catAction :: [(Id, Syntax C)] -> ByteString -> IO ( data SimpleTemplate = forall c . (IsContext c, Data (Context c), Data c) => SimpleTemplate [Syntax c] +data CompactAction = + Deleted Word64 HashRef + | Modified Word64 HashRef FixmeAttrName FixmeAttrVal + deriving stock (Eq,Ord,Show,Generic) + +instance Pretty CompactAction where + pretty = \case + Deleted s r -> pretty $ mklist @C [ mksym "deleted" ] + + data FixmeTemplate = Simple SimpleTemplate @@ -311,14 +346,6 @@ commentKey fp = type ContextShit c = (Data c, Data (Context c), IsContext c, Data (Syntax c)) -class MkId a where - mkId :: a -> Id - -instance MkId FixmeAttrName where - mkId (k :: FixmeAttrName) = Id ("$" <> coerce k) - -mkstr :: forall c . (IsContext c) => FixmeAttrVal -> Syntax c -mkstr (s :: FixmeAttrVal) = Literal (noContext @c) (LitStr (coerce s)) cc0 :: forall c . ContextShit c => Context c cc0 = noContext :: Context c