1
1
mirror of https://github.com/github/semantic.git synced 2024-12-31 10:57:00 +03:00

Merge pull request #656 from github/throw-syntax

Add support for Throw syntax
This commit is contained in:
Rick Winfrey 2016-08-01 14:57:31 -05:00 committed by GitHub
commit 122e9dd806
7 changed files with 14 additions and 3 deletions

View File

@ -77,6 +77,8 @@ data Category
| Object
-- | A return statement.
| Return
-- | A throw statement.
| Throw
-- | A constructor statement, e.g. new Foo;
| Constructor
-- | A try statement.

View File

@ -66,6 +66,7 @@ toTermName source term = case unwrap term of
S.For exprs _ -> termNameFromChildren term exprs
S.While expr _ -> toTermName' expr
S.DoWhile _ expr -> toTermName' expr
S.Throw expr -> toText $ Source.slice (characterRange $ extract expr) source
S.Constructor expr -> toTermName' expr
S.Try expr _ _ -> toText $ Source.slice (characterRange $ extract expr) source
S.Array _ -> toText $ Source.slice (characterRange $ extract term) source
@ -121,6 +122,7 @@ instance HasCategory Category where
C.DoWhile -> "do/while statement"
C.Object -> "object"
C.Return -> "return statement"
C.Throw -> "throw statement"
C.Constructor -> "constructor"
C.Catch -> "catch statement"
C.Try -> "try statement"
@ -199,6 +201,7 @@ diffSummaries sources = cata $ \case
(Free (infos :< S.For exprs body)) -> annotateWithCategory infos <$> join exprs <> body
(Free (infos :< S.While expr body)) -> annotateWithCategory infos <$> expr <> body
(Free (infos :< S.DoWhile expr body)) -> annotateWithCategory infos <$> expr <> body
(Free (infos :< S.Throw expr)) -> annotateWithCategory infos <$> expr
(Free (infos :< S.Constructor expr)) -> annotateWithCategory infos <$> expr
(Free (infos :< S.Try expr catch finally)) -> annotateWithCategory infos <$> expr <> fromMaybe [] catch <> fromMaybe [] finally
(Free (infos :< S.Array children)) -> annotateWithCategory infos <$> join children

View File

@ -91,12 +91,14 @@ termConstructor source sourceSpan info = cofree . construct
construct children | Pair == (category info) = withDefaultInfo $ S.Fixed children
construct children | C.Error == category info =
withDefaultInfo $ S.Error sourceSpan children
construct children | For == (category info), Just (exprs, body) <- unsnoc children =
construct children | For == category info, Just (exprs, body) <- unsnoc children =
withDefaultInfo $ S.For exprs body
construct children | While == (category info), [expr, body] <- children =
construct children | While == category info, [expr, body] <- children =
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
construct children | Throw == category info, [expr] <- children =
withDefaultInfo $ S.Throw expr
construct children | Constructor == category info, [expr] <- children =
withDefaultInfo $ S.Constructor expr
construct children | Try == category info = case children of

View File

@ -90,6 +90,7 @@ termFields info syntax = "range" .= characterRange info : "category" .= category
S.Comment _ -> []
S.Commented comments child -> childrenFields (comments <> maybeToList child)
S.Error sourceSpan c -> [ "sourceSpan" .= sourceSpan ] <> childrenFields c
S.Throw c -> [ "throwExpression" .= c ]
S.Try body catch finally -> [ "tryBody" .= body ] <> [ "tryCatch" .= catch ] <> [ "tryFinally" .= finally ]
S.Array c -> childrenFields c
S.Class identifier superclass definitions -> [ "classIdentifier" .= identifier ] <> [ "superclass" .= superclass ] <> [ "definitions" .= definitions ]

View File

@ -64,6 +64,7 @@ styleName category = "category-" <> case category of
C.While -> "while"
C.DoWhile -> "do_while"
C.Return -> "return_statement"
C.Throw -> "throw_statement"
C.Constructor -> "constructor"
C.Try -> "try_statement"
C.Catch -> "catch_statement"

View File

@ -60,6 +60,7 @@ data Syntax
| DoWhile { doWhileBody :: f, doWhileExpr :: f }
| While { whileExpr :: f, whileBody :: f }
| Return (Maybe f)
| Throw f
| Constructor f
| Try f (Maybe f) (Maybe f)
-- | An array literal with list of children.

View File

@ -88,6 +88,7 @@ defaultCategoryForNodeName name = case name of
"while_statement" -> While
"do_statement" -> DoWhile
"return_statement" -> Return
"throw_statement" -> Throw
"try_statement" -> Try
"method_definition" -> Method
_ -> Other name