mirror of
https://github.com/github/semantic.git
synced 2024-12-01 00:33:59 +03:00
Add namespace mapping
This commit is contained in:
parent
d9c40de4e1
commit
f86d43a6e5
@ -113,6 +113,8 @@ data Category
|
||||
| MathOperator
|
||||
-- | A module
|
||||
| Module
|
||||
-- | A namespace in TypeScript.
|
||||
| Namespace
|
||||
-- | An import
|
||||
| Import
|
||||
-- | An export
|
||||
|
@ -62,6 +62,6 @@ toTuple child = pure child
|
||||
toPublicFieldDefinition :: (HasField fields Category) => [SyntaxTerm Text fields] -> Maybe (S.Syntax Text (SyntaxTerm Text fields))
|
||||
toPublicFieldDefinition children = case break (\x -> category (extract x) == Identifier) children of
|
||||
(prev, [identifier, assignment]) -> Just $ S.VarAssignment (prev ++ [identifier]) assignment
|
||||
(prev, [identifier]) -> Just $ S.VarDecl children
|
||||
(_, [_]) -> Just $ S.VarDecl children
|
||||
_ -> Nothing
|
||||
|
||||
|
@ -51,6 +51,8 @@ termAssignment _ category children =
|
||||
(Method, [ identifier, exprs ]) -> Just $ S.Method identifier Nothing Nothing [] (toList (unwrap exprs))
|
||||
(Class, [ identifier, superclass, definitions ]) -> Just $ S.Class identifier (Just superclass) (toList (unwrap definitions))
|
||||
(Class, [ identifier, definitions ]) -> Just $ S.Class identifier Nothing (toList (unwrap definitions))
|
||||
(Module, [ identifier, definitions ]) -> Just $ S.Module identifier (toList (unwrap definitions))
|
||||
(Namespace, [ identifier, definitions ]) -> Just $ S.Namespace identifier (toList (unwrap definitions))
|
||||
(Import, [ statements, identifier ] ) -> Just $ S.Import identifier (toList (unwrap statements))
|
||||
(Import, [ identifier ] ) -> Just $ S.Import identifier []
|
||||
(Export, [ statements, identifier] ) -> Just $ S.Export (Just identifier) (toList (unwrap statements))
|
||||
@ -145,4 +147,6 @@ categoryForTypeScriptName = \case
|
||||
"type_annotation" -> Ty
|
||||
"accessibility_modifier" -> Identifier
|
||||
"template_chars" -> TemplateString
|
||||
"module" -> Module
|
||||
"ambient_namespace" -> Namespace
|
||||
name -> Other name
|
||||
|
@ -131,7 +131,8 @@ syntaxToTermField syntax = case syntax of
|
||||
S.Class identifier superclass definitions -> [ "identifier" .= identifier ] <> [ "superclass" .= superclass ] <> [ "definitions" .= definitions ]
|
||||
S.Method identifier receiver ty parameters definitions -> [ "identifier" .= identifier ] <> [ "receiver" .= receiver ] <> [ "type" .= ty ] <> [ "parameters" .= parameters ] <> [ "definitions" .= definitions ]
|
||||
S.If expression clauses -> [ "expression" .= expression ] <> childrenFields clauses
|
||||
S.Module identifier definitions-> [ "identifier" .= identifier ] <> [ "definitions" .= definitions ]
|
||||
S.Module identifier definitions -> [ "identifier" .= identifier ] <> [ "definitions" .= definitions ]
|
||||
S.Namespace identifier definitions -> [ "identifier" .= identifier ] <> [ "definitions" .= definitions ]
|
||||
S.Import identifier statements -> [ "identifier" .= identifier ] <> [ "statements" .= statements ]
|
||||
S.Export identifier statements -> [ "identifier" .= identifier ] <> [ "statements" .= statements ]
|
||||
S.Yield expr -> [ "yieldExpression" .= expr ]
|
||||
|
@ -84,6 +84,7 @@ styleName category = "category-" <> case category of
|
||||
C.CommaOperator -> "comma_operator"
|
||||
Other string -> string
|
||||
C.Module -> "module_statement"
|
||||
C.Namespace -> "namespace"
|
||||
C.Import -> "import_statement"
|
||||
C.Export -> "export_statement"
|
||||
C.AnonymousFunction -> "anonymous_function"
|
||||
|
@ -38,6 +38,7 @@ annotatable term = isAnnotatable (unwrap term) term
|
||||
S.Method{} -> Annotatable
|
||||
S.Function{} -> Annotatable
|
||||
S.Module{} -> Annotatable
|
||||
S.Namespace{} -> Annotatable
|
||||
_ -> Unannotatable
|
||||
|
||||
data Identifiable a = Identifiable a | Unidentifiable a
|
||||
@ -53,6 +54,7 @@ identifiable term = isIdentifiable (unwrap term) term
|
||||
S.VarAssignment{} -> Identifiable
|
||||
S.SubscriptAccess{} -> Identifiable
|
||||
S.Module{} -> Identifiable
|
||||
S.Namespace{} -> Identifiable
|
||||
S.Class{} -> Identifiable
|
||||
S.Method{} -> Identifiable
|
||||
S.Leaf{} -> Identifiable
|
||||
@ -270,6 +272,7 @@ toTermName source term = case unwrap term of
|
||||
S.Comment a -> toS a
|
||||
S.Commented _ _ -> termNameFromChildren term (toList $ unwrap term)
|
||||
S.Module identifier _ -> toTermName' identifier
|
||||
S.Namespace 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) <> " }"
|
||||
@ -434,6 +437,7 @@ instance HasCategory Category where
|
||||
C.CommaOperator -> "comma operator"
|
||||
C.Empty -> "empty statement"
|
||||
C.Module -> "module"
|
||||
C.Namespace -> "namespace"
|
||||
C.Import -> "import statement"
|
||||
C.Export -> "export statement"
|
||||
C.AnonymousFunction -> "anonymous function"
|
||||
|
@ -79,6 +79,7 @@ data Syntax a f
|
||||
| If f [f]
|
||||
-- | A module with an identifier, and a list of syntaxes.
|
||||
| Module { moduleId:: f, moduleBody :: [f] }
|
||||
| Namespace { namespaceId:: f, namespaceBody :: [f] }
|
||||
| Import f [f]
|
||||
| Export (Maybe f) [f]
|
||||
| Yield [f]
|
||||
@ -148,6 +149,7 @@ instance Listable2 Syntax where
|
||||
\/ liftCons5 recur (liftTiers recur) (liftTiers recur) (liftTiers recur) (liftTiers recur) Method
|
||||
\/ liftCons2 recur (liftTiers recur) If
|
||||
\/ liftCons2 recur (liftTiers recur) Module
|
||||
\/ liftCons2 recur (liftTiers recur) Namespace
|
||||
\/ liftCons2 recur (liftTiers recur) Import
|
||||
\/ liftCons2 (liftTiers recur) (liftTiers recur) Export
|
||||
\/ liftCons1 (liftTiers recur) Yield
|
||||
|
@ -67,7 +67,6 @@ documentToTerm language document SourceBlob{..} = do
|
||||
copyNamed = ts_node_copy_named_child_nodes document
|
||||
copyAll = ts_node_copy_child_nodes document
|
||||
|
||||
|
||||
isNonEmpty :: HasField fields Category => SyntaxTerm Text fields -> Bool
|
||||
isNonEmpty = (/= Empty) . category . extract
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
namespace Promise {
|
||||
declare namespace Promise {
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
{+(Program
|
||||
(Other "module"
|
||||
(Module
|
||||
(Identifier)))+}
|
||||
|
@ -1,5 +1,4 @@
|
||||
{+(Program
|
||||
(ParseError
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(ExpressionStatements))+}
|
||||
(Other "ambient_declaration"
|
||||
(Namespace
|
||||
(Identifier))))+}
|
||||
|
@ -1,3 +1,3 @@
|
||||
{-(Program
|
||||
(Other "module"
|
||||
(Module
|
||||
(Identifier)))-}
|
||||
|
@ -1,5 +1,4 @@
|
||||
{-(Program
|
||||
(ParseError
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(ExpressionStatements))-}
|
||||
(Other "ambient_declaration"
|
||||
(Namespace
|
||||
(Identifier))))-}
|
||||
|
@ -1,7 +1,6 @@
|
||||
(Program
|
||||
{+(ParseError
|
||||
(Identifier)
|
||||
(Identifier))+}
|
||||
{+(ExpressionStatements)+}
|
||||
{-(Other "module"
|
||||
{+(Other "ambient_declaration"
|
||||
(Namespace
|
||||
(Identifier)))+}
|
||||
{-(Module
|
||||
(Identifier))-})
|
||||
|
@ -1,7 +1,6 @@
|
||||
(Program
|
||||
{+(Other "module"
|
||||
{+(Module
|
||||
(Identifier))+}
|
||||
{-(ParseError
|
||||
(Identifier)
|
||||
(Identifier))-}
|
||||
{-(ExpressionStatements)-})
|
||||
{-(Other "ambient_declaration"
|
||||
(Namespace
|
||||
(Identifier)))-})
|
||||
|
@ -1,3 +1,3 @@
|
||||
(Program
|
||||
(Other "module"
|
||||
(Module
|
||||
(Identifier)))
|
||||
|
@ -1,5 +1,4 @@
|
||||
(Program
|
||||
(ParseError
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(ExpressionStatements))
|
||||
(Other "ambient_declaration"
|
||||
(Namespace
|
||||
(Identifier))))
|
||||
|
Loading…
Reference in New Issue
Block a user