Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 068904a

Browse files
author
Aaron Leung
committed
Cleaning up the quoted/unquoted metadata for string-like objects.
1 parent 1d06e56 commit 068904a

File tree

5 files changed

+35
-65
lines changed

5 files changed

+35
-65
lines changed

document_parser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,9 @@ namespace Sass {
972972
// see if there any interpolants
973973
const char* p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly<hash_lbrace> > >(str.begin, str.end);
974974
if (!p) {
975-
return context.new_Node(Node::string_constant, path, line, str);
975+
Node result(context.new_Node(Node::string_constant, path, line, str));
976+
result.is_quoted() = true;
977+
return result;
976978
}
977979

978980
Node schema(context.new_Node(Node::string_schema, path, line, 1));
@@ -1000,6 +1002,7 @@ namespace Sass {
10001002
break;
10011003
}
10021004
}
1005+
schema.is_quoted() = true;
10031006
schema.should_eval() = true;
10041007
return schema;
10051008
}
@@ -1044,7 +1047,9 @@ namespace Sass {
10441047
schema << triple;
10451048
}
10461049
else if (lex< string_constant >()) {
1047-
schema << context.new_Node(Node::string_constant, path, line, lexed);
1050+
Node str(context.new_Node(Node::string_constant, path, line, lexed));
1051+
str.is_quoted() = true;
1052+
schema << str;
10481053
}
10491054
else if (lex< variable >()) {
10501055
schema << context.new_Node(Node::variable, path, line, lexed);

eval_apply.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,14 @@ namespace Sass {
498498
Node::Type optype = op.type();
499499
Node::Type ltype = acc.type();
500500
Node::Type rtype = rhs.type();
501-
if (ltype == Node::number && rhs.is_string()) {
502-
acc = (new_Node(Node::concatenation, list.path(), list.line(), 2) << acc);
503-
if (optype != Node::add) acc << op;
504-
if (rtype == Node::concatenation) acc += rhs;
505-
else acc << rhs;
506-
acc.is_quoted() = rhs.is_quoted();
507-
acc.is_unquoted() = rhs.is_unquoted();
508-
}
509-
else if (ltype == Node::number && rtype == Node::number) {
501+
// if (ltype == Node::number && rhs.is_string()) {
502+
// acc = (new_Node(Node::concatenation, list.path(), list.line(), 2) << acc);
503+
// if (optype != Node::add) acc << op;
504+
// if (rtype == Node::concatenation) acc += rhs;
505+
// else acc << rhs;
506+
// acc.is_quoted() = rhs.is_quoted();
507+
// }
508+
if (ltype == Node::number && rtype == Node::number) {
510509
acc = new_Node(list.path(), list.line(), operate(op, acc.numeric_value(), rhs.numeric_value()));
511510
}
512511
else if (ltype == Node::number && rtype == Node::numeric_dimension) {
@@ -536,8 +535,6 @@ namespace Sass {
536535
acc = (new_Node(Node::value_schema, list.path(), list.line(), 3) << acc);
537536
acc << op;
538537
acc << rhs;
539-
acc.is_quoted() = false;
540-
acc.is_unquoted() = true;
541538
}
542539
}
543540
else if (ltype == Node::numeric_color && rtype == Node::number) {
@@ -568,15 +565,16 @@ namespace Sass {
568565
if (optype != Node::add) acc << op;
569566
acc += rhs;
570567
acc.is_quoted() = acc[0].is_quoted();
571-
acc.is_unquoted() = acc[0].is_unquoted();
572568
}
573569
else if (acc.is_string() || rhs.is_string()) {
574570
acc = (new_Node(Node::concatenation, list.path(), list.line(), 2) << acc);
575571
if (optype != Node::add) acc << op;
576572
acc << rhs;
577-
if (!acc[0].is_string()) {
573+
if (acc[0].is_quoted() || (ltype == Node::number && rhs.is_quoted())) {
574+
acc.is_quoted() = true;
575+
}
576+
else {
578577
acc.is_quoted() = false;
579-
acc.is_unquoted() = true;
580578
}
581579
}
582580
else { // lists or schemas
@@ -599,7 +597,6 @@ namespace Sass {
599597
acc << rhs;
600598
}
601599
acc.is_quoted() = false;
602-
acc.is_unquoted() = true;
603600
}
604601
return reduce(list, head + 2, acc, new_Node);
605602
}

functions.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,15 @@ namespace Sass {
745745
extern Signature unquote_sig = "unquote($string)";
746746
Node unquote(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) {
747747
Node cpy(new_Node(path, line, bindings[parameter_names[0].token()]));
748-
cpy.is_unquoted() = true; // in case it happens to be a string
749-
cpy.is_quoted() = false; // in case it happens to be an identifier
748+
cpy.is_quoted() = false;
750749
return cpy;
751750
}
752751

753752
extern Signature quote_sig = "quote($string)";
754753
Node quote(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) {
755754
Node orig(arg(quote_sig, path, line, parameter_names, bindings, 0, Node::string_t));
756755
Node copy(new_Node(path, line, orig));
757-
copy.is_unquoted() = false; // in case it happens to be a string
758-
copy.is_quoted() = true; // in case it happens to be an identifier
756+
copy.is_quoted() = true;
759757
return copy;
760758
}
761759

@@ -1082,9 +1080,7 @@ namespace Sass {
10821080
type_name = Token::make(string_name);
10831081
} break;
10841082
}
1085-
Node type(new_Node(Node::string_constant, path, line, type_name));
1086-
type.is_unquoted() = true;
1087-
return type;
1083+
return new_Node(Node::identifier, path, line, type_name);
10881084
}
10891085

10901086
extern Signature unit_sig = "unit($number)";
@@ -1093,12 +1089,16 @@ namespace Sass {
10931089
switch (val.type())
10941090
{
10951091
case Node::number: {
1096-
return new_Node(Node::string_constant, path, line, Token::make(empty_str));
1092+
Node u(new_Node(Node::string_constant, path, line, Token::make(empty_str)));
1093+
u.is_quoted() = true;
1094+
return u;
10971095
} break;
10981096

10991097
case Node::numeric_dimension:
11001098
case Node::numeric_percentage: {
1101-
return new_Node(Node::string_constant, path, line, val.unit());
1099+
Node u(new_Node(Node::string_constant, path, line, val.unit()));
1100+
u.is_quoted() = true;
1101+
return u;
11021102
} break;
11031103

11041104
// unreachable
@@ -1197,6 +1197,7 @@ namespace Sass {
11971197
Node result(new_Node(Node::concatenation, path, line, 2));
11981198
result << image_path_val;
11991199
result << base_path;
1200+
result.is_quoted() = true;
12001201
if (!only_path) result = (new_Node(Node::uri, path, line, 1) << result);
12011202

12021203
return result;

node.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ namespace Sass {
189189
bool has_backref() const;
190190
bool from_variable() const;
191191
bool& should_eval() const;
192-
bool& is_unquoted() const; // for strings
193-
bool& is_quoted() const; // for identifiers
192+
bool& is_quoted() const;
194193
bool is_numeric() const;
195194
bool is_string() const; // for all string-like types
196195
bool is_schema() const; // for all interpolated data
@@ -269,7 +268,6 @@ namespace Sass {
269268
bool has_backref;
270269
bool from_variable;
271270
bool should_eval;
272-
bool is_unquoted;
273271
bool is_quoted;
274272
bool has_been_extended;
275273

@@ -286,8 +284,7 @@ namespace Sass {
286284
has_backref(false),
287285
from_variable(false),
288286
should_eval(false),
289-
is_unquoted(false), // for strings
290-
is_quoted(false), // for identifiers -- yeah, it's hacky for now
287+
is_quoted(false),
291288
has_been_extended(false)
292289
{ }
293290

@@ -442,7 +439,6 @@ namespace Sass {
442439
inline bool Node::has_backref() const { return ip_->has_backref; }
443440
inline bool Node::from_variable() const { return ip_->from_variable; }
444441
inline bool& Node::should_eval() const { return ip_->should_eval; }
445-
inline bool& Node::is_unquoted() const { return ip_->is_unquoted; }
446442
inline bool& Node::is_quoted() const { return ip_->is_quoted; }
447443
inline bool Node::is_numeric() const { return ip_->is_numeric(); }
448444
inline bool Node::is_string() const { return ip_->is_string(); }

node_emitters.cpp

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ namespace Sass {
285285
} break;
286286

287287
case string_constant: {
288-
if (is_unquoted()) return token().unquote();
288+
if (!is_quoted()) return token().unquote();
289289
else {
290290
string result(token().to_string());
291291
if (result[0] != '"' && result[0] != '\'') return "\"" + result + "\"";
@@ -334,51 +334,22 @@ namespace Sass {
334334
result += chunk;
335335
}
336336
}
337-
if (is_unquoted()) result = result.substr(1, result.length() - 2);
337+
if (!is_quoted()) result = result.substr(1, result.length() - 2);
338338
return result;
339339
} break;
340340

341341
case concatenation: {
342342
string result;
343-
bool quoted /* = (at(0).type() == string_constant || at(0).type() == string_schema) ? true : false */;
344-
if (at(0).type() == string_constant ||
345-
at(0).type() == string_schema ||
346-
(at(0).is_numeric() && (at(1).is_quoted() || !at(1).is_unquoted()))) {
347-
quoted = true;
348-
}
349-
else {
350-
quoted = false;
351-
}
352343
for (size_t i = 0, S = size(); i < S; ++i) {
353-
// result += at(i).to_string().substr(1, at(i).token().length()-2);
354-
Node::Type itype = at(i).type();
355-
if (itype == Node::string_constant || itype == Node::string_schema) {
356-
result += at(i).unquote();
357-
}
358-
else {
359-
result += at(i).to_string();
360-
}
344+
result += at(i).unquote();
361345
}
362-
// if (inside_of == identifier_schema || inside_of == property) return result;
363-
// else return "\"" + result + "\"";
364-
if (!(inside_of == identifier_schema || inside_of == property) && quoted && !is_unquoted()) {
346+
if (!(inside_of == identifier_schema || inside_of == property) && is_quoted()) {
365347
result = "\"" + result + "\"";
366348
}
367349
return result;
368350
} break;
369351

370352
case warning: {
371-
// string prefix("WARNING: ");
372-
// string indent(" ");
373-
// Node contents(at(0));
374-
// string result(contents.to_string());
375-
// if (contents.type() == string_constant || contents.type() == string_schema) {
376-
// result = result.substr(1, result.size()-2); // unquote if it's a single string
377-
// }
378-
// // These cerrs aren't log lines! They're supposed to be here!
379-
// cerr << prefix << result << endl;
380-
// cerr << indent << "on line " << at(0).line() << " of " << at(0).path();
381-
// cerr << endl << endl;
382353
return "";
383354
} break;
384355

0 commit comments

Comments
 (0)