w3c / w3c/csswg-drafts

[Meta] Modular/distributed grammar definitions

Open
#6,744 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

css-values-5 meta
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

There are a lot of cases where a certain value type / token consists of a disjunction of potential tokens, each defined in a separate section of the spec. However, there are still sections with "main" grammar definitions, that need to be updated every time new tokens are added or removed.

E.g.: Images:

<image> = <url> | <image()> | <image-set()> | <cross-fade()> | <element()> | <gradient>

Color 4:

<color> = <absolute-color-base> | currentcolor | <system-color> | <device-cmyk()>

<absolute-color-base> = <hex-color> | <named-color> | transparent |
    <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> |
    <lab()> | <lch()> |
	<oklab()> | <oklch()> |
    <color()>

Color 5:

<color-space> = srgb | hsl | hwb | xyz | lab | lch | oklab | oklch

This is a maintenance overhead for editors, and makes it more likely for these definitions to get out of sync as tokens are added or removed (case in point: I just added oklab() and oklch() to the <color> grammar because they had not been added there too).

It should be possible to define a subtype entirely by adding a section, without also having to update centralized grammars. This also makes it possible to extend types in separate specs or levels.

Perhaps in addition to =, we could define a |= operator for grammars that means "whatever this token can be from the rest of the spec(s), plus these tokens". E.g., right now, adding OKLab and OKLCH needed edits not just to add their section but also to extend <color> and in Color 5, to extend <color-space>.

If |= existed, the entirety of the grammar changes that these introduce could be self-contained in their section:

<absolute-color-base> |= <oklab()> | <oklch()>
<color-space> |= oklab | oklch

oklab() = oklab( [<percentage> | none] [<number> | none] [<number> | none] [ / [<alpha-value> | none] ]? )
oklch() = oklch( [<percentage> | none] [<number> | none] [<hue> | none] [ / [<alpha-value> | none] ]? )

One could make the point that these summary grammars are useful (though not sure how useful they can be if out of sync). However, Bikeshed could generate them, similarly to how we generated indices, and that way they are guaranteed to be in sync.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining how Bikeshed represents grammar definitions and how its index-generation machinery produces summaries. Define what |= should mean across sections and specifications, then verify that distributed additions remain synchronized with any generated summary grammars.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
documentation, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.