From 36ac6a4104c1ad78855951c975704907f07d54e4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 10 Sep 2017 18:28:21 +0100 Subject: [PATCH] Rename MetaVar to Metavar. --- src/Diff.hs | 22 +++++++++++----------- src/Renderer/SExpression.hs | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Diff.hs b/src/Diff.hs index cf04456d3..262093c51 100644 --- a/src/Diff.hs +++ b/src/Diff.hs @@ -28,28 +28,28 @@ import Text.Show newtype Diff syntax ann = Diff { unDiff :: DiffF syntax ann (Diff syntax ann) } data DiffF syntax ann recur - = Copy [(MetaVar, recur)] (Both ann) (syntax recur) - | Var MetaVar + = Copy [(Metavar, recur)] (Both ann) (syntax recur) + | Var Metavar | Patch (Patch (TermF syntax ann recur)) deriving (Foldable, Functor, Traversable) type SyntaxDiff fields = Diff Syntax (Record fields) -diffFBindings :: DiffF syntax ann recur -> [(MetaVar, recur)] +diffFBindings :: DiffF syntax ann recur -> [(Metavar, recur)] diffFBindings (Copy bindings _ _) = bindings diffFBindings _ = [] -newtype MetaVar = MetaVar { unMetaVar :: String } +newtype Metavar = Metavar { unMetavar :: String } deriving (Eq, Ord, Show) -newtype Env a = Env { unEnv :: [(MetaVar, a)] } +newtype Env a = Env { unEnv :: [(Metavar, a)] } deriving (Eq, Foldable, Functor, Monoid, Ord, Show, Traversable) -envExtend :: MetaVar -> a -> Env a -> Env a +envExtend :: Metavar -> a -> Env a -> Env a envExtend var val (Env m) = Env ((var, val) : m) -envLookup :: MetaVar -> Env a -> Maybe a +envLookup :: Metavar -> Env a -> Maybe a envLookup var = lookup var . unEnv @@ -126,8 +126,8 @@ copy :: Both ann -> syntax (Diff syntax ann) -> Diff syntax ann copy = (Diff .) . Copy [] -instance Pretty MetaVar where - pretty (MetaVar v) = pretty v +instance Pretty Metavar where + pretty (Metavar v) = pretty v instance Apply1 Pretty1 fs => Pretty1 (Diff (Union fs)) where @@ -220,6 +220,6 @@ instance (ToJSONFields a, ToJSONFields1 f) => ToJSONFields (Diff f a) where toJSONFields = toJSONFields . unDiff instance (ToJSON b, ToJSONFields a, ToJSONFields1 f) => ToJSONFields (DiffF f a b) where - toJSONFields (Copy vs a f) = foldr (\ (MetaVar k, v) -> (pack k .= v :)) [] vs <> toJSONFields a <> toJSONFields1 f - toJSONFields (Var (MetaVar v)) = [ "metavar" .= v ] + toJSONFields (Copy vs a f) = foldr (\ (Metavar k, v) -> (pack k .= v :)) [] vs <> toJSONFields a <> toJSONFields1 f + toJSONFields (Var (Metavar v)) = [ "metavar" .= v ] toJSONFields (Patch a) = toJSONFields a diff --git a/src/Renderer/SExpression.hs b/src/Renderer/SExpression.hs index fd1549265..ae45f442f 100644 --- a/src/Renderer/SExpression.hs +++ b/src/Renderer/SExpression.hs @@ -32,7 +32,7 @@ printDiffF diff n = case diff of Replace a b -> nl n <> pad (n - 1) <> "{ " <> printTermF a n <> nl (n + 1) <> pad (n - 1) <> "->" <> printTermF b n <> " }" Copy vs (Join (_, annotation)) syntax -> nl n <> pad n <> "(" <> showBindings (fmap (\ b -> b n) <$> vs) <> showAnnotation annotation <> foldMap (\ d -> d (n + 1)) syntax <> ")" - Var v -> nl n <> pad n <> showMetaVar v + Var v -> nl n <> pad n <> showMetavar v printTermF :: (ConstrainAll Show fields, Foldable f, Functor f) => TermF f (Record fields) (Int -> ByteString) -> Int -> ByteString printTermF (annotation :< syntax) n = "(" <> showAnnotation annotation <> foldMap (\t -> t (n + 1)) syntax <> ")" @@ -50,10 +50,10 @@ showAnnotation Nil = "" showAnnotation (only :. Nil) = pack (show only) showAnnotation (first :. rest) = pack (show first) <> " " <> showAnnotation rest -showBindings :: [(MetaVar, ByteString)] -> ByteString +showBindings :: [(Metavar, ByteString)] -> ByteString showBindings [] = "" showBindings bindings = "[ " <> fold (intersperse "\n, " (showBinding <$> bindings)) <> " ]" - where showBinding (var, val) = showMetaVar var <> "/" <> val + where showBinding (var, val) = showMetavar var <> "/" <> val -showMetaVar :: MetaVar -> ByteString -showMetaVar (MetaVar s) = pack ('$' : s) +showMetavar :: Metavar -> ByteString +showMetavar (Metavar s) = pack ('$' : s)