1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 20:41:38 +03:00

Parse struct type declarations

This commit is contained in:
joshvera 2017-01-17 12:23:56 -05:00
parent 71a147862a
commit a95d57c8cf
4 changed files with 9 additions and 1 deletions

View File

@ -215,6 +215,7 @@ data Category
| DecrementStatement
-- | A qualified identifier, e.g. Module.function in Go.
| QualifiedIdentifier
| FieldDeclarations
deriving (Eq, Generic, Ord, Show)
-- Instances
@ -322,6 +323,7 @@ instance Arbitrary Category where
, pure IncrementStatement
, pure DecrementStatement
, pure QualifiedIdentifier
, pure FieldDeclarations
, Other <$> arbitrary
]

View File

@ -469,6 +469,7 @@ instance HasCategory Category where
C.IncrementStatement -> "increment statement"
C.DecrementStatement -> "decrement statement"
C.QualifiedIdentifier -> "qualified identifier"
C.FieldDeclarations -> "field declarations"
instance HasField fields Category => HasCategory (SyntaxTerm leaf fields) where
toCategoryName = toCategoryName . category . extract

View File

@ -42,7 +42,7 @@ termConstructor source sourceSpan name range children _ = case name of
other -> S.Error other
"type_declaration" -> toTypeDecls children
"type_spec" -> toTypeDecl children
"struct_type" -> toStruct children
"struct_type" -> toStructTy children
"field_declaration" -> toFieldDecl children
"expression_switch_statement" ->
case Prologue.break isCaseClause children of
@ -124,6 +124,10 @@ termConstructor source sourceSpan name range children _ = case name of
[] -> S.Leaf . toText $ slice range source
_ -> S.Indexed children
where
toStructTy children = do
fields <- withRanges range FieldDeclarations children (S.Indexed children)
withDefaultInfo (S.Ty fields)
toLiteral = \case
children@[ty, _] -> case category (extract ty) of
ArrayTy -> toImplicitArray children

View File

@ -143,6 +143,7 @@ styleName category = "category-" <> case category of
C.DecrementStatement -> "decrement_statement"
C.QualifiedIdentifier -> "qualified_identifier"
C.IndexExpression -> "index_expression"
C.FieldDeclarations -> "field_declarations"
-- | Pick the class name for a split patch.
splitPatchToClassName :: SplitPatch a -> AttributeValue