Skip to content

Commit

Permalink
Fix unquoted strings/urls beginning with scss interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Mar 8, 2024
1 parent dbce79f commit eb25ac9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
25 changes: 24 additions & 1 deletion Syntaxes/SCSS.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ variables:
selector_end: (?=[;{}])

tag_name_begin: (?=[[:alpha:]]|#{)
unquoted_url_begin: (?=[[:alnum:]/]|#{)

# SCSS variables

Expand Down Expand Up @@ -260,6 +261,20 @@ contexts:

###[ CSS STRINGS ]#############################################################

font-family-names:
# replace CSS context to add interpolation support
- match: '{{ident_begin}}'
push: font-family-name-body

font-family-name-body:
- meta_include_prototype: false
- meta_scope: meta.string.css string.unquoted.css
- include: scss-string-interpolations
- match: '{{break}}(?!\s+{{ident_start}})'
pop: 1
# consume unicode escapes and possibly following whitespace
- match: '{{unicode}}'

string-content:
- meta_prepend: true
- include: scss-string-interpolations
Expand All @@ -281,6 +296,15 @@ contexts:
- include: comments
- include: else-pop

unquoted-urls:
# replace CSS context to add interpolation support
- match: '{{unquoted_url_begin}}'
push: unquoted-url-body

unquoted-url-body:
- meta_prepend: true
- include: scss-string-interpolations

###[ SassDoc COMMENTS ]########################################################

sassdoc-comments:
Expand Down Expand Up @@ -780,7 +804,6 @@ contexts:
- include: important-operators
- include: scss-declarations
- include: scss-constants
- include: scss-interpolations
- include: scss-variables
- include: scss-operators
- include: scss-variadics
Expand Down
30 changes: 27 additions & 3 deletions Tests/syntax_test_scss.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@
src: url($roboto-font-path + "/Roboto-Light.woff2") format("woff2");

// This is parsed as an interpolated special function.
/* TODO: unsure how this should be handled, */
src: url(#{$roboto-font-path}/Roboto-Regular.woff2) format("woff2");
// ^^^^^^^^^^^^^^^^^^^^ meta.interpolation.scss
// ^ -meta.interpolation.scss
// ^^^ meta.function-call.identifier.css
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.css meta.group.css
// ^^^^^^^^^^^^^^^^^^^^ meta.string.css meta.interpolation.scss
// ^^^^^^^^^^^^^^^^^^^^^ meta.string.css string.unquoted.css - meta.interpolation.scss
// ^^^^^^^^^^^^^^^^^ variable.other.scss
// ^ punctuation.definition.variable.scss
}
Expand Down Expand Up @@ -188,6 +189,29 @@
// ^ punctuation.section.interpolation.begin.scss
// ^^^^^^^^^ variable.other.scss
// ^ punctuation.section.interpolation.end.scss

$color: "red";

color: #{$color};
//^^^^^ meta.property-name.css support.type.property-name.css
// ^ punctuation.separator.key-value.css
// ^ meta.property-value.css - meta.interpolation
// ^^^^^^^^^ meta.property-value.css support.constant.property-value.css meta.interpolation.scss

$font_name: "Roboto";

font-family: #{$font_name + "Mono"};
//^^^^^^^^^^^ meta.property-name.css support.type.property-name.css
// ^ punctuation.separator.key-value.css
// ^ meta.property-value.css - meta.interpolation
// ^^^^^^^^^^^^^^^^^^^^^^ meta.property-value.css meta.string.css meta.interpolation.scss

font-family: My#{$font_name};
//^^^^^^^^^^^ meta.property-name.css support.type.property-name.css
// ^ punctuation.separator.key-value.css
// ^ meta.property-value.css - meta.string - meta.interpolation
// ^^ meta.property-value.css meta.string.css string.unquoted.css
// ^^^^^^^^^^^^^ meta.property-value.css meta.string.css meta.interpolation.scss
}

.gray {
Expand Down

0 comments on commit eb25ac9

Please sign in to comment.