Skip to content

Commit 28ee088

Browse files
committed
Merge pull request #1198 from mgreter/bugfix/issue_442
Fix interpolation edge case in value parsing
2 parents 928260d + e00aec6 commit 28ee088

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

parser.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,13 @@ namespace Sass {
423423
string name(Util::normalize_underscores(lexed));
424424
ParserState var_source_position = pstate;
425425
if (!lex< exactly<':'> >()) error("expected ':' after " + name + " in assignment statement", pstate);
426-
Expression* val = parse_list();
426+
Expression* val;
427+
Selector_Lookahead lookahead = lookahead_for_value(position);
428+
if (lookahead.has_interpolants && lookahead.found) {
429+
val = parse_value_schema(lookahead.found);
430+
} else {
431+
val = parse_list();
432+
}
427433
val->is_delayed(false);
428434
bool is_default = false;
429435
bool is_global = false;
@@ -1568,12 +1574,18 @@ namespace Sass {
15681574
else if (lex< hex >()) {
15691575
(*schema) << new (ctx.mem) Textual(pstate, Textual::HEX, unquote(lexed));
15701576
}
1577+
else if (lex < exactly < '-' > >()) {
1578+
(*schema) << new (ctx.mem) String_Constant(pstate, lexed);
1579+
}
15711580
else if (lex< quoted_string >()) {
15721581
(*schema) << new (ctx.mem) String_Quoted(pstate, lexed);
15731582
}
15741583
else if (lex< variable >()) {
15751584
(*schema) << new (ctx.mem) Variable(pstate, Util::normalize_underscores(lexed));
15761585
}
1586+
else if (peek< parenthese_scope >()) {
1587+
(*schema) << parse_factor();
1588+
}
15771589
else {
15781590
error("error parsing interpolated value", pstate);
15791591
}
@@ -2175,23 +2187,24 @@ namespace Sass {
21752187
(q = peek< percentage >(p)) ||
21762188
(q = peek< dimension >(p)) ||
21772189
(q = peek< quoted_string >(p)) ||
2178-
(q = peek< variable >(p)) ||
2190+
(q = peek< variable >(p)) ||
21792191
(q = peek< exactly<'*'> >(p)) ||
21802192
(q = peek< exactly<'+'> >(p)) ||
21812193
(q = peek< exactly<'~'> >(p)) ||
21822194
(q = peek< exactly<'>'> >(p)) ||
21832195
(q = peek< exactly<','> >(p)) ||
2196+
(q = peek< sequence<parenthese_scope, interpolant>>(p)) ||
21842197
(saw_stuff && (q = peek< exactly<'-'> >(p))) ||
21852198
(q = peek< binomial >(p)) ||
21862199
(q = peek< block_comment >(p)) ||
21872200
(q = peek< sequence< optional<sign>,
21882201
zero_plus<digit>,
21892202
exactly<'n'> > >(p)) ||
21902203
(q = peek< sequence< optional<sign>,
2191-
one_plus<digit> > >(p)) ||
2204+
one_plus<digit> > >(p)) ||
21922205
(q = peek< number >(p)) ||
21932206
(q = peek< sequence< exactly<'&'>,
2194-
identifier_alnums > >(p)) ||
2207+
identifier_alnums > >(p)) ||
21952208
(q = peek< exactly<'&'> >(p)) ||
21962209
(q = peek< exactly<'%'> >(p)) ||
21972210
(q = peek< sequence< exactly<'.'>, interpolant > >(p)) ||

prelexer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,5 +769,16 @@ namespace Sass {
769769
alternatives< exactly<';'>, exactly<'}'> >
770770
>(src);
771771
}
772+
773+
const char* parenthese_scope(const char* src) {
774+
return sequence <
775+
exactly < '(' >,
776+
skip_over_scopes <
777+
exactly < '(' >,
778+
exactly < ')' >
779+
>
780+
>(src);
781+
}
782+
772783
}
773784
}

prelexer.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace Sass {
8686

8787
// find another opener inside?
8888
else if (const char* pos = start(src)) {
89-
++ level; // increase stack counter
89+
++ level; // increase counter
9090
src = pos - 1; // advance position
9191
}
9292

@@ -108,6 +108,10 @@ namespace Sass {
108108
return 0;
109109
}
110110

111+
// skip to a skip delimited by parentheses
112+
// uses smart `skip_over_scopes` internally
113+
const char* parenthese_scope(const char* src);
114+
111115
// skip to delimiter (mx) inside given range
112116
// this will savely skip over all quoted strings
113117
// recursive skip stuff delimited by start/stop

0 commit comments

Comments
 (0)