Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an empty declaration appear after the last semi-colon if that semi-colon is followed by a closing brace?

Tags:

css

Let's look at this CSS rule:

#foo { color: red; }

As you can see, the declaration block of the above rule contains one declaration, namely color: red. However, according to my interpretation of the CSS standard, the above declaration block also contains a second, empty declaration, which is located between the chars ; and }.

#foo { color: red; }
                  ^ --- an empty declaration is located here

I'm asking this question on Stack Overflow to determine if my interpretation is correct, i.e. if there indeed exists a second, empty declaration in the above CSS rule.

Btw, I'm using the CSS 2.1 standard, specifically "Chapter 4: Syntax", since the "CSS Syntax" module is outdated, and not safe to use.

OK, let me explain. I base my interpretation on these definitions:

  • The standard states that, within a declaration block, a semi-colon is a separator which appears between individual declarations:

    A declaration block starts with a left curly brace ({) and ends with the matching right curly brace (}). In between there must be a list of zero or more semicolon-separated (;) declarations.

    So, according to the above definition, a semi-colon my only appear between two declarations, i.e. a semi-colon must be both preceded, and followed by a declaration.

  • The standard defines a declaration as:

    A declaration is either empty or consists of a property name, followed by a colon (:), followed by a property value.

    The above definition states that a declaration can be empty. Unfortunately, the standard does not define the term "empty declaration", nor is that term mentioned anywhere else in the standard.

Let's go back to the example:

#foo { color: red; }

The above rule is valid CSS. By applying the definition for semi-colons (from above), the semi-colon in this rule must both be preceded, and followed by a declaration. However, the semi-colon is followed by the closing curly brace (which ends the declaration). In order to explain this contradiction, I insert an empty declaration between ; and }, and provide this definition:

An empty declaration is the absence of a declaration in a position within a declaration block where a declaration i required, but not found.

Is this interpretation of the standard correct, and does the declaration block indeed contain two declarations?

like image 201
Šime Vidas Avatar asked Dec 07 '12 20:12

Šime Vidas


1 Answers

Yes, this is normal in computer languages that define the semicolon as a separator and not part of a statement (or declaration or whatever). There is no other possible interpretation, and the issue has no practical impact, as an empty declaration has no effect.

like image 129
Jukka K. Korpela Avatar answered Sep 22 '22 15:09

Jukka K. Korpela