Skip to content

Commit

Permalink
Fix #96 SCSS parser failure (S2260): parser does not support identifi…
Browse files Browse the repository at this point in the history
…ers starting with '-#'
  • Loading branch information
racodond committed Mar 29, 2018
1 parent 8f4f498 commit 3b5038d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ public enum LexicalGrammar implements GrammarRuleKey {
SCSS_MULTILINE_STRING,
SCSS_MULTILINE_STRING_LITERAL,

SCSS_IDENT,

/* Less */
LESS_VARIABLE_DECLARATION,
LESS_VARIABLE_DECLARATION_AS_PARAMETER,
Expand Down Expand Up @@ -623,10 +625,17 @@ private static void scss(LexerlessGrammarBuilder b) {
b.rule(SCSS_AT_ROOT_WITH).is(SPACING, b.token(GenericTokenType.LITERAL, "with"));
b.rule(SCSS_AT_ROOT_WITHOUT).is(SPACING, b.token(GenericTokenType.LITERAL, "without"));

b.rule(SCSS_IDENT).is(
b.firstOf(
b.regexp("(?i)(progid:DXImageTransform\\.Microsoft\\.[a-z]+)"),
b.sequence(_NMSTART, b.zeroOrMore(_NMCHAR)),
b.oneOrMore(_NMCHAR)))
.skip();

b.rule(SCSS_IDENT_INTERPOLATED_IDENTIFIER_NO_WS).is(
b.token(GenericTokenType.LITERAL,
b.sequence(
b.optional(IDENT_IDENTIFIER_NO_WS),
b.optional(SCSS_IDENT),
b.regexp("#\\{[^\\n\\r\\f\\}]*\\}"),
b.zeroOrMore(
b.firstOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void classSelector() {
checkParsed(".abc#{$class}", "abc#{$class}", true);
checkParsed(".abc#{$class}#{$class1}def", "abc#{$class}#{$class1}def", true);
checkParsed(".abc#{$class}e#{$class1}def", "abc#{$class}e#{$class1}def", true);
checkParsed(".-abc#{$class}e#{$class1}def", "-abc#{$class}e#{$class1}def", true);
checkParsed(".--abc#{$class}e#{$class1}def", "--abc#{$class}e#{$class1}def", true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public IdSelectorTreeTest() {
public void idSelector() {
checkParsed("#id", "id", false);
checkParsed("#id#{$abc}-def", "id#{$abc}-def", true);
checkParsed("#-id#{$abc}-def", "-id#{$abc}-def", true);
checkParsed("#--id#{$abc}-def", "--id#{$abc}-def", true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void scssInterpolatedIdentifierNoWS() {
checkParsed("abc#{$class}");
checkParsed("abc#{$class}#{$class1}def");
checkParsed("-moz-abc#{$class}e#{$class1}def");
checkParsed("--abc#{$class}e#{$class1}def");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void scssInterpolatedIdentifier() {
checkParsed(" -moz-abc#{ $abc * 2 + 3}e#{$class1}def", "-moz-abc#{ $abc * 2 + 3}e#{$class1}def");
checkParsed("#{ 2 * 3 + 5 + $abc}", "#{ 2 * 3 + 5 + $abc}");
checkParsed("abc#{ 2 * 3 + 5 + $abc}def", "abc#{ 2 * 3 + 5 + $abc}def");
checkParsed("-abc#{ 2 * 3 + 5 + $abc}def", "-abc#{ 2 * 3 + 5 + $abc}def");
checkParsed("--abc#{ 2 * 3 + 5 + $abc}def", "--abc#{ 2 * 3 + 5 + $abc}def");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public void scssMixin() {
assertThat(tree.block().propertyDeclarations()).hasSize(2);
assertThat(tree.block().rulesets()).hasSize(2);
assertThat(tree.block().scssMixinIncludes()).hasSize(2);

checkParsed("@mixin view-mixin($key) { &-#{$key}-view { color: red; } }");
}

@Test
Expand Down

0 comments on commit 3b5038d

Please sign in to comment.