From 859820cfb2fdc62fb11322e5b6695cc025a61d85 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Wed, 30 Nov 2016 15:40:06 -0600 Subject: [PATCH] Added support for Continue statements in JavaScript --- src/Category.hs | 3 +++ src/DiffSummary.hs | 4 ++++ src/Language/JavaScript.hs | 1 + src/Renderer/JSON.hs | 1 + src/Renderer/Split.hs | 1 + src/Syntax.hs | 1 + 6 files changed, 11 insertions(+) diff --git a/src/Category.hs b/src/Category.hs index dc04f190e..e0a4c4559 100644 --- a/src/Category.hs +++ b/src/Category.hs @@ -159,6 +159,8 @@ data Category | BlockParameter -- | A break statement, e.g. break; in JavaScript. | Break + -- | A continue statement, e.g. continue; in JavaScript. + | Continue deriving (Eq, Generic, Ord, Show) -- Instances @@ -242,6 +244,7 @@ instance Arbitrary Category where , pure HashSplatParameter , pure BlockParameter , pure Break + , pure Continue , Other <$> arbitrary ] diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 86fc3d91c..8e90b2920 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -155,6 +155,7 @@ determiner (LeafInfo "ensure block" _ _) = "an" determiner (LeafInfo "when block" _ _) = "a" determiner (LeafInfo "anonymous function" _ _) = "an" determiner (LeafInfo "break statement" _ _) = "a" +determiner (LeafInfo "continue statement" _ _) = "a" determiner (BranchInfo bs _ _) = determiner (last bs) determiner _ = "the" @@ -177,6 +178,7 @@ toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of (LeafInfo cName@"import statement" termName _) -> toDoc termName <+> toDoc cName (LeafInfo cName@"subshell command" termName _) -> toDoc termName <+> toDoc cName (LeafInfo cName@"break statement" _ _) -> toDoc cName + (LeafInfo cName@"continue statement" _ _) -> toDoc cName LeafInfo{..} -> squotes (toDoc termName) <+> toDoc categoryName node -> panic $ "Expected a leaf info but got a: " <> show node @@ -252,6 +254,7 @@ toTermName source term = case unwrap term of S.Negate expr -> toTermName' expr S.Rescue args _ -> intercalate ", " $ toTermName' <$> args S.Break expr -> toTermName' expr + S.Continue expr -> toTermName' expr where toTermName' = toTermName source termNameFromChildren term children = termNameFromRange (unionRangesFrom (range term) (range <$> children)) termNameFromSource term = termNameFromRange (range term) @@ -420,6 +423,7 @@ instance HasCategory Category where C.HashSplatParameter -> "parameter" C.BlockParameter -> "parameter" C.Break -> "break statement" + C.Continue -> "continue statement" instance HasField fields Category => HasCategory (SyntaxTerm leaf fields) where toCategoryName = toCategoryName . category . extract diff --git a/src/Language/JavaScript.hs b/src/Language/JavaScript.hs index 2d720ed16..cc9943f30 100644 --- a/src/Language/JavaScript.hs +++ b/src/Language/JavaScript.hs @@ -195,4 +195,5 @@ categoryForJavaScriptProductionName name = case name of "import_statement" -> Import "export_statement" -> Export "break_statement" -> Break + "continue_statement" -> Continue _ -> Other name diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index b2b95632c..0451bd79d 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -135,4 +135,5 @@ syntaxToTermField syntax = case syntax of S.TypeAssertion a b -> childrenFields [a, b] S.TypeConversion a b -> childrenFields [a, b] S.Break expr -> [ "expression" .= expr ] + S.Continue expr -> [ "expression" .= expr ] where childrenFields c = [ "children" .= c ] diff --git a/src/Renderer/Split.hs b/src/Renderer/Split.hs index 679739105..022638d7c 100644 --- a/src/Renderer/Split.hs +++ b/src/Renderer/Split.hs @@ -113,6 +113,7 @@ styleName category = "category-" <> case category of C.HashSplatParameter -> "hash_splat_param" C.BlockParameter -> "block_param" C.Break -> "break_statement" + C.Continue -> "continue_statement" -- | Pick the class name for a split patch. splitPatchToClassName :: SplitPatch a -> AttributeValue diff --git a/src/Syntax.hs b/src/Syntax.hs index f74a368f0..7cb99fc93 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -89,6 +89,7 @@ data Syntax a f | TypeAssertion f f | TypeConversion f f | Break f + | Continue f deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON)