atom / language-css

CSS package for Atom
Other
59 stars 77 forks source link

Implement naming conventions in CSS grammar #167

Open chbk opened 4 years ago

chbk commented 4 years ago

Description of the Change

This is a rewrite of the Tree-sitter grammar to implement naming conventions for syntax scopes.

Currently, Atom uses the TextMate grammar because the Tree-sitter grammar is lacking. This PR thoroughly updates the Tree-sitter grammar to be fully functional.

Benefits

Possible Drawbacks

The changes aim to facilitate theme development, filling the template is enough to ensure coherent highlighting across languages, instead of painfully creating styling rules for every language separately.

Regex grammar scopes vs homogenized Tree-sitter grammar scopes:

Applicable Issues

Related Pull Requests

chbk commented 4 years ago

Preview of the changes between the current TextMate grammar and this PR's Tree-sitter grammar, with Atom's default syntax themes:

Without naming conventions
(current TextMate grammar)
With naming conventions in
theme and Tree-sitter grammar
Solarized Dark
solarized-dark-css-0
Solarized Dark
solarized-dark-css-1
One Dark
one-dark-css-0
One Dark
one-dark-css-1
Base16 Tomorrow Dark
base16-dark-css-0
Base16 Tomorrow Dark
base16-dark-css-1
Atom Dark
atom-dark-css-0
Atom Dark
atom-dark-css-1
Solarized Light
solarized-light-css-0
Solarized Light
solarized-light-css-1
One Light
one-light-css-0
One Light
one-light-css-1
Base16 Tomorrow Light
base16-light-css-0
Base16 Tomorrow Light
base16-light-css-1
Atom Light
atom-light-css-0
Atom Light
atom-light-css-1

Code snippet:

@import url("p.css") print;
@import 't.css' tv, tty;

@media screen,
(orientation: portrait),
(invalid: 0) and (top: 4) {
  body + pre::after {
    content: 'fruit';
    --bandana: #488cff;
  }
}

@supports
(top: 4)
or (invalid: 0)
or (orientation: portrait) {
  div > p::first-letter {
     color: #FE742F;
     font-weight: (bold);
     height: initial;
  }
}

@keyframes ninja {
  to {
    top: (2000cm);
  }
}

:root, *,
h1 > wall ~ select,
.table:not(wall):not(div),
#id:not(.wall),
#wall a[href*="karate"],
dash[type~=swift],
slash[data-melon=5],
#url::before,
.nth:nth-child(4) {
  color: var(--bandana);
  top: 30em !important;
  display: flex;
  invalid: invalid;
  filter: invalid(20%);
  border: 1px solid gray;
  border: 3.1hz solid what;
  /* Firefox */
  transform: scaleY(-1);
}
cssinate commented 3 years ago

This looks like a valiant project. I like the idea. I haven't created themes before, so please enlighten me: if this gets accepted, won't themes break?

chbk commented 3 years ago

Default themes have been updated already so they'll work fine with this PR. For other community themes, it depends on what the merging strategy is:

The TextMate documentation doesn't provide many useful scopes for CSS, so the scopes I listed above seem to have emerged from some sort of genetic process, selecting what works with existing themes. It's blatant with support.type.property-name for example, which is not a type at all, or entity.other.attribute-name.id which is not an attribute name. This is what makes creating a theme so difficult, the inconsistencies require you to check what works with each language individually.