From c46a0bd6155cdca5fe22f7f1eb1d77604717e8ea Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 10 Jul 2017 15:58:29 -0700 Subject: [PATCH 1/3] :memo: --- src/Data/Syntax/Statement.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Syntax/Statement.hs b/src/Data/Syntax/Statement.hs index 17f708ffe..5a6ea79d0 100644 --- a/src/Data/Syntax/Statement.hs +++ b/src/Data/Syntax/Statement.hs @@ -38,7 +38,7 @@ newtype Pattern a = Pattern a instance Eq1 Pattern where liftEq = genericLiftEq instance Show1 Pattern where liftShowsPrec = genericLiftShowsPrec - +-- | A let statement or local binding, like 'a as b' or 'let a = b'. data Let a = Let { letVariable :: !a, letValue :: !a, letBody :: !a } deriving (Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) From b35091f7542efd8b94145f65746cd3da17965404 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 10 Jul 2017 15:58:41 -0700 Subject: [PATCH 2/3] Assign aliased imports --- src/Language/Python/Syntax.hs | 4 ++++ test/fixtures/python/import-statement.A.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 19838467b..03ecca3f3 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -124,6 +124,7 @@ statement = assertStatement <|> ifStatement <|> identifier <|> import' + <|> importAlias <|> importFrom <|> nonlocalStatement <|> passStatement @@ -354,6 +355,9 @@ import' = makeTerm <$> symbol ImportStatement <*> children (Declaration.Import < importFrom :: Assignment importFrom = makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> many expression) +importAlias :: Assignment +importAlias = makeTerm <$> symbol AliasedImport <*> children (flip Statement.Let <$> expression <*> expression <*> emptyTerm) + assertStatement :: Assignment assertStatement = makeTerm <$ symbol AssertStatement <*> location <*> children (Expression.Call <$> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier <$> source)) <*> many expression) diff --git a/test/fixtures/python/import-statement.A.py b/test/fixtures/python/import-statement.A.py index 212b3db10..245079e6a 100644 --- a/test/fixtures/python/import-statement.A.py +++ b/test/fixtures/python/import-statement.A.py @@ -1,2 +1,2 @@ -import a, b -import b.c as d +import a, b as c +import b.c as d, e From d6e101711710ca8e87cb21bc3aa3c3e352662b29 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 10 Jul 2017 16:11:03 -0700 Subject: [PATCH 3/3] Assign wildcard (*) in import from statements --- src/Language/Python/Syntax.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 03ecca3f3..3c952c3ed 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -133,6 +133,7 @@ statement = assertStatement <|> returnStatement <|> tryStatement <|> whileStatement + <|> wildcardImport <|> withStatement expressionStatement :: Assignment @@ -358,6 +359,9 @@ importFrom = makeTerm <$> symbol ImportFromStatement <*> children (Declaration.I importAlias :: Assignment importAlias = makeTerm <$> symbol AliasedImport <*> children (flip Statement.Let <$> expression <*> expression <*> emptyTerm) +wildcardImport :: Assignment +wildcardImport = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source) + assertStatement :: Assignment assertStatement = makeTerm <$ symbol AssertStatement <*> location <*> children (Expression.Call <$> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier <$> source)) <*> many expression)