mirror of
https://github.com/github/semantic.git
synced 2024-12-30 18:36:27 +03:00
Add send statements
This commit is contained in:
parent
45fe48b1ad
commit
20ead53d1c
@ -203,6 +203,8 @@ data Category
|
||||
| Literal
|
||||
-- | A channel type in Go.
|
||||
| ChannelTy
|
||||
-- | A send statement in Go.
|
||||
| Send
|
||||
deriving (Eq, Generic, Ord, Show)
|
||||
|
||||
-- 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.
|
||||
toTermName :: forall leaf fields. (HasCategory leaf, DefaultFields fields) => Source Char -> SyntaxTerm leaf fields -> Text
|
||||
toTermName source term = case unwrap term of
|
||||
S.Send _ _ -> termNameFromSource term
|
||||
S.Ty ty -> termNameFromSource ty
|
||||
S.TypeDecl id _ -> toTermName' id
|
||||
S.TypeAssertion _ _ -> termNameFromSource term
|
||||
@ -461,6 +462,7 @@ instance HasCategory Category where
|
||||
C.Element -> "element"
|
||||
C.Literal -> "literal"
|
||||
C.ChannelTy -> "channel type"
|
||||
C.Send -> "send statement"
|
||||
|
||||
instance HasField fields Category => HasCategory (SyntaxTerm leaf fields) where
|
||||
toCategoryName = toCategoryName . category . extract
|
||||
|
@ -107,6 +107,9 @@ termConstructor source sourceSpan name range children _ = case name of
|
||||
"channel_type" -> withDefaultInfo $ case children of
|
||||
[ty] -> S.Ty ty
|
||||
rest -> S.Error rest
|
||||
"send_statement" -> withDefaultInfo $ case children of
|
||||
[channel, expr] -> S.Send channel expr
|
||||
rest -> S.Error rest
|
||||
_ -> withDefaultInfo $ case children of
|
||||
[] -> S.Leaf . toText $ slice range source
|
||||
_ -> S.Indexed children
|
||||
@ -261,4 +264,5 @@ categoryForGoName = \case
|
||||
"element" -> Element
|
||||
"literal_value" -> Literal
|
||||
"channel_type" -> ChannelTy
|
||||
"send_statement" -> Send
|
||||
s -> Other (toS s)
|
||||
|
@ -151,4 +151,5 @@ syntaxToTermField syntax = case syntax of
|
||||
S.TypeDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
||||
S.FieldDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
||||
S.Ty ty -> [ "type" .= ty ]
|
||||
S.Send channel expr -> [ "channel" .= channel ] <> [ "expression" .= expr ]
|
||||
where childrenFields c = [ "children" .= c ]
|
||||
|
@ -102,6 +102,8 @@ data Syntax a f
|
||||
| FieldDecl f (Maybe f)
|
||||
-- | A type.
|
||||
| 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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user