Skip to content

Commit 3faf115

Browse files
committed
Replace Quoted Strings with Constants where possible
Fixes #1295 Fixes #1328
1 parent cccda81 commit 3faf115

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

parser.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ namespace Sass {
591591
// try to parse mutliple interpolants
592592
if (const char* p = find_first_in_interval< exactly<hash_lbrace> >(i, end_of_selector)) {
593593
// accumulate the preceding segment if the position has advanced
594-
if (i < p) (*schema) << new (ctx.mem) String_Quoted(pstate, string(i, p));
594+
if (i < p) (*schema) << new (ctx.mem) String_Constant(pstate, string(i, p));
595595
// check if the interpolation only contains white-space (error out)
596596
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
597597
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
@@ -611,7 +611,7 @@ namespace Sass {
611611
// add the last segment if there is one
612612
else {
613613
// make sure to add the last bits of the string up to the end (if any)
614-
if (i < end_of_selector) (*schema) << new (ctx.mem) String_Quoted(pstate, string(i, end_of_selector));
614+
if (i < end_of_selector) (*schema) << new (ctx.mem) String_Constant(pstate, string(i, end_of_selector));
615615
// exit loop
616616
i = end_of_selector;
617617
}
@@ -740,7 +740,7 @@ namespace Sass {
740740
// comments are allowed, but not spaces?
741741
combinator = Complex_Selector::REFERENCE;
742742
if (!lex < re_reference_combinator >()) return 0;
743-
reference = new (ctx.mem) String_Quoted(pstate, lexed);
743+
reference = new (ctx.mem) String_Constant(pstate, lexed);
744744
if (!lex < exactly < '/' > >()) return 0; // ToDo: error msg?
745745
}
746746
else /* if (lex< zero >()) */ combinator = Complex_Selector::ANCESTOR_OF;
@@ -958,7 +958,7 @@ namespace Sass {
958958

959959
String* value = 0;
960960
if (lex_css< identifier >()) {
961-
value = new (ctx.mem) String_Quoted(p, lexed);
961+
value = new (ctx.mem) String_Constant(p, lexed);
962962
}
963963
else if (lex_css< quoted_string >()) {
964964
value = parse_interpolated_chunk(lexed, true); // needed!
@@ -988,7 +988,7 @@ namespace Sass {
988988
prop = parse_identifier_schema();
989989
}
990990
else if (lex< sequence< optional< exactly<'*'> >, identifier > >()) {
991-
prop = new (ctx.mem) String_Quoted(pstate, lexed);
991+
prop = new (ctx.mem) String_Constant(pstate, lexed);
992992
prop->is_delayed(true);
993993
}
994994
else {
@@ -1394,7 +1394,7 @@ namespace Sass {
13941394
return new (ctx.mem) Parent_Selector(pstate); }
13951395

13961396
if (lex< kwd_important >())
1397-
{ return new (ctx.mem) String_Quoted(pstate, "!important"); }
1397+
{ return new (ctx.mem) String_Constant(pstate, "!important"); }
13981398

13991399
if (const char* stop = peek< value_schema >())
14001400
{ return parse_value_schema(stop); }
@@ -1428,7 +1428,7 @@ namespace Sass {
14281428
{ return new (ctx.mem) Textual(pstate, Textual::DIMENSION, lexed); }
14291429

14301430
if (lex< sequence< static_component, one_plus< identifier > > >())
1431-
{ return new (ctx.mem) String_Quoted(pstate, lexed); }
1431+
{ return new (ctx.mem) String_Constant(pstate, lexed); }
14321432

14331433
if (lex< number >())
14341434
{ return new (ctx.mem) Textual(pstate, Textual::NUMBER, lexed); }
@@ -1438,7 +1438,7 @@ namespace Sass {
14381438

14391439
// Special case handling for `%` proceeding an interpolant.
14401440
if (lex< sequence< exactly<'%'>, optional< percentage > > >())
1441-
{ return new (ctx.mem) String_Quoted(pstate, lexed); }
1441+
{ return new (ctx.mem) String_Constant(pstate, lexed); }
14421442

14431443
error("error reading values after " + lexed.to_string(), pstate);
14441444

@@ -1466,7 +1466,7 @@ namespace Sass {
14661466
if (p) {
14671467
if (i < p) {
14681468
// accumulate the preceding segment if it's nonempty
1469-
(*schema) << new (ctx.mem) String_Quoted(pstate, string(i, p));
1469+
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, p));
14701470
}
14711471
// we need to skip anything inside strings
14721472
// create a new target in parser/prelexer
@@ -1488,7 +1488,7 @@ namespace Sass {
14881488
}
14891489
else { // no interpolants left; add the last segment if nonempty
14901490
// check if we need quotes here (was not sure after merge)
1491-
if (i < chunk.end) (*schema) << new (ctx.mem) String_Quoted(pstate, string(i, chunk.end));
1491+
if (i < chunk.end) (*schema) << new (ctx.mem) String_Constant(pstate, string(i, chunk.end));
14921492
break;
14931493
}
14941494
++ i;
@@ -1538,7 +1538,7 @@ namespace Sass {
15381538
p = find_first_in_interval< exactly<hash_lbrace> >(i, str.end);
15391539
if (p) {
15401540
if (i < p) {
1541-
(*schema) << new (ctx.mem) String_Quoted(pstate, string(i, p)); // accumulate the preceding segment if it's nonempty
1541+
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, p)); // accumulate the preceding segment if it's nonempty
15421542
}
15431543
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
15441544
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
@@ -1558,7 +1558,7 @@ namespace Sass {
15581558
}
15591559
else { // no interpolants left; add the last segment if nonempty
15601560
if (i < str.end) {
1561-
(*schema) << new (ctx.mem) String_Quoted(pstate, string(i, str.end));
1561+
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, str.end));
15621562
}
15631563
break;
15641564
}
@@ -1573,10 +1573,10 @@ namespace Sass {
15731573
*kwd_arg << new (ctx.mem) Variable(pstate, Util::normalize_underscores(lexed));
15741574
} else {
15751575
lex< alternatives< identifier_schema, identifier > >();
1576-
*kwd_arg << new (ctx.mem) String_Quoted(pstate, lexed);
1576+
*kwd_arg << new (ctx.mem) String_Constant(pstate, lexed);
15771577
}
15781578
lex< exactly<'='> >();
1579-
*kwd_arg << new (ctx.mem) String_Quoted(pstate, lexed);
1579+
*kwd_arg << new (ctx.mem) String_Constant(pstate, lexed);
15801580
if (peek< variable >()) *kwd_arg << parse_list();
15811581
else if (lex< number >()) *kwd_arg << new (ctx.mem) Textual(pstate, Textual::NUMBER, Util::normalize_decimals(lexed));
15821582
else if (peek < ie_keyword_arg_value >()) { *kwd_arg << parse_list(); }
@@ -1596,7 +1596,7 @@ namespace Sass {
15961596
while (position < stop) {
15971597
// parse space between tokens
15981598
if (lex< spaces >() && num_items) {
1599-
(*schema) << new (ctx.mem) String_Quoted(pstate, " ");
1599+
(*schema) << new (ctx.mem) String_Constant(pstate, " ");
16001600
}
16011601
if (peek< re_functional >()) {
16021602
(*schema) << parse_function_call();
@@ -1605,7 +1605,7 @@ namespace Sass {
16051605
else if (lex< exactly < hash_lbrace > >()) {
16061606
// Try to lex static expression first
16071607
if (lex< re_static_expression >()) {
1608-
(*schema) << new (ctx.mem) String_Quoted(pstate, lexed);
1608+
(*schema) << new (ctx.mem) String_Constant(pstate, lexed);
16091609
} else {
16101610
(*schema) << parse_list();
16111611
}
@@ -1614,7 +1614,7 @@ namespace Sass {
16141614
}
16151615
// lex some string constants
16161616
else if (lex< alternatives < exactly<'%'>, exactly < '-' >, identifier > >()) {
1617-
(*schema) << new (ctx.mem) String_Quoted(pstate, lexed);
1617+
(*schema) << new (ctx.mem) String_Constant(pstate, lexed);
16181618
}
16191619
// lex a quoted string
16201620
else if (lex< quoted_string >()) {
@@ -1662,7 +1662,7 @@ namespace Sass {
16621662
// see if there any interpolants
16631663
const char* p = find_first_in_interval< exactly<hash_lbrace> >(id.begin, id.end);
16641664
if (!p) {
1665-
return new (ctx.mem) String_Quoted(pstate, string(id.begin, id.end));
1665+
return new (ctx.mem) String_Constant(pstate, string(id.begin, id.end));
16661666
}
16671667

16681668
String_Schema* schema = new (ctx.mem) String_Schema(pstate);
@@ -1671,7 +1671,7 @@ namespace Sass {
16711671
if (p) {
16721672
if (i < p) {
16731673
// accumulate the preceding segment if it's nonempty
1674-
(*schema) << new (ctx.mem) String_Quoted(pstate, string(i, p));
1674+
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, p));
16751675
}
16761676
// we need to skip anything inside strings
16771677
// create a new target in parser/prelexer
@@ -1693,7 +1693,7 @@ namespace Sass {
16931693
}
16941694
}
16951695
else { // no interpolants left; add the last segment if nonempty
1696-
if (i < end) (*schema) << new (ctx.mem) String_Quoted(pstate, string(i, id.end));
1696+
if (i < end) (*schema) << new (ctx.mem) String_Constant(pstate, string(i, id.end));
16971697
break;
16981698
}
16991699
}
@@ -1884,7 +1884,7 @@ namespace Sass {
18841884
if (lex < identifier_schema >()) {
18851885
String_Schema* schema = new (ctx.mem) String_Schema(pstate);
18861886
*schema << media_query->media_type();
1887-
*schema << new (ctx.mem) String_Quoted(pstate, " ");
1887+
*schema << new (ctx.mem) String_Constant(pstate, " ");
18881888
*schema << parse_identifier_schema();
18891889
media_query->media_type(schema);
18901890
}
@@ -2146,7 +2146,7 @@ namespace Sass {
21462146
// consume whitespace and comments
21472147
spaces, block_comment, line_comment,
21482148
// match `/deep/` selector (pass-trough)
2149-
// match reference /\/[^\/]+\//;
2149+
// there is no functionality for it yet
21502150
schema_reference_combinator,
21512151
// match selector ops /[*&%,()\[\]]/
21522152
class_char < selector_lookahead_ops >,

0 commit comments

Comments
 (0)