Skip to content

Commit 8494a88

Browse files
committed
Improve parser to leave significant white-space in place
1 parent 6d5b6b2 commit 8494a88

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/parser.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ namespace Sass {
691691

692692
while (peek_css< exactly<','> >())
693693
{
694-
lex< spaces >();
695-
lex< css_comments >();
694+
lex< css_comments >(false);
696695
// consume everything up and including the comma speparator
697696
reloop = lex< exactly<','> >() != 0;
698697
// remember line break (also between some commas)
@@ -847,7 +846,7 @@ namespace Sass {
847846

848847
Simple_Selector* Parser::parse_simple_selector()
849848
{
850-
lex < css_comments >();
849+
lex < css_comments >(false);
851850
if (lex< alternatives < id_name, class_name > >()) {
852851
return SASS_MEMORY_NEW(ctx.mem, Selector_Qualifier, pstate, lexed);
853852
}
@@ -1000,7 +999,7 @@ namespace Sass {
1000999
bool is_indented = true;
10011000
const std::string property(lexed);
10021001
if (!lex_css< one_plus< exactly<':'> > >()) error("property \"" + property + "\" must be followed by a ':'", pstate);
1003-
lex < optional_css_comments >();
1002+
lex < css_comments >(false);
10041003
if (peek_css< exactly<';'> >()) error("style declaration must contain a value", pstate);
10051004
if (peek_css< exactly<'{'> >()) is_indented = false; // don't indent if value is empty
10061005
if (peek_css< static_value >()) {
@@ -1024,7 +1023,7 @@ namespace Sass {
10241023
}
10251024
}
10261025
}
1027-
1026+
lex < css_comments >(false);
10281027
auto decl = SASS_MEMORY_NEW(ctx.mem, Declaration, prop->pstate(), prop, value/*, lex<kwd_important>()*/);
10291028
decl->is_indented(is_indented);
10301029
return decl;
@@ -1332,6 +1331,7 @@ namespace Sass {
13321331
// called from parse_value_schema
13331332
Expression* Parser::parse_factor()
13341333
{
1334+
lex < css_comments >(false);
13351335
if (lex_css< exactly<'('> >()) {
13361336
// parse_map may return a list
13371337
Expression* value = parse_map();
@@ -1399,7 +1399,7 @@ namespace Sass {
13991399
// parse one value for a list
14001400
Expression* Parser::parse_value()
14011401
{
1402-
lex< css_comments >();
1402+
lex< css_comments >(false);
14031403
if (lex< ampersand >())
14041404
{
14051405
return SASS_MEMORY_NEW(ctx.mem, Parent_Selector, pstate); }
@@ -2099,15 +2099,15 @@ namespace Sass {
20992099
at_rule->selector(parse_selector_list());
21002100
}
21012101

2102-
lex < css_comments >();
2102+
lex < css_comments >(false);
21032103

21042104
if (lex < static_property >()) {
21052105
at_rule->value(parse_interpolated_chunk(Token(lexed)));
21062106
} else if (!(peek < alternatives < exactly<'{'>, exactly<'}'>, exactly<';'> > >())) {
21072107
at_rule->value(parse_list());
21082108
}
21092109

2110-
lex < css_comments >();
2110+
lex < css_comments >(false);
21112111

21122112
if (peek< exactly<'{'> >()) {
21132113
at_rule->block(parse_block());

src/parser.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,18 @@ namespace Sass {
166166
{
167167
// copy old token
168168
Token prev = lexed;
169+
// store previous pointer
170+
const char* oldpos = position;
169171
// throw away comments
170172
// update srcmap position
171173
lex < Prelexer::css_comments >();
172174
// now lex a new token
173175
const char* pos = lex< mx >();
174-
// maybe restore prev token
175-
if (pos == 0) lexed = prev;
176+
// maybe restore prev state
177+
if (pos == 0) {
178+
lexed = prev;
179+
position = oldpos;
180+
}
176181
// return match
177182
return pos;
178183
}

0 commit comments

Comments
 (0)