mirror of
https://github.com/github/semantic.git
synced 2024-12-30 18:36:27 +03:00
Make a switch statements clause a Maybe
This commit is contained in:
parent
4d06cbd63c
commit
0d13819f30
@ -171,6 +171,7 @@ toLeafInfos LeafInfo{..} = pure $ JSONSummary (summary leafCategory termName) so
|
|||||||
C.EndBlock -> categoryName'
|
C.EndBlock -> categoryName'
|
||||||
C.Yield | Text.null termName -> categoryName'
|
C.Yield | Text.null termName -> categoryName'
|
||||||
C.Return | Text.null termName -> categoryName'
|
C.Return | Text.null termName -> categoryName'
|
||||||
|
C.Switch | Text.null termName -> categoryName'
|
||||||
_ -> "the" <+> squotes (toDoc termName) <+> toDoc categoryName
|
_ -> "the" <+> squotes (toDoc termName) <+> toDoc categoryName
|
||||||
where
|
where
|
||||||
termAndCategoryName = "the" <+> toDoc termName <+> toDoc categoryName
|
termAndCategoryName = "the" <+> toDoc termName <+> toDoc categoryName
|
||||||
@ -222,7 +223,7 @@ toTermName source term = case unwrap term of
|
|||||||
-- TODO: We should remove Case from Syntax since I don't think we should ever
|
-- TODO: We should remove Case from Syntax since I don't think we should ever
|
||||||
-- evaluate Case as a single toTermName Text - joshvera
|
-- evaluate Case as a single toTermName Text - joshvera
|
||||||
S.Case expr _ -> termNameFromSource expr
|
S.Case expr _ -> termNameFromSource expr
|
||||||
S.Switch expr _ -> toTermName' expr
|
S.Switch expr _ -> maybe "" toTermName' expr
|
||||||
S.Ternary expr _ -> toTermName' expr
|
S.Ternary expr _ -> toTermName' expr
|
||||||
S.OperatorAssignment id _ -> toTermName' id
|
S.OperatorAssignment id _ -> toTermName' id
|
||||||
S.Operator _ -> termNameFromSource term
|
S.Operator _ -> termNameFromSource term
|
||||||
@ -289,7 +290,9 @@ parentContexts contexts = hsep $ either identifiableDoc annotatableDoc <$> conte
|
|||||||
C.RescueModifier -> "in the" <+> squotes ("rescue" <+> termName t) <+> "modifier"
|
C.RescueModifier -> "in the" <+> squotes ("rescue" <+> termName t) <+> "modifier"
|
||||||
C.If -> "in the" <+> squotes (termName t) <+> catName c
|
C.If -> "in the" <+> squotes (termName t) <+> catName c
|
||||||
C.Case -> "in the" <+> squotes (termName t) <+> catName c
|
C.Case -> "in the" <+> squotes (termName t) <+> catName c
|
||||||
C.Switch -> "in the" <+> squotes (termName t) <+> catName c
|
C.Switch -> case t of
|
||||||
|
"" -> "in a" <+> catName c
|
||||||
|
_ -> "in the" <+> squotes (termName t) <+> catName c
|
||||||
C.When -> "in a" <+> catName c
|
C.When -> "in a" <+> catName c
|
||||||
C.BeginBlock -> "in a" <+> catName c
|
C.BeginBlock -> "in a" <+> catName c
|
||||||
C.EndBlock -> "in an" <+> catName c
|
C.EndBlock -> "in an" <+> catName c
|
||||||
|
@ -62,7 +62,7 @@ algorithmWithTerms construct t1 t2 = maybe (recursively t1 t2) (fmap annotate) $
|
|||||||
S.FunctionCall <$> recursively identifierA identifierB
|
S.FunctionCall <$> recursively identifierA identifierB
|
||||||
<*> bySimilarity argsA argsB
|
<*> bySimilarity argsA argsB
|
||||||
(S.Switch exprA casesA, S.Switch exprB casesB) -> Just $
|
(S.Switch exprA casesA, S.Switch exprB casesB) -> Just $
|
||||||
S.Switch <$> recursively exprA exprB
|
S.Switch <$> sequenceA (recursively <$> exprA <*> exprB)
|
||||||
<*> bySimilarity casesA casesB
|
<*> bySimilarity casesA casesB
|
||||||
(S.Object tyA a, S.Object tyB b) -> Just $
|
(S.Object tyA a, S.Object tyB b) -> Just $
|
||||||
S.Object <$> sequenceA (recursively <$> tyA <*> tyB)
|
S.Object <$> sequenceA (recursively <$> tyA <*> tyB)
|
||||||
|
@ -43,9 +43,11 @@ termConstructor source sourceSpan name range children _ = case name of
|
|||||||
"expression_switch_statement" ->
|
"expression_switch_statement" ->
|
||||||
case Prologue.break isCaseClause children of
|
case Prologue.break isCaseClause children of
|
||||||
(clauses, cases) -> do
|
(clauses, cases) -> do
|
||||||
clauses <- withCategory ExpressionStatements (S.Indexed clauses)
|
clauses' <- case clauses of
|
||||||
|
[] -> pure Nothing
|
||||||
|
clauses'' -> Just <$> (withCategory ExpressionStatements (S.Indexed clauses''))
|
||||||
cases' <- sequenceA $ toCase <$> cases
|
cases' <- sequenceA $ toCase <$> cases
|
||||||
withDefaultInfo $ S.Switch clauses cases'
|
withDefaultInfo $ S.Switch clauses' cases'
|
||||||
where
|
where
|
||||||
isCaseClause = (== Other "expression_case_clause") . category . extract
|
isCaseClause = (== Other "expression_case_clause") . category . extract
|
||||||
toCase clause = case toList (unwrap clause) of
|
toCase clause = case toList (unwrap clause) of
|
||||||
@ -63,7 +65,7 @@ termConstructor source sourceSpan name range children _ = case name of
|
|||||||
case Prologue.break isCaseClause children of
|
case Prologue.break isCaseClause children of
|
||||||
(clauses, cases) -> do
|
(clauses, cases) -> do
|
||||||
withDefaultInfo $ case clauses of
|
withDefaultInfo $ case clauses of
|
||||||
[id] -> S.Switch id cases
|
[id] -> S.Switch (Just id) cases
|
||||||
_ -> S.Error children
|
_ -> S.Error children
|
||||||
where isCaseClause = (== Case) . category . extract
|
where isCaseClause = (== Case) . category . extract
|
||||||
"select_statement" -> withDefaultInfo $ S.Select (toCommunicationCase =<< children)
|
"select_statement" -> withDefaultInfo $ S.Select (toCommunicationCase =<< children)
|
||||||
|
@ -58,7 +58,7 @@ termConstructor source sourceSpan name range children allChildren
|
|||||||
("var_assignment", _ ) -> S.Error children
|
("var_assignment", _ ) -> S.Error children
|
||||||
("var_declaration", _) -> S.Indexed $ toVarDecl <$> children
|
("var_declaration", _) -> S.Indexed $ toVarDecl <$> children
|
||||||
("trailing_var_declaration", _) -> S.Indexed $ toVarDecl <$> children
|
("trailing_var_declaration", _) -> S.Indexed $ toVarDecl <$> children
|
||||||
("switch_statement", expr : rest) -> S.Switch expr rest
|
("switch_statement", expr : rest) -> S.Switch (Just expr) rest
|
||||||
("switch_statement", _ ) -> S.Error children
|
("switch_statement", _ ) -> S.Error children
|
||||||
("case", [ expr, body ]) -> S.Case expr [body]
|
("case", [ expr, body ]) -> S.Case expr [body]
|
||||||
("case", _ ) -> S.Error children
|
("case", _ ) -> S.Error children
|
||||||
|
@ -70,7 +70,7 @@ termConstructor source sourceSpan name range children allChildren
|
|||||||
[ elseBlock ] | Else <- category (extract elseBlock) -> S.Try body rescues (Just elseBlock) Nothing
|
[ elseBlock ] | Else <- category (extract elseBlock) -> S.Try body rescues (Just elseBlock) Nothing
|
||||||
[ ensure ] | Ensure <- category (extract ensure) -> S.Try body rescues Nothing (Just ensure)
|
[ ensure ] | Ensure <- category (extract ensure) -> S.Try body rescues Nothing (Just ensure)
|
||||||
_ -> S.Try body rescues Nothing Nothing
|
_ -> S.Try body rescues Nothing Nothing
|
||||||
("case", expr : body ) -> S.Switch expr body
|
("case", expr : body ) -> S.Switch (Just expr) body
|
||||||
("case", _ ) -> S.Error children
|
("case", _ ) -> S.Error children
|
||||||
("when", condition : body ) -> S.Case condition body
|
("when", condition : body ) -> S.Case condition body
|
||||||
("when", _ ) -> S.Error children
|
("when", _ ) -> S.Error children
|
||||||
|
@ -45,7 +45,7 @@ data Syntax a f
|
|||||||
-- | A subscript access contains a syntax, and another syntax that indefies a property or value in the first syntax.
|
-- | A subscript access contains a syntax, and another syntax that indefies a property or value in the first syntax.
|
||||||
-- | e.g. in Javascript x["y"] represents a subscript access syntax.
|
-- | e.g. in Javascript x["y"] represents a subscript access syntax.
|
||||||
| SubscriptAccess { subscriptId :: f, subscriptElement :: f }
|
| SubscriptAccess { subscriptId :: f, subscriptElement :: f }
|
||||||
| Switch { switchExpr :: f, cases :: [f] }
|
| Switch { switchExpr :: (Maybe f), cases :: [f] }
|
||||||
| Case { caseExpr :: f, caseStatements :: [f] }
|
| Case { caseExpr :: f, caseStatements :: [f] }
|
||||||
-- | A default case in a switch statement.
|
-- | A default case in a switch statement.
|
||||||
| Default [f]
|
| Default [f]
|
||||||
|
Loading…
Reference in New Issue
Block a user