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

Conversation

@kanghyojun
Copy link
Member

commented Apr 12, 2018

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

However, it needs more test cases for merge.

@kanghyojun

This comment has been minimized.

Copy link
Member Author

commented Apr 12, 2018

It is releated with #219

@checkmate-bot

This comment has been minimized.

Copy link

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.

@kanghyojun kanghyojun force-pushed the kanghyojun:import-aliasing branch from afd38bf to a69542e Apr 13, 2018

@codecov

This comment has been minimized.

Copy link

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.

@kanghyojun kanghyojun force-pushed the kanghyojun:import-aliasing branch from a69542e to 6b824da Apr 19, 2018

@kanghyojun kanghyojun requested a review from dahlia Apr 25, 2018

@kanghyojun kanghyojun self-assigned this Apr 25, 2018

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

This comment has been minimized.

Copy link
@dahlia

dahlia Apr 25, 2018

Member

Please add a space right after --.

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

This comment has been minimized.

Copy link
@dahlia

dahlia Apr 25, 2018

Member

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)

This comment has been minimized.

Copy link
@dahlia

dahlia Apr 25, 2018

Member

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

@kanghyojun kanghyojun force-pushed the kanghyojun:import-aliasing branch 3 times, most recently from 1e581a8 to 77b5274 Apr 25, 2018

@kanghyojun kanghyojun force-pushed the kanghyojun:import-aliasing branch from 77b5274 to 25da998 Apr 25, 2018

, (["zzz"], ["qqq", "ppp"])
imports mod1 `shouldBe` [ (["foo", "bar"], [ ("baz", "baz")
, ("qux", "qux")
])

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
@dahlia
, (["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)

This comment has been minimized.

Copy link
@dahlia
] Nothing)
]

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

This comment has been minimized.

Copy link
@dahlia
, 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)

This comment has been minimized.

Copy link
@dahlia
, 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)

This comment has been minimized.

Copy link
@dahlia
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 ]

This comment has been minimized.

Copy link
@dahlia
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 ]

This comment has been minimized.

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

This comment has been minimized.

Copy link
@dahlia

@kanghyojun kanghyojun force-pushed the kanghyojun:import-aliasing branch from 25da998 to 1a7da15 Apr 25, 2018

@dahlia
Copy link
Member

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)

@kanghyojun kanghyojun force-pushed the kanghyojun:import-aliasing branch from 1a7da15 to 6be588a Apr 30, 2018

@dahlia
dahlia approved these changes Apr 30, 2018

@kanghyojun kanghyojun merged commit 4fb4391 into nirum-lang:master Apr 30, 2018

4 checks passed

codecov/patch 95.31% of diff hit (target 75.84%)
Details
codecov/project 76.16% (+0.31%) compared to dc13fd9
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@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
3 participants
You can’t perform that action at this time.