allow comments on any line, don't require '.' for blank lines #471

Closed
bos opened this Issue May 24, 2012 · 6 comments

Comments

Projects
None yet
3 participants
Contributor

bos commented May 24, 2012

(Imported from Trac #478, reported by @dcoutts on 2009-01-24)

It confuses people that in .cabal files, comments can only appear on lines on their own, and not at the end of other lines.

We should consider relaxing this as long as it can be done in a backwards compatible way.

The only thing to worry about is command line flags like:

  cc-options: --some-flag
If we required a space after the -- that might be sufficient. There are some tools that interpret -- on its own as an argument, but usually only as a separator between flag arguments and non-flag arguments and we do not expect those to be given in .cabal files.

We might like to allow -- within quotes eg "--" however that's also not easy because of the syntax and format of .cabal files. They have no consistent lexical syntax, each field is parsed separately. The overall structure is parsed based on layout without parsing individual fields. In particular .cabal files are not tokenised.

The second issue is easier. The original specification required that blank lines within a field include a leading . character. This applies to multi-paragraph descriptions. This syntax is totally unnecessary. The parser could cope fine without it. We should accept the convention for backwards compatibility but also allow ordinary blank lines. Multiple blank lines within a field should still be collapsed to one, and trailing blank lines within a field should be trimmed.

Contributor

bos commented May 24, 2012

(Imported comment by guest on 2009-01-24)

The second issue is easier. The original specification required that blank lines within a field include a leading . character. This applies to multi-paragraph descriptions. This syntax is totally unnecessary. The parser could cope fine without it. We should accept the convention for backwards compatibility but also allow ordinary blank lines. Multiple blank lines within a field should still be collapsed to one, and trailing blank lines within a field should be trimmed.

Major +1. The '.' syntax is a leading annoyance of the description field syntax for me.

Contributor

bos commented May 24, 2012

(Imported comment by @creswick on 2009-01-24)

The error output for this could at least mention that comments aren't allowed at the end of lines.

There is also an inconsistency in the syntax for build-depends and some other lists (eg: extra-source-files). Comments at the end of a line in an extra-source-files list do not cause a parse error, yet they do when added to the end of a line in a build-depends list.

In my opinion, the simplest solution is to require that -- be escaped. (eg: --, or -- ) when it is not used as a comment delimiter. However, I say that without having any experience with the cabal source, so I can't judge the difficulty. I'm also a newbie to haskell, so perhaps this isn't such a great idea...

I'd be willing to start working on such a fix if someone with more background than I can suggest one :)

Contributor

bos commented May 24, 2012

(Imported comment by @dcoutts on 2009-12-19)

Replying to @creswick:

The error output for this could at least mention that comments aren't allowed at the end of lines.

This is tricky because we do not know they are there.

There is also an inconsistency in the syntax for build-depends and some other lists (eg: extra-source-files). Comments at the end of a line in an extra-source-files list do not cause a parse error, yet they do when added to the end of a line in a build-depends list.

It's not actually inconsistent. Remember that "-- blah" in a field is considered as part of the field. So for build-depends, that does not parse, but it's perfectly ok to have a source file called "--" and "blah". Of course it will fail when trying to sdist because the files do not exist.

In my opinion, the simplest solution is to require that -- be escaped. (eg: \-\-, or \-- ) when it is not used as a comment delimiter.

That's fairly ugly and will not reduce confusion because people will not know that they can or should use that syntax.

As I mention in the original description, I think the thing to do is to consider whether allowing "-- " as the start of a comment could possibly cause problems in fields like ghc-options, since "--" is a valid value to pass to a program.

Contributor

bos commented May 24, 2012

(Imported comment by @creswick on 2009-12-19)

Replying to @dcoutts:

Replying to @creswick:
The error output for this could at least mention that comments aren't allowed at the end of lines.

This is tricky because we do not know they are there.

ah.. that's too bad. I take it the parser would need to be substantially augmented to include the reason for the parse failure? (If we could get the offset into the cabal file that caused the parse error, then some post-processing might help infer the error output.)
There is also an inconsistency in the syntax for build-depends and some other lists (eg: extra-source-files). Comments at the end of a line in an extra-source-files list do not cause a parse error, yet they do when added to the end of a line in a build-depends list.

It's not actually inconsistent. Remember that "-- blah" in a field is considered as part of the field. So for build-depends, that does not parse, but it's perfectly ok to have a source file called "--" and "blah". Of course it will fail when trying to sdist because the files do not exist.

Right... I guess I was conflating something different that struck me as inconsistent: build-depends seems to be comma-delimited, while extra-source-files (and others) look to be white-space delimited. I haven't dug into the source to look at the grammar yet though, so I may well be wrong here too. Anyway, that's out of scope for this ticket...
In my opinion, the simplest solution is to require that -- be escaped. (eg: \-\-, or \-- ) when it is not used as a comment delimiter.

That's fairly ugly and will not reduce confusion because people will not know that they can or should use that syntax.

I agree that it's ugly, but the current situation is also not clear.
As I mention in the original description, I think the thing to do is to consider whether allowing "-- " as the start of a comment could possibly cause problems in fields like ghc-options, since "--" is a valid value to pass to a program.

gcc accepts some options that start with "--" so there is a conflict in at least some situations. The first to come to mind is cpp-options, and as you mentioned, files could contain "--" or even "-- " as well.

Since "--" is pretty commonly used to pass arguments to an underlying system, I think it's safe to assume that this will eventually become a problem.

What about supporting additional comment syntaxes, such as haskell's block comments, or the traditional '#'? (I'm not enamored by this idea either, by the way, but thought I'd toss it out there.)

Contributor

bos commented May 24, 2012

(Imported comment by @dcoutts on 2009-12-20)

Replying to @creswick:

ah.. that's too bad. I take it the parser would need to be substantially augmented to include the reason for the parse failure?

Right. The parser we use for field contents gives us precisely no error information. Sadly we cannot have Cabal depend on packages like parsec so we're stuck with a useless parser for the moment.

(If we could get the offset into the cabal file that caused the parse error, then some post-processing might help infer the error output.)

We only know where the field starts, not where the error is detected.

Right... I guess I was conflating something different that struck me as inconsistent: build-depends seems to be comma-delimited, while extra-source-files (and others) look to be white-space delimited. I haven't dug into the source to look at the grammar yet though, so I may well be wrong here too. Anyway, that's out of scope for this ticket...

That's quite true. That is inconsistent and I don't see an immediate reason for it. We should be able to allow space or commas in both.

gcc accepts some options that start with "--" so there *is* a conflict in at least some situations. The first to come to mind is cpp-options, and as you mentioned, files could contain "--" or even "-- " as well.

Right, though I guess if -- needs to be passed then Cabal should do it automatically.

Since "--" is pretty commonly used to pass arguments to an underlying system, I think it's safe to assume that this will eventually become a problem.

Maybe, maybe not. Cabal doesn't provide a great deal of control over where flags go and -- makes all subsequent flags be interpreted as args.

What about supporting additional comment syntaxes, such as haskell's block comments, or the traditional '#'? (I'm not enamored by this idea either, by the way, but thought I'd toss it out there.)

I agree, there's not an obvious nice solution.

As I see it, the problem is the confusion, not the inability to put comments on the same lines as fields. Once you realise it's not possible, it's not really a major restriction. So I don't see the need to add extra syntax to allow comments on the same line. That doesn't address the problem of people accidentally using -- comments.

Perhaps if we decide that the ability to specify -- in the options fields is needed then we can tell people to use "--" instead.

jsl commented Feb 24, 2015

Given that there is no activity since 2009, I propose closing. Please re-open or create a new issue if this feature is still desired.

/cc @tibbe

@tibbe tibbe closed this Feb 24, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment