mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Add type assertions
This commit is contained in:
parent
231310a484
commit
83453dd54f
@ -142,6 +142,7 @@ data Category
|
|||||||
| Defer
|
| Defer
|
||||||
| Go
|
| Go
|
||||||
| Slice
|
| Slice
|
||||||
|
| TypeAssertion
|
||||||
deriving (Eq, Generic, Ord, Show)
|
deriving (Eq, Generic, Ord, Show)
|
||||||
|
|
||||||
-- Instances
|
-- Instances
|
||||||
@ -215,6 +216,7 @@ instance Arbitrary Category where
|
|||||||
, pure Defer
|
, pure Defer
|
||||||
, pure Go
|
, pure Go
|
||||||
, pure Slice
|
, pure Slice
|
||||||
|
, pure TypeAssertion
|
||||||
, Other <$> arbitrary
|
, Other <$> arbitrary
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -179,6 +179,7 @@ toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of
|
|||||||
-- Returns a text representing a specific term given a source and a term.
|
-- Returns a text representing a specific term given a source and a term.
|
||||||
toTermName :: forall leaf fields. (HasCategory leaf, DefaultFields fields) => Source Char -> SyntaxTerm leaf fields -> Text
|
toTermName :: forall leaf fields. (HasCategory leaf, DefaultFields fields) => Source Char -> SyntaxTerm leaf fields -> Text
|
||||||
toTermName source term = case unwrap term of
|
toTermName source term = case unwrap term of
|
||||||
|
S.TypeAssertion _ _ -> termNameFromSource term
|
||||||
S.Go expr -> toTermName' expr
|
S.Go expr -> toTermName' expr
|
||||||
S.Defer expr -> toTermName' expr
|
S.Defer expr -> toTermName' expr
|
||||||
S.AnonymousFunction params _ -> "anonymous" <> paramsToArgNames params
|
S.AnonymousFunction params _ -> "anonymous" <> paramsToArgNames params
|
||||||
@ -400,6 +401,7 @@ instance HasCategory Category where
|
|||||||
C.Go -> "go statement"
|
C.Go -> "go statement"
|
||||||
C.Slice -> "slice expression"
|
C.Slice -> "slice expression"
|
||||||
C.Defer -> "defer statement"
|
C.Defer -> "defer statement"
|
||||||
|
C.TypeAssertion -> "type assertion"
|
||||||
|
|
||||||
instance HasField fields Category => HasCategory (SyntaxTerm leaf fields) where
|
instance HasField fields Category => HasCategory (SyntaxTerm leaf fields) where
|
||||||
toCategoryName = toCategoryName . category . extract
|
toCategoryName = toCategoryName . category . extract
|
||||||
|
@ -56,6 +56,9 @@ termConstructor source sourceSpan name range children = case (name, children) of
|
|||||||
("selector_expression", children) -> withDefaultInfo $ toSubscriptAccess children
|
("selector_expression", children) -> withDefaultInfo $ toSubscriptAccess children
|
||||||
("index_expression", children) -> withDefaultInfo $ toSubscriptAccess children
|
("index_expression", children) -> withDefaultInfo $ toSubscriptAccess children
|
||||||
("slice_expression", children) -> sliceToSubscriptAccess children
|
("slice_expression", children) -> sliceToSubscriptAccess children
|
||||||
|
("type_assertion_expression", children) -> withDefaultInfo $ case children of
|
||||||
|
[a, b] -> S.TypeAssertion a b
|
||||||
|
rest -> S.Error rest
|
||||||
-- TODO: Handle multiple var specs
|
-- TODO: Handle multiple var specs
|
||||||
("var_declaration", varSpecs) -> withDefaultInfo . S.Indexed =<< mapM toVarDecl varSpecs
|
("var_declaration", varSpecs) -> withDefaultInfo . S.Indexed =<< mapM toVarDecl varSpecs
|
||||||
("short_var_declaration", children) -> listToVarDecls children
|
("short_var_declaration", children) -> listToVarDecls children
|
||||||
@ -170,5 +173,6 @@ categoryForGoName = \case
|
|||||||
"communication_case" -> Case
|
"communication_case" -> Case
|
||||||
"defer_statement" -> Defer
|
"defer_statement" -> Defer
|
||||||
"go_statement" -> Go
|
"go_statement" -> Go
|
||||||
|
"type_assertion_expression" -> TypeAssertion
|
||||||
s -> Other (toS s)
|
s -> Other (toS s)
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ data Syntax a f
|
|||||||
| Rescue [f] [f]
|
| Rescue [f] [f]
|
||||||
| Go f
|
| Go f
|
||||||
| Defer f
|
| Defer f
|
||||||
|
| TypeAssertion f f
|
||||||
deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON)
|
deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user