Re: CDO and CDC in CSS1

Russell Steven Shawn O'Connor writes:
 > 
 > According to the grammer in Appendix B, the following is illegal:
 > 
 > H1 <!-- { color: blue }
 > 
 > because CDO isn't allowd at that point.  Although Appendix B doesn't say
 > thid, I'd assume that the parser really supposed to throw out the CDO and
 > CDC tokens.  In that case the example given is legal (weird but legal). 
 > Perhaps this is an example of why the UA shouldn't use this grammer
 > directly.  Or perhaps I'm confusing a grammer for an author to use vs the
 > grammer an UA should use.

That is part of the issue, but the "<!--" thing has a history of its
own:

1. Of course, it shouldn't be in CSS in the first place, but to keep
old browsers from displaying embedded style sheets, a rather dirty
trick was employed: declare the STYLE element to have CDATA content,
which means that SGML-compliant parsers and newer browsers will see
the "<!--" simply as four characters, and not as a comment. Older
browsers, that don't know that STYLE has CDATA content, will assume
that "<!--" is a comment and thus skip to the next "-->". (The same
trick was subsequently employed to hide SCRIPT from old browsers,
although there it became even uglier, with the script comment in turn
having to hide the SGML comment...)

2. This means that the content of the STYLE element includes "<!--" at
the start and "-->" at the end, so, in order to not get into the same
mess as with SCRIPT, these strings needed to be legal in the CSS
syntax.

3. Next it was felt that many people (and programs!) would copy and
concatenate style sheets from one document to another, and also to
external style sheets, without being too careful about removing the
"<!--". So the syntax was made a bit more forgiving, allowing "<!--"
and "-->" in places where they were likely to end up as a result of
these copying operations.

More than that wasn't felt necessary. People that copy and paste have
to know what they are doing anyway, and allowing these strings to
appear in more places might occasionally save somebody from a syntax
error, but changes are high that there is something else wrong as well
then.

So the message these tokens are supposed to give is: yes, it is OK to
take the complete contents of two STYLE elements, and concatenate
them, without having to strip off the make-believe comment
markers. But at the same time, these markers are not things you can
stick anywhere you like, to decorate, obfuscate, or whatever purpose
you have in mind.

 > What would be the correct way for a UA to handle the above example?

That is a different matter, and it is well defined in CSS: the above
line starts out as a selector, but half way through there is a token
that cannot legally occur there. So the UA is then required to forget
about the selector, skip ahead to the next balanced '}', and start
parsing again after that.

And back to author versus UA: the grammar in appendix B indeed defines
the syntax that CSS2 authors should use. (Tries to, anyway, since
there are many semantic restrictions that are expressed in English in
the text and cannot be shown in the grammar.)

There are additional rules, like the one given above, about what a
parser should do with certain non-grammatical constructs. From that
you could deduce the language that a UA *actually* accepts, which is a
much larger language than the one defined by the grammar (and which,
we hope, includes all the future levels of CSS). Of course, all the
additional constructs are to be ignored, but ignored in a certain
well-defined, predictable way. (See chapter 4 for the syntax of "all
future CSS levels".)




Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos/                              W3C/INRIA
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 93 65 76 92            06902 Sophia Antipolis Cedex, France
  +33 (0)4 92 38 76 92 (<--- after 5 Jan 1998)

Received on Thursday, 19 February 1998 17:02:37 UTC