mirror of
https://github.com/github/semantic.git
synced 2024-12-30 18:36:27 +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
|
||||
|
||||
-- | 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)
|
||||
|
||||
instance Eq1 Import where liftEq = genericLiftEq
|
||||
@ -261,6 +261,7 @@ instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
|
||||
-- TODO: Implement Eval instance for Import
|
||||
instance (MonadFail m) => Eval t v m Import
|
||||
|
||||
|
||||
-- | A declared type (e.g. `a []int` in Go).
|
||||
data Type a = Type { typeName :: !a, typeKind :: !a }
|
||||
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)
|
||||
|
||||
import' :: Assignment
|
||||
import' = makeTerm <$> symbol ImportStatement <*> children (Declaration.Import <$> manyTerm expression)
|
||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> manyTerm expression)
|
||||
<|> makeTerm <$> symbol AliasedImport <*> children (flip Statement.Let <$> term expression <*> term expression <*> emptyTerm)
|
||||
<|> makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source)
|
||||
import' = mk <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
|
||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> expression <*> (wildCard <|> expressions) <*> emptyTerm)
|
||||
where
|
||||
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 = makeTerm <$> symbol AssertStatement <*> children (Expression.Call <$> pure [] <*> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier <$> source)) <*> manyTerm expression <*> emptyTerm)
|
||||
|
Loading…
Reference in New Issue
Block a user