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

Line trailing comments not stripped #2681

Closed
phadej opened this issue Jun 25, 2015 · 8 comments
Closed

Line trailing comments not stripped #2681

phadej opened this issue Jun 25, 2015 · 8 comments
Assignees
Milestone

Comments

@phadej
Copy link
Collaborator

phadej commented Jun 25, 2015

issue with accelerate-cuda 0.14.0.0 file: https://gist.github.com/phadej/641d82190cdd0400fc28

Original:

Extra-tmp-files:        config.status
                        config.log
                        autom4te.cache
                        accelerate-cuda.buildinfo               -- generated by configure

Formatted:

extra-tmp-files:
    config.status
    config.log
    autom4te.cache
    accelerate-cuda.buildinfo
    --
    generated
    by
    configure

I'm not sure if the issue is in the parser or prettyprinter


related to: #2460 #2607

@phadej
Copy link
Collaborator Author

phadej commented Jun 25, 2015

Test case in phadej@836d414

@BardurArantsson
Copy link
Collaborator

This issue desperately needs a description of what the actual problem is, i.e. what did you do and what did you expect to happen? What did happen?

@23Skidoo
Copy link
Member

23Skidoo commented Jun 25, 2015

This issue desperately needs a description of what the actual problem is, i.e. what did you do and what did you expect to happen?

He took accelerate-cuda-0.14.0.0.cabal and ran it through cabal format. See #2607 (comment).

@BardurArantsson
Copy link
Collaborator

Yes, I can see that, but this is still not a useful issue description if a reader of the issue has to trawl through comments in a different issue/PR to figure out what's going on. (Esp. since the PR is still open.)

EDIT: grammer

@lspitzner
Copy link
Collaborator

@BardurArantsson without any deeper knowledge about the subject, here is my guess what is meant:

-- generated by configure is a comment. it is not kept intact by a parse/pretty-print round-trip.

the expected behaviour is that
a) the output contains the complete comment -- generated by configure
b) most importantly: there are not three new extra-temp-files, namely "generated" "by" and "configure"

@BardurArantsson
Copy link
Collaborator

Ok, that's a more useful description. It shouldn't be necessary to guess, however since it would take all of 5 minutes for the reporter to write that :).

( @phadej : I promise, I'm not trying to single you out specifically (... at length). I'm just making the point that for issue descriptions to be useful they must be understandable by people who aren't involved in the original issues, etc. IOW understandable on their own. You just happened to provide an example. :))

@phadej phadej changed the title cabal format outputs comments? Line trailing comments not stripped Jun 26, 2015
@phadej
Copy link
Collaborator Author

phadej commented Jun 26, 2015

I investigated this further. The problem is in the parser, it doesn't strip -- trailing line comments.
For example cabal file with

license: BSD3 -- or should we have GPL?

will fail to parse, which is ok.

But list fields (like extra-source-files) will be parsed so comment as treated as real content:

extra-src-files: README.md -- foobar

into

extraSrcFiles = ["README.md","--","foobar"],

There is trimLines in Cabal.Distribution.ParseUtils which strips whole line comments, but it cannot be extended as context is important. Eg. we would like to have

cc-options: --my-special-compiler-option

Hacky soluton A:

I could make abit hacky solution to strip WS+ DASH DASH WS+ (not DOUBLEQUOTE)* from the end of the lines in trimLines.


Real solution B: would be to take @dcoutts parsec parser into use, but it is blocked by ghc-the-library dependency on Cabal. I could help with decoupling, if there are some pointers.

@phadej
Copy link
Collaborator Author

phadej commented Aug 15, 2017

Update. This is by design. The frame syntax of .cabal like files doesn't accept end-of-line comments.

I'm not sure how to proceed. Some warning would be useful. Maybe warn about, --files, and suggest using "--files" in some fields (files, and modules, build-depends?)

ping @hvr

@phadej phadej self-assigned this Dec 16, 2017
@phadej phadej added this to the 2.2 milestone Dec 16, 2017
phadej added a commit to phadej/cabal that referenced this issue Dec 24, 2017
Resolves haskell#2681

Cabal files don't have trailing line comments. In many fields they
simply cause parse errors, but e.g. in extra-source-files
virtually everything is accepted. As there is simple
work around if people actually want double-dash, let's warn
about bare one.
phadej added a commit to phadej/cabal that referenced this issue Dec 24, 2017
Resolves haskell#2681

Cabal files don't have trailing line comments. In many fields they
simply cause parse errors, but e.g. in extra-source-files
virtually everything is accepted. As there is simple
work around if people actually want double-dash, let's warn
about bare one.
phadej added a commit to phadej/cabal that referenced this issue Dec 25, 2017
Resolves haskell#2681

Cabal files don't have trailing line comments. In many fields they
simply cause parse errors, but e.g. in extra-source-files
virtually everything is accepted. As there is simple
work around if people actually want double-dash, let's warn
about bare one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants