mirror of
https://github.com/github/semantic.git
synced 2025-01-02 12:23:08 +03:00
Give imports a bit more structure
This commit is contained in:
parent
891d489937
commit
132eb26486
@ -251,7 +251,7 @@ 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 { importContent :: ![a] }
|
data Import a = Import { importFrom :: !a, importSymbols :: !a, importAlias :: !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
|
||||||
@ -261,6 +261,7 @@ instance Show1 Import 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
|
||||||
|
|
||||||
|
|
||||||
-- | A declared type (e.g. `a []int` in Go).
|
-- | A declared type (e.g. `a []int` in Go).
|
||||||
data Type a = Type { typeName :: !a, typeKind :: !a }
|
data Type a = Type { typeName :: !a, typeKind :: !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)
|
||||||
|
@ -374,10 +374,14 @@ comment :: Assignment
|
|||||||
comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
|
comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
|
||||||
|
|
||||||
import' :: Assignment
|
import' :: Assignment
|
||||||
import' = makeTerm <$> symbol ImportStatement <*> children (Declaration.Import <$> manyTerm expression)
|
import' = mk <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
|
||||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> manyTerm expression)
|
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> expression <*> (wildCard <|> expressions) <*> emptyTerm)
|
||||||
<|> makeTerm <$> symbol AliasedImport <*> children (flip Statement.Let <$> term expression <*> term expression <*> emptyTerm)
|
where
|
||||||
<|> makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
|
aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> emptyTerm <*> expression)
|
||||||
|
plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> emptyTerm)
|
||||||
|
wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
|
||||||
|
mk _ [child] = child
|
||||||
|
mk location children = makeTerm location children
|
||||||
|
|
||||||
assertStatement :: Assignment
|
assertStatement :: Assignment
|
||||||
assertStatement = makeTerm <$> symbol AssertStatement <*> children (Expression.Call <$> pure [] <*> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier <$> source)) <*> manyTerm expression <*> emptyTerm)
|
assertStatement = makeTerm <$> symbol AssertStatement <*> children (Expression.Call <$> pure [] <*> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier <$> source)) <*> manyTerm expression <*> emptyTerm)
|
||||||
|
Loading…
Reference in New Issue
Block a user