1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Merge pull request #661 from github/constructors

Add Constructors to Syntax
This commit is contained in:
Rick Winfrey 2016-08-01 12:52:09 -05:00 committed by GitHub
commit 37f0492c90
7 changed files with 12 additions and 1 deletions

View File

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

View File

@ -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.Constructor expr -> toTermName' expr
S.Try expr _ _ -> toText $ Source.slice (characterRange $ extract expr) source 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
@ -120,6 +121,7 @@ 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.Constructor -> "constructor"
C.Catch -> "catch statement" C.Catch -> "catch statement"
C.Try -> "try statement" C.Try -> "try statement"
C.Finally -> "finally statement" C.Finally -> "finally statement"
@ -197,6 +199,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.Constructor expr)) -> annotateWithCategory infos <$> expr
(Free (infos :< S.Try expr catch finally)) -> annotateWithCategory infos <$> expr <> fromMaybe [] catch <> fromMaybe [] finally (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

View File

@ -97,6 +97,8 @@ 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 | Constructor == category info, [expr] <- children =
withDefaultInfo $ S.Constructor expr
construct children | Try == category info = case children of construct children | Try == category info = case children of
[body] -> withDefaultInfo $ S.Try body Nothing Nothing [body] -> withDefaultInfo $ S.Try body Nothing Nothing
[body, catch] | Catch <- category (extract catch) -> withDefaultInfo $ S.Try body (Just catch) Nothing [body, catch] | Catch <- category (extract catch) -> withDefaultInfo $ S.Try body (Just catch) Nothing

View File

@ -85,7 +85,8 @@ termFields info syntax = "range" .= characterRange info : "category" .= category
S.SubscriptAccess id property -> [ "subscriptId" .= id ] <> [ "property" .= property ] S.SubscriptAccess id property -> [ "subscriptId" .= id ] <> [ "property" .= property ]
S.Object pairs -> childrenFields pairs S.Object pairs -> childrenFields pairs
S.Pair a b -> childrenFields [a, b] S.Pair a b -> childrenFields [a, b]
S.Return expr -> [ "returnExpr" .= expr ] S.Return expr -> [ "returnExpression" .= expr ]
S.Constructor expr -> [ "constructorExpression" .= expr ]
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

View File

@ -64,6 +64,7 @@ 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.Constructor -> "constructor"
C.Try -> "try_statement" C.Try -> "try_statement"
C.Catch -> "catch_statement" C.Catch -> "catch_statement"
C.Finally -> "finally_statement" C.Finally -> "finally_statement"

View File

@ -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)
| Constructor f
| Try f (Maybe f) (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]

View File

@ -46,6 +46,7 @@ categoriesForLanguage language name = case (language, name) of
(JavaScript, "void_op") -> Operator -- void operator, e.g. void 2. (JavaScript, "void_op") -> Operator -- void operator, e.g. void 2.
(JavaScript, "for_in_statement") -> For (JavaScript, "for_in_statement") -> For
(JavaScript, "for_of_statement") -> For (JavaScript, "for_of_statement") -> For
(JavaScript, "new_expression") -> Constructor
(JavaScript, "class") -> Class (JavaScript, "class") -> Class
(JavaScript, "catch") -> Catch (JavaScript, "catch") -> Catch
(JavaScript, "finally") -> Finally (JavaScript, "finally") -> Finally