1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 04:10:29 +03:00

Add interfaces

This commit is contained in:
joshvera 2017-03-28 15:54:31 -04:00
parent f86d43a6e5
commit 9c5e73897b
5 changed files with 15 additions and 0 deletions

View File

@ -115,6 +115,8 @@ data Category
| Module
-- | A namespace in TypeScript.
| Namespace
-- | An interface
| Interface
-- | An import
| Import
-- | An export

View File

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

View File

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

View File

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

View File

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