mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Add import symbol declaration to Go
This commit is contained in:
parent
98a369668d
commit
494dbf8fe4
@ -251,13 +251,20 @@ instance Show1 Comprehension where liftShowsPrec = genericLiftShowsPrec
|
|||||||
instance (MonadFail m) => Eval t v m Comprehension
|
instance (MonadFail m) => Eval t v m Comprehension
|
||||||
|
|
||||||
-- | Import declarations.
|
-- | 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)
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
instance Eq1 Import where liftEq = genericLiftEq
|
instance Eq1 Import where liftEq = genericLiftEq
|
||||||
instance Ord1 Import where liftCompare = genericLiftCompare
|
instance Ord1 Import where liftCompare = genericLiftCompare
|
||||||
instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
|
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
|
-- TODO: Implement Eval instance for Import
|
||||||
instance (MonadFail m) => Eval t v m Import
|
instance (MonadFail m) => Eval t v m Import
|
||||||
|
|
||||||
|
@ -390,8 +390,8 @@ importDeclaration :: Assignment
|
|||||||
importDeclaration = mk <$> symbol ImportDeclaration <*> children (manyTerm (importSpec <|> importSpecList))
|
importDeclaration = mk <$> symbol ImportDeclaration <*> children (manyTerm (importSpec <|> importSpecList))
|
||||||
where
|
where
|
||||||
importSpec = makeTerm <$> symbol ImportSpec <*> children (namedImport <|> plainImport)
|
importSpec = makeTerm <$> symbol ImportSpec <*> children (namedImport <|> plainImport)
|
||||||
namedImport = flip Declaration.Import <$> expression <*> expression <*> emptyTerm
|
namedImport = flip Declaration.Import <$> expression <*> expression <*> pure []
|
||||||
plainImport = Declaration.Import <$> expression <*> emptyTerm <*> emptyTerm
|
plainImport = Declaration.Import <$> expression <*> emptyTerm <*> pure []
|
||||||
importSpecList = makeTerm <$> symbol ImportSpecList <*> children (manyTerm (importSpec <|> comment))
|
importSpecList = makeTerm <$> symbol ImportSpecList <*> children (manyTerm (importSpec <|> comment))
|
||||||
mk _ [child] = child
|
mk _ [child] = child
|
||||||
mk location children = makeTerm location children
|
mk location children = makeTerm location children
|
||||||
|
@ -377,10 +377,10 @@ comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
|
|||||||
|
|
||||||
import' :: Assignment
|
import' :: Assignment
|
||||||
import' = mk <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
|
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
|
where
|
||||||
aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> emptyTerm)
|
aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> pure [])
|
||||||
plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> emptyTerm)
|
plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> pure [])
|
||||||
wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
|
wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
|
||||||
mk _ [child] = child
|
mk _ [child] = child
|
||||||
mk location children = makeTerm location children
|
mk location children = makeTerm location children
|
||||||
|
@ -166,6 +166,7 @@ type Syntax = '[
|
|||||||
, TypeScript.Syntax.Update
|
, TypeScript.Syntax.Update
|
||||||
, TypeScript.Syntax.ComputedPropertyName
|
, TypeScript.Syntax.ComputedPropertyName
|
||||||
, TypeScript.Syntax.Decorator
|
, TypeScript.Syntax.Decorator
|
||||||
|
, Declaration.ImportSymbol
|
||||||
, []
|
, []
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user