mirror of
https://github.com/github/semantic.git
synced 2024-12-21 13:51:44 +03:00
Add tag to FieldDecl
This commit is contained in:
parent
e0983245d2
commit
52c4f1a7b4
@ -264,7 +264,7 @@ toTermName source term = case unwrap term of
|
||||
S.Continue expr -> toTermName' expr
|
||||
S.BlockStatement children -> termNameFromChildren term children
|
||||
S.Default children -> termNameFromChildren term children
|
||||
S.FieldDecl id expr -> termNameFromSource id <> (maybe "" (\expr' -> " " <> termNameFromSource expr') expr)
|
||||
S.FieldDecl id expr tag -> termNameFromSource id <> (maybe "" (\expr' -> " " <> termNameFromSource expr') expr) <> (maybe "" ((" " <>) . termNameFromSource) tag)
|
||||
where toTermName' = toTermName source
|
||||
termNameFromChildren term children = termNameFromRange (unionRangesFrom (range term) (range <$> children))
|
||||
termNameFromSource term = termNameFromRange (range term)
|
||||
|
@ -143,9 +143,13 @@ termConstructor source sourceSpan name range children _ = case name of
|
||||
[ty, values] -> withCategory Struct (S.Struct (Just ty) (toList $ unwrap values))
|
||||
rest -> withRanges range Error rest $ S.Error rest
|
||||
toFieldDecl = \case
|
||||
[identifier, ty] -> withCategory FieldDecl (S.FieldDecl identifier (Just ty))
|
||||
[identifier] -> withCategory FieldDecl (S.FieldDecl identifier Nothing)
|
||||
rest -> withRanges range Error rest $ S.Error rest
|
||||
rest@[identifier, ty] -> case category (extract ty) of
|
||||
Identifier -> withCategory FieldDecl (S.FieldDecl identifier (Just ty) Nothing)
|
||||
StringLiteral -> withCategory FieldDecl (S.FieldDecl identifier Nothing (Just ty))
|
||||
_ -> withRanges range Error rest (S.Error rest)
|
||||
[identifier] -> withCategory FieldDecl (S.FieldDecl identifier Nothing Nothing)
|
||||
[identifier, ty, tag] -> withCategory FieldDecl (S.FieldDecl identifier (Just ty) (Just tag))
|
||||
rest -> withRanges range Error rest (S.Error rest)
|
||||
|
||||
toExpression f = \case
|
||||
[expr] -> f expr
|
||||
|
@ -149,7 +149,7 @@ syntaxToTermField syntax = case syntax of
|
||||
S.ParameterDecl ty field -> [ "type" .= ty ] <> [ "identifier" .= field ]
|
||||
S.Default c -> childrenFields c
|
||||
S.TypeDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
||||
S.FieldDecl id ty -> [ "type" .= ty ] <> [ "identifier" .= id ]
|
||||
S.FieldDecl id ty tag -> [ "type" .= ty ] <> [ "identifier" .= id ] <> [ "tag" .= tag]
|
||||
S.Ty ty -> [ "type" .= ty ]
|
||||
S.Send channel expr -> [ "channel" .= channel ] <> [ "expression" .= expr ]
|
||||
where childrenFields c = [ "children" .= c ]
|
||||
|
@ -98,8 +98,8 @@ data Syntax a f
|
||||
| ParameterDecl (Maybe f) f
|
||||
-- | A type declaration has an identifier and a type.
|
||||
| TypeDecl f f
|
||||
-- | A field declaration.
|
||||
| FieldDecl f (Maybe f)
|
||||
-- | A field declaration with an optional type, and an optional tag.
|
||||
| FieldDecl f (Maybe f) (Maybe f)
|
||||
-- | A type.
|
||||
| Ty f
|
||||
-- | A send statement has a channel and an expression in Go.
|
||||
|
Loading…
Reference in New Issue
Block a user