Re: [csswg-drafts] [css-nesting] Problem with mixing properties and selectors (#8249)

@tabatkins and I disagree that splitting style rule and declaration parsing on non-ident start over-restricts the future of CSS declaration syntax. But to understand why, we need to consider:

* CSS declaration syntax has been extremely stable for almost three decades. Unlike Selectors, it isn't an area where we do lots of interesting syntactic things.
* What's closed off for future extension isn't everything we pipe through the selector path today. It's everything that's invalid today.

We're not just reserving everything that has an ident start for declarations: we're reserving everything that results in an invalid sequence, whether that sequence is parsed in as invalid style declarations or invalid style rules or a mix of both.

Remember the parsing rules being proposed for mixed context are a little different:
* if we triggered a declaration parse, we swallow up to the next semicolon
* if we triggered a style rule parse, we swallow up to the next {}-block _or semicolon_, whichever comes first

The following sequences are all **complete** invalid constructs: they are thrown away and anything after them starts a new parse. Which means we can interpret them however we want in the future.

```
@foo anything except semicolon { anything }
random stuff: other stuff { anything } anything;
random(stuff): other stuff;
!other stuff: more stuff;
++extra stuff: stuff;
(anything): anything;
```

The only thing we're closing off entirely is a new construct that maps to the following sequence:
1. a sequence that starts with a symbol (and thus triggers style rule parse)
2. a {}-block (which thus ends the style rule parse)
3. a sequence that is currently a valid style rule or valid property declaration (which then gets read in as valid by current browsers)

Basically, we can't introduce new things like:

```
#stuff starting with a symbol { anything in this block } valid-property: value;
/* new thing all parsed as one declaration */
```

which doesn't seem very likely for us to add in the first place.

So as long as we're not planning to introduce a new type of property declaration that maps to that, we can introduce any new declaration syntax additions we want in the future. Though for the sake of preserving LALR parsing, we'll want any symbol start to be something that is not currently valid as a selector start token.

And on the flip side, we're closing off selectors that start with functional notation (`function(...)`). That's it.

I think this is plenty of open space for innovation.

-- 
GitHub Notification of comment by fantasai
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8249#issuecomment-1362033982 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 21 December 2022 20:07:39 UTC