Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added aliased import #258

Merged
merged 16 commits into from Apr 30, 2018
Merged

Added aliased import #258

merged 16 commits into from Apr 30, 2018

Conversation

@kanghyojun
Copy link
Member

@kanghyojun kanghyojun commented Apr 12, 2018

It's handy to avoid a name shadowing. It resolve #217.

However, it needs more test cases for merge.

@kanghyojun
Copy link
Member Author

@kanghyojun kanghyojun commented Apr 12, 2018

It is releated with #219

Loading

@checkmate-bot
Copy link

@checkmate-bot checkmate-bot commented Apr 12, 2018

Checklist 🤔

src/Nirum/Parser.hs

  • If a new reserved keyword is introduced, it has to be also added to reservedKeywords set in the Nirum.Constructs.Identifier module.

Loading

@codecov
Copy link

@codecov codecov bot commented Apr 13, 2018

Codecov Report

Merging #258 into master will increase coverage by 0.31%.
The diff coverage is 95.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #258      +/-   ##
==========================================
+ Coverage   75.84%   76.16%   +0.31%     
==========================================
  Files          33       33              
  Lines        2414     2446      +32     
  Branches      132      132              
==========================================
+ Hits         1831     1863      +32     
  Misses        451      451              
  Partials      132      132
Impacted Files Coverage Δ
src/Nirum/Targets/Python/Validators.hs 83.13% <ø> (ø) ⬆️
src/Nirum/Targets/Python/TypeExpression.hs 93.1% <100%> (+0.12%) ⬆️
src/Nirum/Parser.hs 87.34% <100%> (+0.48%) ⬆️
src/Nirum/TypeInstance/BoundModule.hs 68.96% <100%> (+2.29%) ⬆️
src/Nirum/Package/ModuleSet.hs 93.61% <100%> (ø) ⬆️
src/Nirum/Constructs/Module.hs 70% <100%> (+4.09%) ⬆️
src/Nirum/Constructs/Identifier.hs 96.29% <100%> (+0.06%) ⬆️
src/Nirum/Targets/Python/Serializers.hs 79.48% <50%> (+2.56%) ⬆️
src/Nirum/Constructs/TypeDeclaration.hs 77.77% <90%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5630d29...6be588a. Read the comment docs.

Loading

, Import ["baz"] "qux" empty
] Nothing
, Module
[ Import ["foo", "bar"] "xyz" "xyz" empty --MissingModulePathError
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a space right after --.

Loading

return [Import path ident aSet | (ident, aSet) <- idents]
return [ Import path source imp aSet
| (imp, source, aSet) <- idents
]
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have tests for all combinations of the following conditions:

Empty parentheses Single import name w/o trailing comma Single import name w/ trailing comma Multiple import names w/o trailing comma Multiple import names w/ trailing comma
With as import foo () import foo (x as a) import foo (x as a,) import foo (x as a, y as b, c) import foo (x as a, y as b, c,)
Without as import foo() import foo (a) import foo(a, b, c,) import foo (a,) import foo(a, b, c)

Loading

Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test if the parser disallows and shows an error when there are duplicated alias names.

Loading

@kanghyojun kanghyojun force-pushed the import-aliasing branch 3 times, most recently from 1e581a8 to 77b5274 Apr 25, 2018
, (["zzz"], ["qqq", "ppp"])
imports mod1 `shouldBe` [ (["foo", "bar"], [ ("baz", "baz")
, ("qux", "qux")
])
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

, (["xyz"], [("asdf", "asdf")])
, (["zzz"], [ ("qqq", "qqq")
, ("ppp", "ppp")
])
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

Nothing -> toType
coreModulePath
identifier
(DS.lookup identifier $ types coreModule)
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

, (["qux"], Module [ Import ["foo"] "abc" empty -- MissingImportError
, Import ["foo"] "def" empty -- MissingImportError
, (["qux"], Module [ Import ["foo"] "abc" "abc" empty -- MissingImportError
, Import ["foo"] "def" "def" empty -- MissingImportError
] Nothing)
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

] Nothing)
]

circularImportsModules :: [(ModulePath, Module)]
circularImportsModules =
[ (["asdf"], Module [ Import ["asdf"] "foo" empty
[ (["asdf"], Module [ Import ["asdf"] "foo" "foo" empty
, TypeDeclaration "bar" (Alias "text") empty
] Nothing)
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

, TypeDeclaration "bar" (Alias "text") empty
] Nothing)
, (["abc", "def"], Module [ Import ["abc", "ghi"] "bar" empty
, (["abc", "def"], Module [ Import ["abc", "ghi"] "bar" "bar" empty
, TypeDeclaration
"foo" (Alias "text") empty
] Nothing)
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

, TypeDeclaration
"bar" (Alias "text") empty
] Nothing)
, (["abc", "xyz"], Module [ Import ["abc", "def"] "foo" empty
, (["abc", "xyz"], Module [ Import ["abc", "def"] "foo" "foo" empty
, TypeDeclaration
"baz" (Alias "text") empty
] Nothing)
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

let (parse', expectError) = helperFuncs $ P.imports []
it "can single import name w/o trailing comma" $ do
parse' "import foo.bar (a);" `shouldBeRight`
[ Import ["foo", "bar"] "a" "a" empty ]
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

parse' "import foo.bar (a,);" `shouldBeRight`
[ Import ["foo", "bar"] "a" "a" empty ]
parse' "import foo.bar (a as qux,);" `shouldBeRight`
[ Import ["foo", "bar"] "qux" "a" empty ]
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

<?> "names to import"
idents <- many' [] $ \ importNames' -> do
notFollowedBy $ choice [char ')', char ',' >> spaces >> char ')']
let forwardNames' = [ i | (i, _, _) <- importNames' ] ++
Copy link
Member

@dahlia dahlia Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Loading

Copy link
Member

@dahlia dahlia left a comment

Build is failing due to lint:

test/Nirum/TypeInstance/BoundModuleSpec.hs:56:1: too long line (83 chars)
test/Nirum/ParserSpec.hs:1180:1: too long line (81 chars)
test/Nirum/ParserSpec.hs:1185:1: too long line (81 chars)
test/Nirum/ParserSpec.hs:1206:1: too long line (82 chars)
test/Nirum/ParserSpec.hs:1215:1: too long line (83 chars)
test/Nirum/ParserSpec.hs:1255:1: too long line (91 chars)

Loading

dahlia
dahlia approved these changes Apr 30, 2018
@kanghyojun kanghyojun merged commit 4fb4391 into nirum-lang:master Apr 30, 2018
4 checks passed
Loading
@dahlia dahlia added this to the Version 0.4.0 milestone May 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants