mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Merge pull request #657 from github/try-syntax
Add support for Try syntax
This commit is contained in:
commit
ca2bdbd49a
@ -77,6 +77,12 @@ data Category
|
|||||||
| Object
|
| Object
|
||||||
-- | A return statement.
|
-- | A return statement.
|
||||||
| Return
|
| Return
|
||||||
|
-- | A try statement.
|
||||||
|
| Try
|
||||||
|
-- | A catch statement.
|
||||||
|
| Catch
|
||||||
|
-- | A finally statement.
|
||||||
|
| Finally
|
||||||
-- | A class declaration.
|
-- | A class declaration.
|
||||||
| Class
|
| Class
|
||||||
-- | A class method declaration.
|
-- | A class method declaration.
|
||||||
|
@ -66,6 +66,7 @@ toTermName source term = case unwrap term of
|
|||||||
S.For exprs _ -> termNameFromChildren term exprs
|
S.For exprs _ -> termNameFromChildren term exprs
|
||||||
S.While expr _ -> toTermName' expr
|
S.While expr _ -> toTermName' expr
|
||||||
S.DoWhile _ expr -> toTermName' expr
|
S.DoWhile _ expr -> toTermName' expr
|
||||||
|
S.Try expr _ _ -> toText $ Source.slice (characterRange $ extract expr) source
|
||||||
S.Array _ -> toText $ Source.slice (characterRange $ extract term) source
|
S.Array _ -> toText $ Source.slice (characterRange $ extract term) source
|
||||||
S.Class identifier _ _ -> toTermName' identifier
|
S.Class identifier _ _ -> toTermName' identifier
|
||||||
S.Method identifier _ _ -> toTermName' identifier
|
S.Method identifier _ _ -> toTermName' identifier
|
||||||
@ -119,6 +120,9 @@ instance HasCategory Category where
|
|||||||
C.DoWhile -> "do/while statement"
|
C.DoWhile -> "do/while statement"
|
||||||
C.Object -> "object"
|
C.Object -> "object"
|
||||||
C.Return -> "return statement"
|
C.Return -> "return statement"
|
||||||
|
C.Catch -> "catch statement"
|
||||||
|
C.Try -> "try statement"
|
||||||
|
C.Finally -> "finally statement"
|
||||||
C.Class -> "class"
|
C.Class -> "class"
|
||||||
C.Method -> "method"
|
C.Method -> "method"
|
||||||
|
|
||||||
@ -193,6 +197,7 @@ diffSummaries sources = cata $ \case
|
|||||||
(Free (infos :< S.For exprs body)) -> annotateWithCategory infos <$> join exprs <> body
|
(Free (infos :< S.For exprs body)) -> annotateWithCategory infos <$> join exprs <> body
|
||||||
(Free (infos :< S.While expr body)) -> annotateWithCategory infos <$> expr <> body
|
(Free (infos :< S.While expr body)) -> annotateWithCategory infos <$> expr <> body
|
||||||
(Free (infos :< S.DoWhile expr body)) -> annotateWithCategory infos <$> expr <> body
|
(Free (infos :< S.DoWhile expr body)) -> annotateWithCategory infos <$> expr <> body
|
||||||
|
(Free (infos :< S.Try expr catch finally)) -> annotateWithCategory infos <$> expr <> fromMaybe [] catch <> fromMaybe [] finally
|
||||||
(Free (infos :< S.Array children)) -> annotateWithCategory infos <$> join children
|
(Free (infos :< S.Array children)) -> annotateWithCategory infos <$> join children
|
||||||
(Free (infos :< S.Class identifier superclass definitions)) -> annotateWithCategory infos <$> identifier <> fromMaybe [] superclass <> join definitions
|
(Free (infos :< S.Class identifier superclass definitions)) -> annotateWithCategory infos <$> identifier <> fromMaybe [] superclass <> join definitions
|
||||||
(Free (infos :< S.Method identifier params definitions)) -> annotateWithCategory infos <$> identifier <> join params <> join definitions
|
(Free (infos :< S.Method identifier params definitions)) -> annotateWithCategory infos <$> identifier <> join params <> join definitions
|
||||||
|
@ -97,6 +97,14 @@ termConstructor source sourceSpan info = cofree . construct
|
|||||||
withDefaultInfo $ S.While expr body
|
withDefaultInfo $ S.While expr body
|
||||||
construct children | DoWhile == (category info), [expr, body] <- children =
|
construct children | DoWhile == (category info), [expr, body] <- children =
|
||||||
withDefaultInfo $ S.DoWhile expr body
|
withDefaultInfo $ S.DoWhile expr body
|
||||||
|
construct children | Try == category info = case children of
|
||||||
|
[body] -> withDefaultInfo $ S.Try body Nothing Nothing
|
||||||
|
[body, catch] | Catch <- category (extract catch) -> withDefaultInfo $ S.Try body (Just catch) Nothing
|
||||||
|
[body, finally] | Finally <- category (extract finally) -> withDefaultInfo $ S.Try body Nothing (Just finally)
|
||||||
|
[body, catch, finally] | Catch <- category (extract catch),
|
||||||
|
Finally <- category (extract finally) ->
|
||||||
|
withDefaultInfo $ S.Try body (Just catch) (Just finally)
|
||||||
|
_ -> withDefaultInfo $ S.Error sourceSpan children
|
||||||
construct children | ArrayLiteral == category info =
|
construct children | ArrayLiteral == category info =
|
||||||
withDefaultInfo $ S.Array children
|
withDefaultInfo $ S.Array children
|
||||||
construct children | Method == category info = case children of
|
construct children | Method == category info = case children of
|
||||||
|
@ -89,6 +89,7 @@ termFields info syntax = "range" .= characterRange info : "category" .= category
|
|||||||
S.Comment _ -> []
|
S.Comment _ -> []
|
||||||
S.Commented comments child -> childrenFields (comments <> maybeToList child)
|
S.Commented comments child -> childrenFields (comments <> maybeToList child)
|
||||||
S.Error sourceSpan c -> [ "sourceSpan" .= sourceSpan ] <> childrenFields c
|
S.Error sourceSpan c -> [ "sourceSpan" .= sourceSpan ] <> childrenFields c
|
||||||
|
S.Try body catch finally -> [ "tryBody" .= body ] <> [ "tryCatch" .= catch ] <> [ "tryFinally" .= finally ]
|
||||||
S.Array c -> childrenFields c
|
S.Array c -> childrenFields c
|
||||||
S.Class identifier superclass definitions -> [ "classIdentifier" .= identifier ] <> [ "superclass" .= superclass ] <> [ "definitions" .= definitions ]
|
S.Class identifier superclass definitions -> [ "classIdentifier" .= identifier ] <> [ "superclass" .= superclass ] <> [ "definitions" .= definitions ]
|
||||||
S.Method identifier params definitions -> [ "methodIdentifier" .= identifier ] <> [ "params" .= params ] <> [ "definitions" .= definitions ]
|
S.Method identifier params definitions -> [ "methodIdentifier" .= identifier ] <> [ "params" .= params ] <> [ "definitions" .= definitions ]
|
||||||
|
@ -64,6 +64,9 @@ styleName category = "category-" <> case category of
|
|||||||
C.While -> "while"
|
C.While -> "while"
|
||||||
C.DoWhile -> "do_while"
|
C.DoWhile -> "do_while"
|
||||||
C.Return -> "return_statement"
|
C.Return -> "return_statement"
|
||||||
|
C.Try -> "try_statement"
|
||||||
|
C.Catch -> "catch_statement"
|
||||||
|
C.Finally -> "finally_statement"
|
||||||
ArrayLiteral -> "array"
|
ArrayLiteral -> "array"
|
||||||
C.Class -> "class_statement"
|
C.Class -> "class_statement"
|
||||||
Other string -> string
|
Other string -> string
|
||||||
|
@ -60,6 +60,7 @@ data Syntax
|
|||||||
| DoWhile { doWhileBody :: f, doWhileExpr :: f }
|
| DoWhile { doWhileBody :: f, doWhileExpr :: f }
|
||||||
| While { whileExpr :: f, whileBody :: f }
|
| While { whileExpr :: f, whileBody :: f }
|
||||||
| Return (Maybe f)
|
| Return (Maybe f)
|
||||||
|
| Try f (Maybe f) (Maybe f)
|
||||||
-- | An array literal with list of children.
|
-- | An array literal with list of children.
|
||||||
| Array [f]
|
| Array [f]
|
||||||
-- | A class with an identifier, superclass, and a list of definitions.
|
-- | A class with an identifier, superclass, and a list of definitions.
|
||||||
|
@ -47,6 +47,8 @@ categoriesForLanguage language name = case (language, name) of
|
|||||||
(JavaScript, "for_in_statement") -> For
|
(JavaScript, "for_in_statement") -> For
|
||||||
(JavaScript, "for_of_statement") -> For
|
(JavaScript, "for_of_statement") -> For
|
||||||
(JavaScript, "class") -> Class
|
(JavaScript, "class") -> Class
|
||||||
|
(JavaScript, "catch") -> Catch
|
||||||
|
(JavaScript, "finally") -> Finally
|
||||||
|
|
||||||
(Ruby, "hash") -> Object
|
(Ruby, "hash") -> Object
|
||||||
_ -> defaultCategoryForNodeName name
|
_ -> defaultCategoryForNodeName name
|
||||||
@ -85,6 +87,7 @@ defaultCategoryForNodeName name = case name of
|
|||||||
"while_statement" -> While
|
"while_statement" -> While
|
||||||
"do_statement" -> DoWhile
|
"do_statement" -> DoWhile
|
||||||
"return_statement" -> Return
|
"return_statement" -> Return
|
||||||
|
"try_statement" -> Try
|
||||||
"method_definition" -> Method
|
"method_definition" -> Method
|
||||||
_ -> Other name
|
_ -> Other name
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user