diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 96680ed83..d6892a352 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -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) diff --git a/src/Language/Go.hs b/src/Language/Go.hs index ed692b254..d763b25d4 100644 --- a/src/Language/Go.hs +++ b/src/Language/Go.hs @@ -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 diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index b02d47882..9a9726da0 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -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 ] diff --git a/src/Syntax.hs b/src/Syntax.hs index 09e99e6d9..84c1356d8 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -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.