Skip to content

Commit

Permalink
Fix interpolation edge case in value parsing
Browse files Browse the repository at this point in the history
Fixes sass#442
  • Loading branch information
mgreter committed May 11, 2015
1 parent fb82f0b commit fa720a7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
21 changes: 17 additions & 4 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,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 @@ -1564,12 +1570,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 @@ -2171,23 +2183,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 @@ -729,5 +729,16 @@ namespace Sass {
alternatives< exactly<';'>, exactly<'}'> >
>(src);
}

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

}
}
15 changes: 14 additions & 1 deletion prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Sass {
// recursive skip stuff delimited by start/stop
// first start/opener must be consumed already!
template<prelexer start, prelexer stop>
const char* skip_over_scopes(const char* src, const char* end = 0) {
const char* skip_over_scopes(const char* src, const char* end) {

size_t level = 0;
bool in_squote = false;
Expand Down Expand Up @@ -105,6 +105,19 @@ 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
// first start/opener must be consumed already!
template<prelexer start, prelexer stop>
const char* skip_over_scopes(const char* src) {
return skip_over_scopes<start, stop>(src, 0);
}

// Match a sequence of characters delimited by the supplied chars.
template <prelexer start, prelexer stop>
const char* recursive_scopes(const char* src) {
Expand Down

0 comments on commit fa720a7

Please sign in to comment.