1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00

Add import symbol declaration to Go

This commit is contained in:
joshvera 2018-01-16 18:16:18 -05:00
parent 98a369668d
commit 494dbf8fe4
4 changed files with 14 additions and 6 deletions

View File

@ -251,13 +251,20 @@ instance Show1 Comprehension where liftShowsPrec = genericLiftShowsPrec
instance (MonadFail m) => Eval t v m Comprehension
-- | Import declarations.
data Import a = Import { importFrom :: !a, importAlias :: !a, importSymbols :: !a }
data Import a = Import { importFrom :: !a, importAlias :: !a, importSymbols :: ![a] }
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
instance Eq1 Import where liftEq = genericLiftEq
instance Ord1 Import where liftCompare = genericLiftCompare
instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
data ImportSymbol a = ImportSymbol { importSymbolName :: !a, importSymbolAlias :: !a }
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
instance Eq1 ImportSymbol where liftEq = genericLiftEq
instance Ord1 ImportSymbol where liftCompare = genericLiftCompare
instance Show1 ImportSymbol where liftShowsPrec = genericLiftShowsPrec
-- TODO: Implement Eval instance for Import
instance (MonadFail m) => Eval t v m Import

View File

@ -390,8 +390,8 @@ importDeclaration :: Assignment
importDeclaration = mk <$> symbol ImportDeclaration <*> children (manyTerm (importSpec <|> importSpecList))
where
importSpec = makeTerm <$> symbol ImportSpec <*> children (namedImport <|> plainImport)
namedImport = flip Declaration.Import <$> expression <*> expression <*> emptyTerm
plainImport = Declaration.Import <$> expression <*> emptyTerm <*> emptyTerm
namedImport = flip Declaration.Import <$> expression <*> expression <*> pure []
plainImport = Declaration.Import <$> expression <*> emptyTerm <*> pure []
importSpecList = makeTerm <$> symbol ImportSpecList <*> children (manyTerm (importSpec <|> comment))
mk _ [child] = child
mk location children = makeTerm location children

View File

@ -377,10 +377,10 @@ comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
import' :: Assignment
import' = mk <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> expression <*> emptyTerm <*> (wildCard <|> expressions))
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> expression <*> emptyTerm <*> (pure <$> (wildCard <|> expressions)))
where
aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> emptyTerm)
plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> emptyTerm)
aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> pure [])
plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> pure [])
wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
mk _ [child] = child
mk location children = makeTerm location children

View File

@ -166,6 +166,7 @@ type Syntax = '[
, TypeScript.Syntax.Update
, TypeScript.Syntax.ComputedPropertyName
, TypeScript.Syntax.Decorator
, Declaration.ImportSymbol
, []
]