1
1
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:
Timothy Clem 2018-01-12 13:08:07 -07:00
parent 891d489937
commit 132eb26486
2 changed files with 10 additions and 5 deletions

View File

@ -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)

View File

@ -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)