Skip to content

Commit 0dd6543

Browse files
committed
Merge pull request #1069 from mgreter/feature/restore-token-on-fail
Improve `lex_css` to restore old token on non-match
2 parents 72bebed + 8330a1a commit 0dd6543

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

parser.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,17 @@ namespace Sass {
165165
template <prelexer mx>
166166
const char* lex_css()
167167
{
168+
// copy old token
169+
Token prev = lexed;
168170
// throw away comments
169171
// update srcmap position
170172
lex < css_comments >();
171-
// now lex a token
172-
return lex< mx >();
173+
// now lex a new token
174+
const char* pos = lex< mx >();
175+
// maybe restore prev token
176+
if (pos == 0) lexed = prev;
177+
// return match
178+
return pos;
173179
}
174180

175181
// all block comments will be skipped and thrown away

0 commit comments

Comments
 (0)