Skip to content

Commit bb3dd08

Browse files
committed
fix: fix hashes in a string becoming a comment
1 parent 7649c6c commit bb3dd08

5 files changed

Lines changed: 538589 additions & 534295 deletions

File tree

grammar.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,16 @@ module.exports = grammar({
900900

901901
option: (_) => /[@A-Za-z-_\d]+/,
902902

903-
hash_escape: (_) => token.immediate(prec(1, /#([#,}]|[\dA-Fa-f]{6})/)),
903+
hash_escape: (_) => token.immediate(prec(1, /#[#,}]/)),
904904
_hash: (_) => token.immediate(prec(1, /#[^#,{}"'HhDPTSFIW]/)),
905+
hash_rgb: (_) => token.immediate(prec(1, /#[\dA-Fa-f]{6}/)),
906+
_hash_rules: ($) =>
907+
choice(
908+
$.hash_escape,
909+
$._hash,
910+
$.hash_rgb,
911+
token.immediate(prec(1, /#[\dA-Fa-f]{1,5}/)),
912+
),
905913
backslash_escape: (_) => BACKSLASH_ESCAPE,
906914
backslash_escape_immediate: (_) => token.immediate(BACKSLASH_ESCAPE),
907915
_expr_variable_name: (_) => /@?[a-z-_\d]+/,
@@ -911,7 +919,7 @@ module.exports = grammar({
911919
operator: (_) => /==|!=|<|>|<=|>=|\|\||&&/,
912920
attribute: (_) => /[a-z-]+/,
913921
_str_single_quotes_inner: ($) =>
914-
choice($.expr_single_quotes, $.hash_escape, $._hash, /([^#'])+/),
922+
choice($.expr_single_quotes, $._hash_rules, /([^#'])+/),
915923
str_single_quotes: ($) =>
916924
seq(
917925
"'",
@@ -924,8 +932,7 @@ module.exports = grammar({
924932
choice(
925933
$.expr_double_quotes,
926934
$.backslash_escape,
927-
$.hash_escape,
928-
$._hash,
935+
$._hash_rules,
929936
/([^#"\\]|\\\r?\n)+/,
930937
),
931938
str_double_quotes: ($) => seq('"', repeat($._str_double_quotes_inner), '"'),
@@ -1010,8 +1017,7 @@ function exprRule($, quote) {
10101017
repeat(
10111018
choice(
10121019
expr,
1013-
$.hash_escape,
1014-
$._hash,
1020+
$._hash_rules,
10151021
token.immediate(
10161022
prec(1, quote == '"' ? /[^,}"#]+/ : /[^,}'#]+/),
10171023
),
@@ -1032,8 +1038,7 @@ function exprRule($, quote) {
10321038
"=",
10331039
choice(
10341040
expr,
1035-
$.hash_escape,
1036-
$._hash,
1041+
$._hash_rules,
10371042
token.immediate(
10381043
prec(1, quote == '"' ? /[^,\]"#]+/ : /[^,\]'#]+/),
10391044
),

0 commit comments

Comments
 (0)