Skip to content

Commit 4f0be36

Browse files
committed
Fix comment parsing
1 parent 1b2a2ce commit 4f0be36

File tree

7 files changed

+35
-16
lines changed

7 files changed

+35
-16
lines changed

src/parser.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace Sass {
6363
return true;
6464
}
6565
else if (next == $asterisk) {
66-
loudComment();
66+
scanLoudComment();
6767
return true;
6868
}
6969
else {
@@ -82,14 +82,11 @@ namespace Sass {
8282
}
8383

8484
// Consumes and ignores a loud (CSS-style) comment.
85-
void Parser::loudComment()
85+
void Parser::scanLoudComment()
8686
{
8787
scanner.expect("/*");
8888
while (true) {
8989
auto next = scanner.readChar();
90-
if (isNewline(next)) {
91-
scanner._fail("*/");
92-
}
9390
if (next != $asterisk) continue;
9491

9592
do {
@@ -275,7 +272,7 @@ namespace Sass {
275272

276273
case $slash:
277274
if (scanner.peekChar(1) == $asterisk) {
278-
buffer.write(rawText(&Parser::loudComment));
275+
buffer.write(rawText(&Parser::scanLoudComment));
279276
}
280277
else {
281278
buffer.write(scanner.readChar());

src/parser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace Sass {
9191
virtual SilentComment* readSilentComment();
9292

9393
// Consumes and ignores a loud (CSS-style) comment.
94-
void loudComment();
94+
virtual void scanLoudComment();
9595

9696
// Consumes a plain CSS identifier. If [unit] is `true`, this
9797
// doesn't parse a `-` followed by a digit. This ensures that

src/parser_sass.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ namespace Sass {
2424
return buffer.getInterpolation(scanner.rawSpanFrom(start));
2525
}
2626

27+
// Consumes and ignores a loud (CSS-style) comment.
28+
// This overrides loud comment consumption so that
29+
// it doesn't consume multi-line comments.
30+
void SassParser::scanLoudComment()
31+
{
32+
scanner.expect("/*");
33+
while (true) {
34+
auto next = scanner.readChar();
35+
if (isNewline(next)) {
36+
scanner._fail("*/");
37+
}
38+
if (next != $asterisk) continue;
39+
40+
do {
41+
next = scanner.readChar();
42+
} while (next == $asterisk);
43+
if (next == $slash) break;
44+
}
45+
}
46+
2747
void SassParser::expectStatementSeparator(sass::string name) {
2848
if (!atEndOfStatement()) expectNewline();
2949
if (peekIndentation() <= currentIndentation) return;
@@ -182,7 +202,7 @@ namespace Sass {
182202
return lastSilentComment.ptr();
183203
break;
184204
case $asterisk:
185-
return loudComment();
205+
return readLoudComment();
186206
break;
187207
default:
188208
return (this->*child)();
@@ -243,7 +263,7 @@ namespace Sass {
243263
return lastSilentComment;
244264
}
245265

246-
LoudComment* SassParser::loudComment()
266+
LoudComment* SassParser::readLoudComment()
247267
{
248268
Offset start(scanner.offset);
249269
scanner.expect("/*");

src/parser_sass.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ namespace Sass {
114114
// Consumes an indented-style loud context.
115115
// This overrides loud comment consumption so
116116
// that it doesn't consume multi-line comments.
117-
LoudComment* loudComment();
117+
LoudComment* readLoudComment();
118+
119+
void scanLoudComment() override final;
118120

119121
void scanWhitespaceWithoutComments() override final;
120122

src/parser_scss.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace Sass {
109109
scanWhitespaceWithoutComments();
110110
break;
111111
case $asterisk:
112-
children.emplace_back(loudComment());
112+
children.emplace_back(readLoudComment());
113113
scanWhitespaceWithoutComments();
114114
break;
115115
default:
@@ -155,7 +155,7 @@ namespace Sass {
155155
scanWhitespaceWithoutComments();
156156
break;
157157
case $asterisk:
158-
statements.emplace_back(loudComment());
158+
statements.emplace_back(readLoudComment());
159159
scanWhitespaceWithoutComments();
160160
break;
161161
default:
@@ -205,7 +205,7 @@ namespace Sass {
205205
// EO readSilentComment
206206

207207
// Consumes a statement-level loud comment block.
208-
LoudComment* ScssParser::loudComment()
208+
LoudComment* ScssParser::readLoudComment()
209209
{
210210
InterpolationBuffer buffer(scanner);
211211
Offset start(scanner.offset);

src/parser_scss.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace Sass {
8181
virtual SilentComment* readSilentComment() override;
8282

8383
// Consumes a statement-level loud comment block.
84-
virtual LoudComment* loudComment();
84+
virtual LoudComment* readLoudComment();
8585

8686
/////////////////////////////////////////////////////////////////////////
8787
/////////////////////////////////////////////////////////////////////////

src/parser_stylesheet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ namespace Sass {
540540
}
541541

542542
isUseAllowed = false;
543-
if (scanner.matches("/*")) nameBuffer.write(rawText(&StylesheetParser::loudComment));
543+
if (scanner.matches("/*")) nameBuffer.write(rawText(&StylesheetParser::scanLoudComment));
544544

545545
StringBuffer midBuffer;
546546
midBuffer.write(rawText(&StylesheetParser::scanWhitespace));
@@ -4713,7 +4713,7 @@ namespace Sass {
47134713

47144714
case $slash:
47154715
if (scanner.peekChar(1) == $asterisk) {
4716-
buffer.write(rawText(&StylesheetParser::loudComment));
4716+
buffer.write(rawText(&StylesheetParser::scanLoudComment));
47174717
}
47184718
else {
47194719
buffer.write(scanner.readChar());

0 commit comments

Comments
 (0)