1
1
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:
joshvera 2017-01-17 11:53:44 -05:00
parent e0983245d2
commit 52c4f1a7b4
4 changed files with 11 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 ]

View File

@ -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.