diff --git a/src/Category.hs b/src/Category.hs index 18a355861..f20bfa894 100644 --- a/src/Category.hs +++ b/src/Category.hs @@ -115,6 +115,8 @@ data Category | Module -- | A namespace in TypeScript. | Namespace + -- | An interface + | Interface -- | An import | Import -- | An export diff --git a/src/Language.hs b/src/Language.hs index 1776ea38e..8fa67cab0 100644 --- a/src/Language.hs +++ b/src/Language.hs @@ -65,3 +65,8 @@ toPublicFieldDefinition children = case break (\x -> category (extract x) == Ide (_, [_]) -> Just $ S.VarDecl children _ -> Nothing +toInterface :: (HasField fields Category) => [SyntaxTerm Text fields] -> Maybe (S.Syntax Text (SyntaxTerm Text fields)) +toInterface (id : rest) = case break (\x -> category (extract x) == Other "object_type") rest of + (clauses, [body]) -> Just $ S.Interface id clauses (toList (unwrap body)) + _ -> Nothing +toInterface _ = Nothing diff --git a/src/Language/TypeScript.hs b/src/Language/TypeScript.hs index aaac759b5..54e21e240 100644 --- a/src/Language/TypeScript.hs +++ b/src/Language/TypeScript.hs @@ -67,6 +67,7 @@ termAssignment _ category children = (Function, [ params, body ]) -> Just $ S.AnonymousFunction (toList (unwrap params)) [body] (Function, [ id, params, body ]) -> Just $ S.Function id (toList (unwrap params)) Nothing [body] (Ty, children) -> Just $ S.Ty children + (Interface, children) -> toInterface children _ -> Nothing categoryForTypeScriptName :: Text -> Category @@ -149,4 +150,5 @@ categoryForTypeScriptName = \case "template_chars" -> TemplateString "module" -> Module "ambient_namespace" -> Namespace + "interface_declaration" -> Interface name -> Other name diff --git a/src/Renderer/Summary.hs b/src/Renderer/Summary.hs index 1e9167ce2..f126b0cf9 100644 --- a/src/Renderer/Summary.hs +++ b/src/Renderer/Summary.hs @@ -39,6 +39,7 @@ annotatable term = isAnnotatable (unwrap term) term S.Function{} -> Annotatable S.Module{} -> Annotatable S.Namespace{} -> Annotatable + S.Interface{} -> Annotatable _ -> Unannotatable data Identifiable a = Identifiable a | Unidentifiable a @@ -55,6 +56,7 @@ identifiable term = isIdentifiable (unwrap term) term S.SubscriptAccess{} -> Identifiable S.Module{} -> Identifiable S.Namespace{} -> Identifiable + S.Interface{} -> Identifiable S.Class{} -> Identifiable S.Method{} -> Identifiable S.Leaf{} -> Identifiable @@ -273,6 +275,7 @@ toTermName source term = case unwrap term of S.Commented _ _ -> termNameFromChildren term (toList $ unwrap term) S.Module identifier _ -> toTermName' identifier S.Namespace identifier _ -> toTermName' identifier + S.Interface identifier _ _ -> toTermName' identifier S.Import identifier [] -> termNameFromSource identifier S.Import identifier exprs -> termNameFromChildren term exprs <> " from " <> toTermName' identifier S.Export Nothing expr -> "{ " <> Text.intercalate ", " (termNameFromSource <$> expr) <> " }" @@ -438,6 +441,7 @@ instance HasCategory Category where C.Empty -> "empty statement" C.Module -> "module" C.Namespace -> "namespace" + C.Interface -> "interface" C.Import -> "import statement" C.Export -> "export statement" C.AnonymousFunction -> "anonymous function" diff --git a/src/Syntax.hs b/src/Syntax.hs index 7fc3b8b29..4b10535c8 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -79,6 +79,8 @@ data Syntax a f | If f [f] -- | A module with an identifier, and a list of syntaxes. | Module { moduleId:: f, moduleBody :: [f] } + -- | An interface with an identifier, a list of clauses, and a list of declarations.. + | Interface f [f] [f] | Namespace { namespaceId:: f, namespaceBody :: [f] } | Import f [f] | Export (Maybe f) [f]