From 5efe89fbd35d909ee6ca448d7ac4c0615f9ff07b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 28 Mar 2017 15:26:10 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A5=20LambdaCase=20from=20the=20de?= =?UTF-8?q?fault=20extensions=20list.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- semantic-diff.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-diff.cabal b/semantic-diff.cabal index 376e5b30c..b2dd2cbb4 100644 --- a/semantic-diff.cabal +++ b/semantic-diff.cabal @@ -108,7 +108,7 @@ library , clock , yaml default-language: Haskell2010 - default-extensions: DeriveFunctor, DeriveFoldable, DeriveTraversable, DeriveGeneric, FlexibleContexts, FlexibleInstances, OverloadedStrings, NoImplicitPrelude, RecordWildCards, LambdaCase, StrictData + default-extensions: DeriveFunctor, DeriveFoldable, DeriveTraversable, DeriveGeneric, FlexibleContexts, FlexibleInstances, OverloadedStrings, NoImplicitPrelude, RecordWildCards, StrictData ghc-options: -Wall -fno-warn-name-shadowing -O2 -j ghc-prof-options: -fprof-auto From a8410e8829ebe8018a9b76278454e69be36adfe1 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 28 Mar 2017 15:32:45 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A5=20various=20uses=20of=20Lambda?= =?UTF-8?q?Case.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Interpreter.hs | 4 ++-- src/Language/Go.hs | 2 +- src/Language/Ruby.hs | 2 +- src/Patch.hs | 2 +- src/Renderer/Summary.hs | 18 +++++++++--------- src/Renderer/TOC.hs | 8 ++++---- src/TreeSitter.hs | 17 +++++++++-------- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 2a8d2df59..0d2929343 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -40,7 +40,7 @@ runSteps algorithm = case runStep algorithm of runStep :: (Eq leaf, HasField fields Category, HasField fields (Maybe FeatureVector)) => Algorithm (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) result -> Either result (Algorithm (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) result) -runStep = \case +runStep step = case step of Return a -> Left a algorithm `Then` cont -> Right $ decompose algorithm >>= cont @@ -49,7 +49,7 @@ runStep = \case decompose :: (Eq leaf, HasField fields Category, HasField fields (Maybe FeatureVector)) => AlgorithmF (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) result -- ^ The step in an algorithm to decompose into its next steps. -> Algorithm (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) result -- ^ The sequence of next steps to undertake to continue the algorithm. -decompose = \case +decompose step = case step of Diff t1 t2 -> algorithmWithTerms t1 t2 Linear t1 t2 -> case galignWith diffThese (unwrap t1) (unwrap t2) of Just result -> wrap . (both (extract t1) (extract t2) :<) <$> sequenceA result diff --git a/src/Language/Go.hs b/src/Language/Go.hs index bc83bbd0f..89eb26e48 100644 --- a/src/Language/Go.hs +++ b/src/Language/Go.hs @@ -76,7 +76,7 @@ termAssignment source category children = case (category, children) of _ -> Nothing categoryForGoName :: Text -> Category -categoryForGoName = \case +categoryForGoName name = case name of "identifier" -> Identifier "int_literal" -> NumberLiteral "float_literal" -> FloatLiteral diff --git a/src/Language/Ruby.hs b/src/Language/Ruby.hs index 5ed11cd05..4a7897bc5 100644 --- a/src/Language/Ruby.hs +++ b/src/Language/Ruby.hs @@ -96,7 +96,7 @@ termAssignment _ category children withRecord record syntax = cofree (record :< syntax) categoryForRubyName :: Text -> Category -categoryForRubyName = \case +categoryForRubyName name = case name of "argument_list_with_parens" -> Args "argument_list" -> Args "argument_pair" -> ArgumentPair diff --git a/src/Patch.hs b/src/Patch.hs index b574ad3ec..8f42e1ee6 100644 --- a/src/Patch.hs +++ b/src/Patch.hs @@ -81,7 +81,7 @@ maybeSnd :: These a b -> Maybe b maybeSnd = these (const Nothing) Just ((Just .) . flip const) patchType :: Patch a -> Text -patchType = \case +patchType patch = case patch of Replace{} -> "modified" Insert{} -> "added" Delete{} -> "removed" diff --git a/src/Renderer/Summary.hs b/src/Renderer/Summary.hs index 59ff53cd6..553b35338 100644 --- a/src/Renderer/Summary.hs +++ b/src/Renderer/Summary.hs @@ -33,7 +33,7 @@ data Annotatable a = Annotatable a | Unannotatable a annotatable :: SyntaxTerm leaf fields -> Annotatable (SyntaxTerm leaf fields) annotatable term = isAnnotatable (unwrap term) term - where isAnnotatable = \case + where isAnnotatable syntax = case syntax of S.Class{} -> Annotatable S.Method{} -> Annotatable S.Function{} -> Annotatable @@ -44,7 +44,7 @@ data Identifiable a = Identifiable a | Unidentifiable a identifiable :: SyntaxTerm leaf fields -> Identifiable (SyntaxTerm leaf fields) identifiable term = isIdentifiable (unwrap term) term - where isIdentifiable = \case + where isIdentifiable syntax = case syntax of S.FunctionCall{} -> Identifiable S.MethodCall{} -> Identifiable S.Function{} -> Identifiable @@ -138,15 +138,15 @@ diffToDiffSummaries sources = para $ \diff -> -- Flattens a patch of diff infos into a list of docs, one for every 'LeafInfo' or `ErrorInfo` it contains. jsonDocSummaries :: Patch DiffInfo -> [JSONSummary Doc SourceSpans] -jsonDocSummaries = \case - p@(Replace i1 i2) -> zipWith (\a b -> +jsonDocSummaries patch = case patch of + Replace i1 i2 -> zipWith (\a b -> JSONSummary { - info = info (prefixWithPatch p This a) <+> "with" <+> info b + info = info (prefixWithPatch patch This a) <+> "with" <+> info b , span = SourceSpans $ These (span a) (span b) }) (toLeafInfos i1) (toLeafInfos i2) - p@(Insert info) -> prefixWithPatch p That <$> toLeafInfos info - p@(Delete info) -> prefixWithPatch p This <$> toLeafInfos info + Insert info -> prefixWithPatch patch That <$> toLeafInfos info + Delete info -> prefixWithPatch patch This <$> toLeafInfos info -- Prefixes a given doc with the type of patch it represents. prefixWithPatch :: Patch DiffInfo -> (SourceSpan -> These SourceSpan SourceSpan) -> JSONSummary Doc SourceSpan -> JSONSummary Doc SourceSpans @@ -157,7 +157,7 @@ prefixWithPatch patch constructor = prefixWithThe (patchToPrefix patch) info = prefix <+> info jsonSummary , span = SourceSpans $ constructor (span jsonSummary) } - patchToPrefix = \case + patchToPrefix patch = case patch of (Replace _ _) -> "Replaced" (Insert _) -> "Added" (Delete _) -> "Deleted" @@ -380,7 +380,7 @@ instance HasCategory Text where toCategoryName = identity instance HasCategory Category where - toCategoryName = \case + toCategoryName category = case category of ArrayLiteral -> "array" BooleanOperator -> "boolean operator" MathOperator -> "math operator" diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index f5692d502..e196eddaa 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -109,7 +109,7 @@ toTOCSummaries patch = case afterOrBefore patch of _ -> NotSummarizable flattenPatch :: Patch DiffInfo -> [Patch DiffInfo] -flattenPatch = \case +flattenPatch patch = case patch of Replace i1 i2 -> zipWith Replace (toLeafInfos' i1) (toLeafInfos' i2) Insert info -> Insert <$> toLeafInfos' info Delete info -> Delete <$> toLeafInfos' info @@ -133,7 +133,7 @@ mapToInSummarizable sources diff children = case (beforeTerm diff, afterTerm dif summarizable :: ComonadCofree (Syntax t) w => w a -> SummarizableTerm (w a) summarizable term = go (unwrap term) term - where go = \case + where go syntax = case syntax of S.Method{} -> SummarizableTerm S.Function{} -> SummarizableTerm _ -> NotSummarizableTerm @@ -143,7 +143,7 @@ toJSONSummaries TOCSummary{..} = case afterOrBefore summaryPatch of Just diffInfo -> toJSONSummaries' diffInfo Nothing -> panic "No diff" where - toJSONSummaries' = \case + toJSONSummaries' diffInfo = case diffInfo of ErrorInfo{..} -> pure $ ErrorSummary termName infoSpan BranchInfo{..} -> branches >>= toJSONSummaries' LeafInfo{..} -> case parentInfo of @@ -183,6 +183,6 @@ toTermName parentOffset parentSource term = case unwrap term of -- The user-facing category name toCategoryName :: Category -> Text -toCategoryName = \case +toCategoryName category = case category of C.SingletonMethod -> "Method" c -> show c diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 479aa073a..17fc8c746 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -81,7 +81,7 @@ assignTerm language source annotation children allChildren = Just a -> pure a _ -> defaultTermAssignment source (category annotation) children allChildren where assignTermByLanguage :: Language -> Source -> Category -> [ SyntaxTerm Text '[ Range, Category, SourceSpan ] ] -> Maybe (S.Syntax Text (SyntaxTerm Text '[ Range, Category, SourceSpan ])) - assignTermByLanguage = \case + assignTermByLanguage language = case language of JavaScript -> JS.termAssignment C -> C.termAssignment Language.Go -> Go.termAssignment @@ -129,12 +129,13 @@ defaultTermAssignment source category children allChildren categoryForLanguageProductionName :: Language -> Text -> Category -categoryForLanguageProductionName = withDefaults . \case - JavaScript -> JS.categoryForJavaScriptProductionName - C -> C.categoryForCProductionName - Ruby -> Ruby.categoryForRubyName - Language.Go -> Go.categoryForGoName - _ -> Other - where withDefaults productionMap = \case +categoryForLanguageProductionName = withDefaults . byLanguage + where withDefaults productionMap name = case name of "ERROR" -> ParseError s -> productionMap s + byLanguage language = case language of + JavaScript -> JS.categoryForJavaScriptProductionName + C -> C.categoryForCProductionName + Ruby -> Ruby.categoryForRubyName + Language.Go -> Go.categoryForGoName + _ -> Other