Skip to content

Commit a7581d6

Browse files
committed
Fix spacing issues with list parsing
1 parent af8365d commit a7581d6

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/ast.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,11 @@ namespace Sass {
14011401
////////////////////////////////////////////////////////
14021402
class String_Quoted : public String_Constant {
14031403
public:
1404-
String_Quoted(ParserState pstate, std::string val)
1404+
String_Quoted(ParserState pstate, std::string val, char q = 0)
14051405
: String_Constant(pstate, val)
14061406
{
14071407
value_ = unquote(value_, &quote_mark_);
1408+
if (q && quote_mark_) quote_mark_ = q;
14081409
}
14091410
virtual bool operator==(const Expression& rhs) const;
14101411
virtual std::string to_string(bool compressed = false, int precision = 5) const;

src/parser.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,14 @@ namespace Sass {
13651365
return parse_function_call_schema();
13661366
}
13671367
else if (lex< identifier_schema >()) {
1368-
return parse_identifier_schema();
1368+
String* string = parse_identifier_schema();
1369+
if (String_Schema* schema = dynamic_cast<String_Schema*>(string)) {
1370+
if (lex < exactly < '(' > >()) {
1371+
*schema << parse_list();
1372+
lex < exactly < ')' > >();
1373+
}
1374+
}
1375+
return string;
13691376
}
13701377
else if (peek< re_functional >()) {
13711378
return parse_function_call();
@@ -1598,13 +1605,14 @@ namespace Sass {
15981605
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
15991606
}
16001607

1608+
const char* e = 0;
16011609
size_t num_items = 0;
16021610
while (position < stop) {
16031611
// parse space between tokens
16041612
if (lex< spaces >() && num_items) {
16051613
(*schema) << new (ctx.mem) String_Constant(pstate, " ");
16061614
}
1607-
if (peek< re_functional >()) {
1615+
if ((e = peek< re_functional >()) && e < stop) {
16081616
(*schema) << parse_function_call();
16091617
}
16101618
// lex an interpolant /#{...}/
@@ -1621,10 +1629,16 @@ namespace Sass {
16211629
// lex some string constants
16221630
else if (lex< alternatives < exactly<'%'>, exactly < '-' >, identifier > >()) {
16231631
(*schema) << new (ctx.mem) String_Constant(pstate, lexed);
1632+
if (*position == '"' || *position == '\'') {
1633+
(*schema) << new (ctx.mem) String_Constant(pstate, " ");
1634+
}
16241635
}
16251636
// lex a quoted string
16261637
else if (lex< quoted_string >()) {
1627-
(*schema) << new (ctx.mem) String_Quoted(pstate, lexed);
1638+
(*schema) << new (ctx.mem) String_Quoted(pstate, lexed, '"');
1639+
if (*position == '"' || *position == '\'' || alpha(position)) {
1640+
(*schema) << new (ctx.mem) String_Constant(pstate, " ");
1641+
}
16281642
}
16291643
// lex (normalized) variable
16301644
else if (lex< variable >()) {
@@ -1680,7 +1694,9 @@ namespace Sass {
16801694
if (p) {
16811695
if (i < p) {
16821696
// accumulate the preceding segment if it's nonempty
1683-
(*schema) << new (ctx.mem) String_Constant(pstate, std::string(i, p));
1697+
const char* o = position; position = i;
1698+
*schema << parse_value_schema(p);
1699+
position = o;
16841700
}
16851701
// we need to skip anything inside strings
16861702
// create a new target in parser/prelexer
@@ -1702,7 +1718,11 @@ namespace Sass {
17021718
}
17031719
}
17041720
else { // no interpolants left; add the last segment if nonempty
1705-
if (i < end) (*schema) << new (ctx.mem) String_Constant(pstate, std::string(i, id.end));
1721+
if (i < end) {
1722+
const char* o = position; position = i;
1723+
*schema << parse_value_schema(id.end);
1724+
position = o;
1725+
}
17061726
break;
17071727
}
17081728
}

src/prelexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ namespace Sass {
143143
alternatives <
144144
digits,
145145
identifier,
146+
quoted_string,
146147
exactly<'+'>,
147148
exactly<'-'>
148149
>

0 commit comments

Comments
 (0)