Skip to content

Commit

Permalink
Fix regression and issues with list and schema parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter authored and xzyfer committed Mar 17, 2016
1 parent 0a05c8d commit 18e1f52
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ namespace Sass {

Selector_List* Selector_List::parentize(Selector_List* ps, Context& ctx)
{
if (!this->has_parent_ref()) return this;
Selector_List* ss = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
Selector_List* list = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
Expand Down Expand Up @@ -1897,6 +1898,10 @@ namespace Sass {
return false;
}

bool String_Constant::is_invisible() const {
return value_.empty() && quote_mark_ == 0;
}

bool String_Constant::operator== (const Expression& rhs) const
{
if (const String_Quoted* qstr = dynamic_cast<const String_Quoted*>(&rhs)) {
Expand Down
1 change: 1 addition & 0 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ namespace Sass {
{ }
std::string type() { return "string"; }
static std::string type_name() { return "string"; }
virtual bool is_invisible() const;

virtual size_t hash()
{
Expand Down
14 changes: 11 additions & 3 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,12 @@ namespace Sass {
if (List* l = dynamic_cast<List*>(ex)) {
List* ll = SASS_MEMORY_NEW(ctx.mem, List, l->pstate(), 0, l->separator());
// this fixes an issue with bourbon sample, not really sure why
if (l->size() && dynamic_cast<Null*>((*l)[0])) { res += " "; }
// if (l->size() && dynamic_cast<Null*>((*l)[0])) { res += ""; }
for(auto item : *l) {
item->is_interpolant(l->is_interpolant());
std::string rl(""); interpolation(ctx, rl, item, into_quotes, l->is_interpolant());
if (rl != "") *ll << SASS_MEMORY_NEW(ctx.mem, String_Quoted, item->pstate(), rl);
bool is_null = dynamic_cast<Null*>(item) != 0; // rl != ""
if (!is_null) *ll << SASS_MEMORY_NEW(ctx.mem, String_Quoted, item->pstate(), rl);
}
res += (ll->to_string(ctx.c_options));
ll->is_interpolant(l->is_interpolant());
Expand Down Expand Up @@ -1170,15 +1171,22 @@ namespace Sass {
}
}
}
bool was_quoted = false;
bool was_interpolant = false;
std::string res("");
for (size_t i = 0; i < L; ++i) {
bool is_quoted = dynamic_cast<String_Quoted*>((*s)[i]) != NULL;
(*s)[i]->perform(this);
if (was_quoted && !(*s)[i]->is_interpolant() && !was_interpolant) { res += " "; }
else if (i > 0 && is_quoted && !(*s)[i]->is_interpolant() && !was_interpolant) { res += " "; }
Expression* ex = (*s)[i]->is_delayed() ? (*s)[i] : (*s)[i]->perform(this);
interpolation(ctx, res, ex, into_quotes, ex->is_interpolant());
was_quoted = dynamic_cast<String_Quoted*>((*s)[i]) != NULL;
was_interpolant = (*s)[i]->is_interpolant();

}
if (!s->is_interpolant()) {
if (res == "") return SASS_MEMORY_NEW(ctx.mem, Null, s->pstate());
if (s->length() > 1 && res == "") return SASS_MEMORY_NEW(ctx.mem, Null, s->pstate());
return SASS_MEMORY_NEW(ctx.mem, String_Constant, s->pstate(), res);
}
String_Quoted* str = SASS_MEMORY_NEW(ctx.mem, String_Quoted, s->pstate(), res);
Expand Down
5 changes: 4 additions & 1 deletion src/inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ namespace Sass {
Expression* list_item = (*list)[i];
if (output_style() != TO_SASS) {
if (list_item->is_invisible()) {
continue;
// this fixes an issue with "" in a list
if (!dynamic_cast<String_Constant*>(list_item)) {
continue;
}
}
}
if (items_output) {
Expand Down
46 changes: 32 additions & 14 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,8 @@ namespace Sass {
}

const char* e = 0;
const char* ee = end;
end = stop;
size_t num_items = 0;
bool need_space = false;
while (position < stop) {
Expand All @@ -1600,7 +1602,7 @@ namespace Sass {
}
if (need_space) {
need_space = false;
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, " ");
// (*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, " ");
}
if ((e = peek< re_functional >()) && e < stop) {
(*schema) << parse_function_call();
Expand All @@ -1627,19 +1629,22 @@ namespace Sass {
else if (lex< alternatives < exactly<'%'>, exactly < '-' >, exactly < '+' > > >()) {
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, lexed);
}
else if (lex< sequence < identifier > >()) {
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, lexed);
// lex a quoted string
else if (lex< quoted_string >()) {
// need_space = true;
// if (schema->length()) (*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, " ");
// else need_space = true;
(*schema) << parse_string();
if ((*position == '"' || *position == '\'') || peek < alternatives < alpha > >()) {
need_space = true;
// need_space = true;
}
if (peek < exactly < '-' > >()) break;
}
// lex a quoted string
else if (lex< quoted_string >()) {
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Quoted, pstate, lexed, '"');
else if (lex< sequence < identifier > >()) {
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, lexed);
if ((*position == '"' || *position == '\'') || peek < alternatives < alpha > >()) {
need_space = true;
// need_space = true;
}
if (peek < exactly < '-' > >()) return schema;
}
// lex (normalized) variable
else if (lex< variable >()) {
Expand Down Expand Up @@ -1670,10 +1675,15 @@ namespace Sass {
(*schema) << parse_factor();
}
else {
return schema;
break;
}
++num_items;
}
if (position != stop) {
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, std::string(position, stop));
position = stop;
}
end = ee;
return schema;
}

Expand Down Expand Up @@ -2387,19 +2397,27 @@ namespace Sass {
non_greedy <
alternatives <
// consume whitespace
block_comment, spaces,
block_comment, // spaces,
// main tokens
interpolant,
sequence <
interpolant,
optional <
quoted_string
>
>,
identifier,
variable,
// issue #442
sequence <
parenthese_scope,
interpolant
interpolant,
optional <
quoted_string
>
>
>,
sequence <
optional_spaces,
// optional_spaces,
alternatives <
exactly<'{'>,
exactly<'}'>,
Expand Down
8 changes: 7 additions & 1 deletion src/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ namespace Sass {
const char* it_before_token = sneak < mx >(start);

// match the given prelexer
return mx(it_before_token);
const char* match = mx(it_before_token);

// check if match is in valid range
return match <= end ? match : 0;

}

Expand All @@ -142,6 +145,9 @@ namespace Sass {
// now call matcher to get position after token
const char* it_after_token = mx(it_before_token);

// check if match is in valid range
if (it_after_token > end) return 0;

// maybe we want to update the parser state anyway?
if (force == false) {
// assertion that we got a valid match
Expand Down

0 comments on commit 18e1f52

Please sign in to comment.