From c1e8ce39e25d084701ad736d72d5635768c29c6e Mon Sep 17 00:00:00 2001 From: joshvera Date: Tue, 13 Feb 2018 11:57:40 -0500 Subject: [PATCH 1/3] Fix definition of plainImport since dotted names can have many expressions --- src/Language/Python/Assignment.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index e9a655787..7515d3cc9 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -379,7 +379,7 @@ import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliased wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source) aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> pure []) - plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> pure []) + plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> (makeTerm <$> location <*> manyTerm expression) <*> emptyTerm <*> pure []) assertStatement :: Assignment assertStatement = makeTerm <$> symbol AssertStatement <*> children (Expression.Call <$> pure [] <*> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier <$> source)) <*> manyTerm expression <*> emptyTerm) From 616a82eb8a2ce6336c3bd8893d7e8d8b29e1f760 Mon Sep 17 00:00:00 2001 From: joshvera Date: Tue, 13 Feb 2018 12:44:50 -0500 Subject: [PATCH 2/3] Fix tests --- src/Language/Python/Assignment.hs | 2 +- .../python/import-from-statement.A.py | 2 + .../python/import-from-statement.B.py | 2 + .../python/import-from-statement.diffA-B.txt | 13 +++++- .../python/import-from-statement.diffB-A.txt | 22 +++++++++- .../python/import-from-statement.parseA.txt | 12 +++++- .../python/import-from-statement.parseB.txt | 12 +++++- test/fixtures/python/import-statement.A.py | 1 + test/fixtures/python/import-statement.B.py | 1 + .../python/import-statement.diffA-B.txt | 36 ++++++---------- .../python/import-statement.diffB-A.txt | 43 +++++++++++-------- .../python/import-statement.parseA.txt | 7 +-- .../python/import-statement.parseB.txt | 9 ++-- 13 files changed, 109 insertions(+), 53 deletions(-) diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index 7515d3cc9..dc1d5f00c 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -372,7 +372,7 @@ comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source) import' :: Assignment import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport)) - <|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> expression <*> emptyTerm <*> someTerm (wildCard <|> dottedName <|> aliasedSymbol <|> importSymbol)) + <|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> (dottedName <|> emptyTerm) <*> emptyTerm <*> someTerm (wildCard <|> dottedName <|> aliasedSymbol <|> importSymbol)) where importSymbol = makeTerm <$> location <*> (Declaration.ImportSymbol <$> expression <*> emptyTerm) aliasedSymbol = makeTerm <$> symbol AliasedImport <*> children (Declaration.ImportSymbol <$> expression <*> expression) diff --git a/test/fixtures/python/import-from-statement.A.py b/test/fixtures/python/import-from-statement.A.py index aa69e6bd0..4e4a834f8 100644 --- a/test/fixtures/python/import-from-statement.A.py +++ b/test/fixtures/python/import-from-statement.A.py @@ -1,3 +1,5 @@ from a import b from a import (b, c) from a import * +from a.b import c +from . import b diff --git a/test/fixtures/python/import-from-statement.B.py b/test/fixtures/python/import-from-statement.B.py index a0fee349b..c1fd4cf48 100644 --- a/test/fixtures/python/import-from-statement.B.py +++ b/test/fixtures/python/import-from-statement.B.py @@ -2,3 +2,5 @@ from b import a from b import (c, a) from b import * from b import a as x, b as y +from b.c import d +from . import d diff --git a/test/fixtures/python/import-from-statement.diffA-B.txt b/test/fixtures/python/import-from-statement.diffA-B.txt index ebfbcbcbd..2cadaa8b2 100644 --- a/test/fixtures/python/import-from-statement.diffA-B.txt +++ b/test/fixtures/python/import-from-statement.diffA-B.txt @@ -35,4 +35,15 @@ {+(ImportSymbol {+(ScopeResolution {+(Identifier)+})+} - {+(Identifier)+})+})+}) + {+(Identifier)+})+})+} + (Import + (ScopeResolution + {-(Identifier)-} + (Identifier) + {+(Identifier)+}) + (Empty) + (ScopeResolution{(Identifier)->(Identifier)})) + (Import + (Empty) + (Empty) + (ScopeResolution{(Identifier)->(Identifier)}))) diff --git a/test/fixtures/python/import-from-statement.diffB-A.txt b/test/fixtures/python/import-from-statement.diffB-A.txt index 2e71d6711..03691e0ea 100644 --- a/test/fixtures/python/import-from-statement.diffB-A.txt +++ b/test/fixtures/python/import-from-statement.diffB-A.txt @@ -24,6 +24,16 @@ ->(Identifier) }) (Empty) (Identifier)) +{+(Import + {+(ScopeResolution + {+(Identifier)+} + {+(Identifier)+})+} + {+(Empty)+} + {+(ScopeResolution{+(Identifier)+})+})+} +{+(Import + {+(Empty)+} + {+(Empty)+} + {+(ScopeResolution{+(Identifier)+})+})+} {-(Import {-(ScopeResolution {-(Identifier)-})-} @@ -35,4 +45,14 @@ {-(ImportSymbol {-(ScopeResolution {-(Identifier)-})-} - {-(Identifier)-})-})-}) + {-(Identifier)-})-})-} +{-(Import + {-(ScopeResolution + {-(Identifier)-} + {-(Identifier)-})-} + {-(Empty)-} + {-(ScopeResolution{-(Identifier)-})-})-} +{-(Import + {-(Empty)-} + {-(Empty)-} + {-(ScopeResolution{-(Identifier)-})-})-}) diff --git a/test/fixtures/python/import-from-statement.parseA.txt b/test/fixtures/python/import-from-statement.parseA.txt index 3186b2f0f..8f0636c06 100644 --- a/test/fixtures/python/import-from-statement.parseA.txt +++ b/test/fixtures/python/import-from-statement.parseA.txt @@ -17,4 +17,14 @@ (ScopeResolution (Identifier)) (Empty) - (Identifier))) + (Identifier)) + (Import + (ScopeResolution + (Identifier) + (Identifier)) + (Empty) + (ScopeResolution(Identifier))) + (Import + (Empty) + (Empty) + (ScopeResolution(Identifier)))) diff --git a/test/fixtures/python/import-from-statement.parseB.txt b/test/fixtures/python/import-from-statement.parseB.txt index 99f16dac5..5b7f9e302 100644 --- a/test/fixtures/python/import-from-statement.parseB.txt +++ b/test/fixtures/python/import-from-statement.parseB.txt @@ -29,4 +29,14 @@ (ImportSymbol (ScopeResolution (Identifier)) - (Identifier)))) + (Identifier))) + (Import + (ScopeResolution + (Identifier) + (Identifier)) + (Empty) + (ScopeResolution(Identifier))) + (Import + (Empty) + (Empty) + (ScopeResolution(Identifier)))) diff --git a/test/fixtures/python/import-statement.A.py b/test/fixtures/python/import-statement.A.py index 245079e6a..5fe8ae9c8 100644 --- a/test/fixtures/python/import-statement.A.py +++ b/test/fixtures/python/import-statement.A.py @@ -1,2 +1,3 @@ import a, b as c import b.c as d, e +import a.b.c diff --git a/test/fixtures/python/import-statement.B.py b/test/fixtures/python/import-statement.B.py index ea8595c83..149dc1f3f 100644 --- a/test/fixtures/python/import-statement.B.py +++ b/test/fixtures/python/import-statement.B.py @@ -1,2 +1,3 @@ import b, a import a.c as e +import b.c.d diff --git a/test/fixtures/python/import-statement.diffA-B.txt b/test/fixtures/python/import-statement.diffA-B.txt index df1661a5e..4b7c13a48 100644 --- a/test/fixtures/python/import-statement.diffA-B.txt +++ b/test/fixtures/python/import-statement.diffA-B.txt @@ -1,26 +1,16 @@ (Program - ( - {+(Import - {+(Identifier)+} - {+(Empty)+})+} - (Import - (Identifier) - (Empty)) - {-(Import - {-(ScopeResolution - {-(Identifier)-})-} - {-(Identifier)-})-}) +({+(Import + {+({+(Identifier)+})+} + {+(Empty)+})+}(Import((Identifier))(Empty)) + {-(Import{-(ScopeResolution{-(Identifier)-})-}{-(Identifier)-})-}) {+(Import - {+(ScopeResolution - {+(Identifier)+} + {+(ScopeResolution + {+(Identifier)+} + {+(Identifier)+})+} {+(Identifier)+})+} - {+(Identifier)+})+} -{-( - {-(Import - {-(ScopeResolution - {-(Identifier)-} - {-(Identifier)-})-} - {-(Identifier)-})-} - {-(Import - {-(Identifier)-} - {-(Empty)-})-})-}) +{+(Import + {+({+(Identifier)+}{+(Identifier)+}{+(Identifier)+})+} + {+(Empty)+})+} +{-({-(Import{-(ScopeResolution{-(Identifier)-}{-(Identifier)-})-}{-(Identifier)-})-} + {-(Import{-({-(Identifier)-})-}{-(Empty)-})-})-} +{-(Import{-({-(Identifier)-}{-(Identifier)-}{-(Identifier)-})-}{-(Empty)-})-}) \ No newline at end of file diff --git a/test/fixtures/python/import-statement.diffB-A.txt b/test/fixtures/python/import-statement.diffB-A.txt index 683af5940..f237a5fd8 100644 --- a/test/fixtures/python/import-statement.diffB-A.txt +++ b/test/fixtures/python/import-statement.diffB-A.txt @@ -1,26 +1,31 @@ (Program - ( + +( {-(Import - {-(Identifier)-} + {-({-(Identifier)-})-} {-(Empty)-})-} - (Import - (Identifier) - (Empty)) + (Import + ((Identifier)) + (Empty)) {+(Import - {+(ScopeResolution - {+(Identifier)+})+} - {+(Identifier)+})+}) -{+( - {+(Import - {+(ScopeResolution - {+(Identifier)+} - {+(Identifier)+})+} + {+(ScopeResolution{+(Identifier)+})+} {+(Identifier)+})+} - {+(Import +) +{+({+ +(Import + {+(ScopeResolution {+(Identifier)+} - {+(Empty)+})+})+} -{-(Import - {-(ScopeResolution + {+(Identifier)+})+} + {+(Identifier)+})+} +{+(Import + {+({+(Identifier)+})+} + {+(Empty)+})+})+} + +(Import + {(ScopeResolution {-(Identifier)-} - {-(Identifier)-})-} - {-(Identifier)-})-}) + {-(Identifier)-})->({+(Identifier)+}{+(Identifier)+}{+(Identifier)+})} + {(Identifier)->(Empty)}) +{-(Import + {-({-(Identifier)-}{-(Identifier)-}{-(Identifier)-})-} + {-(Empty)-})-}) diff --git a/test/fixtures/python/import-statement.parseA.txt b/test/fixtures/python/import-statement.parseA.txt index 7490af55b..b1f5bd8e0 100644 --- a/test/fixtures/python/import-statement.parseA.txt +++ b/test/fixtures/python/import-statement.parseA.txt @@ -1,7 +1,7 @@ (Program ( (Import - (Identifier) + ((Identifier)) (Empty)) (Import (ScopeResolution @@ -14,5 +14,6 @@ (Identifier)) (Identifier)) (Import - (Identifier) - (Empty)))) + ((Identifier)) + (Empty))) + (Import((Identifier)(Identifier)(Identifier))(Empty))) diff --git a/test/fixtures/python/import-statement.parseB.txt b/test/fixtures/python/import-statement.parseB.txt index 43136c81c..503acefea 100644 --- a/test/fixtures/python/import-statement.parseB.txt +++ b/test/fixtures/python/import-statement.parseB.txt @@ -1,13 +1,16 @@ (Program ( (Import - (Identifier) + ((Identifier)) (Empty)) (Import - (Identifier) + ((Identifier)) (Empty))) (Import (ScopeResolution (Identifier) (Identifier)) - (Identifier))) + (Identifier)) + (Import + ((Identifier) (Identifier) (Identifier)) + (Empty))) From 19ab77f434196f81aa9d52646014762da7ccec4d Mon Sep 17 00:00:00 2001 From: joshvera Date: Tue, 13 Feb 2018 20:28:31 -0500 Subject: [PATCH 3/3] Use expressions --- src/Language/Python/Assignment.hs | 2 +- test/fixtures/python/import-statement.diffA-B.txt | 6 +++--- test/fixtures/python/import-statement.diffB-A.txt | 6 +++--- test/fixtures/python/import-statement.parseA.txt | 4 ++-- test/fixtures/python/import-statement.parseB.txt | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index dc1d5f00c..cce3ada4c 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -379,7 +379,7 @@ import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliased wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source) aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> pure []) - plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> (makeTerm <$> location <*> manyTerm expression) <*> emptyTerm <*> pure []) + plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expressions <*> emptyTerm <*> pure []) assertStatement :: Assignment assertStatement = makeTerm <$> symbol AssertStatement <*> children (Expression.Call <$> pure [] <*> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier <$> source)) <*> manyTerm expression <*> emptyTerm) diff --git a/test/fixtures/python/import-statement.diffA-B.txt b/test/fixtures/python/import-statement.diffA-B.txt index 4b7c13a48..bbf2b10d4 100644 --- a/test/fixtures/python/import-statement.diffA-B.txt +++ b/test/fixtures/python/import-statement.diffA-B.txt @@ -1,7 +1,7 @@ (Program ({+(Import - {+({+(Identifier)+})+} - {+(Empty)+})+}(Import((Identifier))(Empty)) + {+(Identifier)+} + {+(Empty)+})+}(Import(Identifier)(Empty)) {-(Import{-(ScopeResolution{-(Identifier)-})-}{-(Identifier)-})-}) {+(Import {+(ScopeResolution @@ -12,5 +12,5 @@ {+({+(Identifier)+}{+(Identifier)+}{+(Identifier)+})+} {+(Empty)+})+} {-({-(Import{-(ScopeResolution{-(Identifier)-}{-(Identifier)-})-}{-(Identifier)-})-} - {-(Import{-({-(Identifier)-})-}{-(Empty)-})-})-} + {-(Import{-(Identifier)-}{-(Empty)-})-})-} {-(Import{-({-(Identifier)-}{-(Identifier)-}{-(Identifier)-})-}{-(Empty)-})-}) \ No newline at end of file diff --git a/test/fixtures/python/import-statement.diffB-A.txt b/test/fixtures/python/import-statement.diffB-A.txt index f237a5fd8..1db2dd601 100644 --- a/test/fixtures/python/import-statement.diffB-A.txt +++ b/test/fixtures/python/import-statement.diffB-A.txt @@ -2,10 +2,10 @@ ( {-(Import - {-({-(Identifier)-})-} + {-(Identifier)-} {-(Empty)-})-} (Import - ((Identifier)) + (Identifier) (Empty)) {+(Import {+(ScopeResolution{+(Identifier)+})+} @@ -18,7 +18,7 @@ {+(Identifier)+})+} {+(Identifier)+})+} {+(Import - {+({+(Identifier)+})+} + {+(Identifier)+} {+(Empty)+})+})+} (Import diff --git a/test/fixtures/python/import-statement.parseA.txt b/test/fixtures/python/import-statement.parseA.txt index b1f5bd8e0..79b264c35 100644 --- a/test/fixtures/python/import-statement.parseA.txt +++ b/test/fixtures/python/import-statement.parseA.txt @@ -1,7 +1,7 @@ (Program ( (Import - ((Identifier)) + (Identifier) (Empty)) (Import (ScopeResolution @@ -14,6 +14,6 @@ (Identifier)) (Identifier)) (Import - ((Identifier)) + (Identifier) (Empty))) (Import((Identifier)(Identifier)(Identifier))(Empty))) diff --git a/test/fixtures/python/import-statement.parseB.txt b/test/fixtures/python/import-statement.parseB.txt index 503acefea..ee15c5754 100644 --- a/test/fixtures/python/import-statement.parseB.txt +++ b/test/fixtures/python/import-statement.parseB.txt @@ -1,10 +1,10 @@ (Program ( (Import - ((Identifier)) + (Identifier) (Empty)) (Import - ((Identifier)) + (Identifier) (Empty))) (Import (ScopeResolution