David J.
David J.

Reputation: 32715

RFC 2068 allows comments nested within comments?

According to: RFC 2068:

Comments can be included in some HTTP header fields by surrounding the comment text with parentheses. Comments are only allowed in fields containing "comment" as part of their field value definition. In all other fields, parentheses are considered part of the field value.

These are the relevant rules:

comment        = "(" *( ctext | comment ) ")"
ctext          = <any TEXT excluding "(" and ")">

Comments inside of comments? This seems silly. My claims are: (1) There is no need for comments nested inside comments. (2) If so, the comment rule would be better expressed as:

comment        = "(" *( ctext ) ")"

Are my claims correct? If not, when are nested comments actually used? Do other libraries care? Is there any history / commentary on this that you know about? (Trying a Web search with "RFC 2068 nested comments" isn't very helpful.)

(Motivation: I care because I'm writing a lexer (with Ragel) for RFC 2068. If comments really need to be nestable, that means recursive rules, which, as I understand it, are not Ragel's sweet spot. I've read some indications that Ragel can handle recursive rules in some cases, but I'm not quite clear on that. Also, I'm looking at the Unicorn Ragel code as well, which is helpful.)

P.S. For simplicity, I'm intentionally not diving into the details of another rule, quoted-string, now.

Update 2012-08-20 : One answer below helpfully cites a newer version of RFC 2068. This is helpful in that it clarifies the parsing rule. However, it doesn't address my other points:

  1. I don't see any convincing rationale for the spec to include comments within comments. It just seems unnecessary -- perhaps over-engineered, perhaps overlooked. This is both annoying and significant because recursive rules make the format a non-regular language. This is something spec writers probably normally should guard against, right?

  2. I have not (yet?) seen examples of in the wild that use comments within comments. If this is the case, the world has implicitly said "nested comments don't matter much."

Upvotes: 0

Views: 191

Answers (1)

paulsm4
paulsm4

Reputation: 121759

Look at RFC2616:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html

Comments can be included in some HTTP header fields by surrounding the comment
text with parentheses. Comments are only allowed in fields containing "comment" 
as part of their field value definition. In all other fields, parentheses are 
considered part of the field value.

       comment        = "(" *( ctext | quoted-pair | comment ) ")"
       ctext          = <any TEXT excluding "(" and ")">

So yes, nested comments are explicitly allowed :)

Upvotes: 1

Related Questions