mirror of
https://github.com/github/semantic.git
synced 2024-12-21 13:51:44 +03:00
Add send statements
This commit is contained in:
parent
45fe48b1ad
commit
20ead53d1c
@ -203,6 +203,8 @@ data Category
|
|||||||
| Literal
|
| Literal
|
||||||
-- | A channel type in Go.
|
-- | A channel type in Go.
|
||||||
| ChannelTy
|
| ChannelTy
|
||||||
|
-- | A send statement in Go.
|
||||||
|
| Send
|
||||||
deriving (Eq, Generic, Ord, Show)
|
deriving (Eq, Generic, Ord, Show)
|
||||||
|
|
||||||
-- Instances
|
-- Instances
|
||||||
|
@ -185,6 +185,7 @@ toLeafInfos LeafInfo{..} = pure $ JSONSummary (summary leafCategory termName) so
|
|||||||
-- 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.Send _ _ -> termNameFromSource term
|
||||||
S.Ty ty -> termNameFromSource ty
|
S.Ty ty -> termNameFromSource ty
|
||||||
S.TypeDecl id _ -> toTermName' id
|
S.TypeDecl id _ -> toTermName' id
|
||||||
S.TypeAssertion _ _ -> termNameFromSource term
|
S.TypeAssertion _ _ -> termNameFromSource term
|
||||||
@ -461,6 +462,7 @@ instance HasCategory Category where
|
|||||||
C.Element -> "element"
|
C.Element -> "element"
|
||||||
C.Literal -> "literal"
|
C.Literal -> "literal"
|
||||||
C.ChannelTy -> "channel type"
|
C.ChannelTy -> "channel type"
|
||||||
|
C.Send -> "send statement"
|
||||||
|
|
||||||
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
|
||||||
|
@ -107,6 +107,9 @@ termConstructor source sourceSpan name range children _ = case name of
|
|||||||
"channel_type" -> withDefaultInfo $ case children of
|
"channel_type" -> withDefaultInfo $ case children of
|
||||||
[ty] -> S.Ty ty
|
[ty] -> S.Ty ty
|
||||||
rest -> S.Error rest
|
rest -> S.Error rest
|
||||||
|
"send_statement" -> withDefaultInfo $ case children of
|
||||||
|
[channel, expr] -> S.Send channel expr
|
||||||
|
rest -> S.Error rest
|
||||||
_ -> withDefaultInfo $ case children of
|
_ -> withDefaultInfo $ case children of
|
||||||
[] -> S.Leaf . toText $ slice range source
|
[] -> S.Leaf . toText $ slice range source
|
||||||
_ -> S.Indexed children
|
_ -> S.Indexed children
|
||||||
@ -261,4 +264,5 @@ categoryForGoName = \case
|
|||||||
"element" -> Element
|
"element" -> Element
|
||||||
"literal_value" -> Literal
|
"literal_value" -> Literal
|
||||||
"channel_type" -> ChannelTy
|
"channel_type" -> ChannelTy
|
||||||
|
"send_statement" -> Send
|
||||||
s -> Other (toS s)
|
s -> Other (toS s)
|
||||||
|
@ -151,4 +151,5 @@ syntaxToTermField syntax = case syntax of
|
|||||||
S.TypeDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
S.TypeDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
||||||
S.FieldDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
S.FieldDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
||||||
S.Ty ty -> [ "type" .= ty ]
|
S.Ty ty -> [ "type" .= ty ]
|
||||||
|
S.Send channel expr -> [ "channel" .= channel ] <> [ "expression" .= expr ]
|
||||||
where childrenFields c = [ "children" .= c ]
|
where childrenFields c = [ "children" .= c ]
|
||||||
|
@ -102,6 +102,8 @@ data Syntax a f
|
|||||||
| FieldDecl f (Maybe f)
|
| FieldDecl f (Maybe f)
|
||||||
-- | A type.
|
-- | A type.
|
||||||
| Ty f
|
| Ty f
|
||||||
|
-- | A send statement has a channel and an expression in Go.
|
||||||
|
| Send 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