Skip to content

Commit

Permalink
Merge pull request sass#1198 from mgreter/bugfix/issue_442
Browse files Browse the repository at this point in the history
Fix interpolation edge case in value parsing
  • Loading branch information
mgreter committed May 12, 2015
2 parents 928260d + e00aec6 commit 28ee088
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
21 changes: 17 additions & 4 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,13 @@ namespace Sass {
string name(Util::normalize_underscores(lexed));
ParserState var_source_position = pstate;
if (!lex< exactly<':'> >()) error("expected ':' after " + name + " in assignment statement", pstate);
Expression* val = parse_list();
Expression* val;
Selector_Lookahead lookahead = lookahead_for_value(position);
if (lookahead.has_interpolants && lookahead.found) {
val = parse_value_schema(lookahead.found);
} else {
val = parse_list();
}
val->is_delayed(false);
bool is_default = false;
bool is_global = false;
Expand Down Expand Up @@ -1568,12 +1574,18 @@ namespace Sass {
else if (lex< hex >()) {
(*schema) << new (ctx.mem) Textual(pstate, Textual::HEX, unquote(lexed));
}
else if (lex < exactly < '-' > >()) {
(*schema) << new (ctx.mem) String_Constant(pstate, lexed);
}
else if (lex< quoted_string >()) {
(*schema) << new (ctx.mem) String_Quoted(pstate, lexed);
}
else if (lex< variable >()) {
(*schema) << new (ctx.mem) Variable(pstate, Util::normalize_underscores(lexed));
}
else if (peek< parenthese_scope >()) {
(*schema) << parse_factor();
}
else {
error("error parsing interpolated value", pstate);
}
Expand Down Expand Up @@ -2175,23 +2187,24 @@ namespace Sass {
(q = peek< percentage >(p)) ||
(q = peek< dimension >(p)) ||
(q = peek< quoted_string >(p)) ||
(q = peek< variable >(p)) ||
(q = peek< variable >(p)) ||
(q = peek< exactly<'*'> >(p)) ||
(q = peek< exactly<'+'> >(p)) ||
(q = peek< exactly<'~'> >(p)) ||
(q = peek< exactly<'>'> >(p)) ||
(q = peek< exactly<','> >(p)) ||
(q = peek< sequence<parenthese_scope, interpolant>>(p)) ||
(saw_stuff && (q = peek< exactly<'-'> >(p))) ||
(q = peek< binomial >(p)) ||
(q = peek< block_comment >(p)) ||
(q = peek< sequence< optional<sign>,
zero_plus<digit>,
exactly<'n'> > >(p)) ||
(q = peek< sequence< optional<sign>,
one_plus<digit> > >(p)) ||
one_plus<digit> > >(p)) ||
(q = peek< number >(p)) ||
(q = peek< sequence< exactly<'&'>,
identifier_alnums > >(p)) ||
identifier_alnums > >(p)) ||
(q = peek< exactly<'&'> >(p)) ||
(q = peek< exactly<'%'> >(p)) ||
(q = peek< sequence< exactly<'.'>, interpolant > >(p)) ||
Expand Down
11 changes: 11 additions & 0 deletions prelexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,5 +769,16 @@ namespace Sass {
alternatives< exactly<';'>, exactly<'}'> >
>(src);
}

const char* parenthese_scope(const char* src) {
return sequence <
exactly < '(' >,
skip_over_scopes <
exactly < '(' >,
exactly < ')' >
>
>(src);
}

}
}
6 changes: 5 additions & 1 deletion prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace Sass {

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

Expand All @@ -108,6 +108,10 @@ namespace Sass {
return 0;
}

// skip to a skip delimited by parentheses
// uses smart `skip_over_scopes` internally
const char* parenthese_scope(const char* src);

// skip to delimiter (mx) inside given range
// this will savely skip over all quoted strings
// recursive skip stuff delimited by start/stop
Expand Down

0 comments on commit 28ee088

Please sign in to comment.