1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00

Added support for Continue statements in JavaScript

This commit is contained in:
Rick Winfrey 2016-11-30 15:40:06 -06:00
parent 9d65261669
commit 859820cfb2
6 changed files with 11 additions and 0 deletions

View File

@ -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
]

View File

@ -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

View File

@ -195,4 +195,5 @@ categoryForJavaScriptProductionName name = case name of
"import_statement" -> Import
"export_statement" -> Export
"break_statement" -> Break
"continue_statement" -> Continue
_ -> Other name

View File

@ -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 ]

View File

@ -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

View File

@ -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)