Skip to content

Added aliased import#258

Merged
kanghyojun merged 16 commits intonirum-lang:masterfrom
kanghyojun:import-aliasing
Apr 30, 2018
Merged

Added aliased import#258
kanghyojun merged 16 commits intonirum-lang:masterfrom
kanghyojun:import-aliasing

Conversation

@kanghyojun
Copy link
Member

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

However, it needs more test cases for merge.

@kanghyojun
Copy link
Member Author

It is releated with #219

@checkmate-bot
Copy link

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.

@codecov
Copy link

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.

@kanghyojun kanghyojun requested a review from dahlia April 25, 2018 11:49
@kanghyojun kanghyojun self-assigned this Apr 25, 2018
@kanghyojun kanghyojun added typ:enhance Type: Enhancement/new feature cmp:compiler Component: Compiler backend (e.g., annotation processors, code generators) target:python dfct:hard Difficulty: Hard labels Apr 25, 2018
, Import ["baz"] "qux" empty
] Nothing
, Module
[ Import ["foo", "bar"] "xyz" "xyz" empty --MissingModulePathError
Copy link
Member

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 --.

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

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)

Copy link
Member

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.

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

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

Choose a reason for hiding this comment

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

👀

Copy link
Member

@dahlia dahlia left a comment

Choose a reason for hiding this comment

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

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 merged commit 4fb4391 into nirum-lang:master Apr 30, 2018
@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

Labels

cmp:compiler Component: Compiler backend (e.g., annotation processors, code generators) dfct:hard Difficulty: Hard target:python typ:enhance Type: Enhancement/new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants