diff --git a/src/Data/Syntax/Declaration.hs b/src/Data/Syntax/Declaration.hs index 6d904ae76..3022d8e89 100644 --- a/src/Data/Syntax/Declaration.hs +++ b/src/Data/Syntax/Declaration.hs @@ -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) diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index 55eb80a71..210f408d4 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -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)