Avi-D-coder / implicit-hie

Auto generate a stack or cabal multi component hie.yaml file
BSD 3-Clause "New" or "Revised" License
201 stars 17 forks source link

Confusing parsing behaviour when a list is the last thing in the .cabal file #34

Open xal-0 opened 3 years ago

xal-0 commented 3 years ago

I ran into some rather confusing behaviour when I used gen-hie with a cabal file that ended with an other-modules list. I loaded Hie.Cabal.Parser into GHCi to confirm this.

Test cabal file (to be parsed with/without a final newline):

name: foo
executable bar
  main-is: Main.hs
  other-modules: Hello
               , World

This file seems to miss World both with/without the final newline.

λ> parsePackage' "name: foo\nexecutable bar\n  main-is: Main.hs\n  other-modules: Hello\n               , World"
Right (Package "foo" [Comp Exe "bar" "./Main.hs",Comp Exe "bar" "./Hello.hs"])

λ> parsePackage' "name: foo\nexecutable bar\n  main-is: Main.hs\n  other-modules: Hello\n               , World\n"
Right (Package "foo" [Comp Exe "bar" "./Main.hs",Comp Exe "bar" "./Hello.hs"])

Test cabal file (to be parsed with/without a final newline):

name: foo
executable bar
  main-is: Main.hs
  other-modules: Hello,
                 World

This file is parsed different with/without a final newline:

λ> parsePackage' "name: foo\nexecutable bar\n  main-is: Main.hs\n  other-modules: Hello,\n                 World"
Right (Package "foo" [Comp Exe "bar" "./Main.hs"])

λ> parsePackage' "name: foo\nexecutable bar\n  main-is: Main.hs\n  other-modules: Hello,\n                 World\n"
Right (Package "foo" [Comp Exe "bar" "./Main.hs",Comp Exe "bar" "./Hello.hs",Comp Exe "bar" "./World.hs"])