Skip to content

Commit

Permalink
[CSS] Improve language constant interpolation support (#3943)
Browse files Browse the repository at this point in the history
This commit adds interpolation support to

a) unquoted font family names
b) langaage ranges
c) unquoted urls
  • Loading branch information
deathaxe authored Mar 15, 2024
1 parent 6730d5e commit 851fc57
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
23 changes: 19 additions & 4 deletions CSS/CSS.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ variables:
illegal_custom_ident_tokens: |-
(?xi: auto | default | inherit | initial | none | unset )
# Constants
lang_range_begin: (?={{ident_start}}|\*)
unquoted_url_begin: (?={{ident_start}}|/)

# Types
# https://www.w3.org/TR/css3-values/#numeric-types
# https://www.w3.org/TR/css-syntax-3/#number-token-diagram
Expand Down Expand Up @@ -3215,13 +3219,24 @@ contexts:
# Font Family Names
# https://drafts.csswg.org/css-fonts-3/#family-name-value
font-family-names:
- match: '{{ident}}(?:\s+{{ident}}(?!\())*'
scope: meta.string.css string.unquoted.css
- match: '{{ident_begin}}'
push: font-family-name-body

font-family-name-body:
- meta_include_prototype: false
- meta_scope: meta.string.css string.unquoted.css
# allow unquoted space separated font names
- match: (?!\s+{{ident_start}}){{break}}
pop: 1
# function call ahead, skip font name
- match: (?=\s+{{ident}}\()
pop: 1
- match: '{{unicode}}'

# Language Ranges
# https://drafts.csswg.org/selectors-4/#language-range
language-ranges:
- match: (?={{nmstart}}|\*)
- match: '{{lang_range_begin}}'
push: language-range-content

language-range-content:
Expand Down Expand Up @@ -3350,7 +3365,7 @@ contexts:
# Unquoted URL token
# https://drafts.csswg.org/css-syntax-3/#consume-a-url-token
unquoted-urls:
- match: (?=[[:alnum:]/])
- match: '{{unquoted_url_begin}}'
push: unquoted-url-body

unquoted-url-body:
Expand Down
7 changes: 7 additions & 0 deletions CSS/syntax_test_css.css
Original file line number Diff line number Diff line change
Expand Up @@ -2967,6 +2967,13 @@
font: sans serif;
/* ^^^^^^^^^^ meta.string.css string.unquoted.css */

font: san\73 -\73 erif;
/* ^^^^^^^^^^^^^^^^ meta.string.css string.unquoted.css */

font: sans serif var(--name);
/* ^^^^^^^^^^ meta.string.css string.unquoted.css */
/* ^^^^^^^^^^^ meta.function-call */

font: inherit;
/* ^^^^^^^ support - string */

Expand Down

0 comments on commit 851fc57

Please sign in to comment.