Commit 068904ae by Aaron Leung

Cleaning up the quoted/unquoted metadata for string-like objects.

parent 1d06e566
...@@ -972,7 +972,9 @@ namespace Sass { ...@@ -972,7 +972,9 @@ namespace Sass {
// see if there any interpolants // see if there any interpolants
const char* p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly<hash_lbrace> > >(str.begin, str.end); const char* p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly<hash_lbrace> > >(str.begin, str.end);
if (!p) { if (!p) {
return context.new_Node(Node::string_constant, path, line, str); Node result(context.new_Node(Node::string_constant, path, line, str));
result.is_quoted() = true;
return result;
} }
Node schema(context.new_Node(Node::string_schema, path, line, 1)); Node schema(context.new_Node(Node::string_schema, path, line, 1));
...@@ -1000,6 +1002,7 @@ namespace Sass { ...@@ -1000,6 +1002,7 @@ namespace Sass {
break; break;
} }
} }
schema.is_quoted() = true;
schema.should_eval() = true; schema.should_eval() = true;
return schema; return schema;
} }
...@@ -1044,7 +1047,9 @@ namespace Sass { ...@@ -1044,7 +1047,9 @@ namespace Sass {
schema << triple; schema << triple;
} }
else if (lex< string_constant >()) { else if (lex< string_constant >()) {
schema << context.new_Node(Node::string_constant, path, line, lexed); Node str(context.new_Node(Node::string_constant, path, line, lexed));
str.is_quoted() = true;
schema << str;
} }
else if (lex< variable >()) { else if (lex< variable >()) {
schema << context.new_Node(Node::variable, path, line, lexed); schema << context.new_Node(Node::variable, path, line, lexed);
......
...@@ -498,15 +498,14 @@ namespace Sass { ...@@ -498,15 +498,14 @@ namespace Sass {
Node::Type optype = op.type(); Node::Type optype = op.type();
Node::Type ltype = acc.type(); Node::Type ltype = acc.type();
Node::Type rtype = rhs.type(); Node::Type rtype = rhs.type();
if (ltype == Node::number && rhs.is_string()) { // if (ltype == Node::number && rhs.is_string()) {
acc = (new_Node(Node::concatenation, list.path(), list.line(), 2) << acc); // acc = (new_Node(Node::concatenation, list.path(), list.line(), 2) << acc);
if (optype != Node::add) acc << op; // if (optype != Node::add) acc << op;
if (rtype == Node::concatenation) acc += rhs; // if (rtype == Node::concatenation) acc += rhs;
else acc << rhs; // else acc << rhs;
acc.is_quoted() = rhs.is_quoted(); // acc.is_quoted() = rhs.is_quoted();
acc.is_unquoted() = rhs.is_unquoted(); // }
} if (ltype == Node::number && rtype == Node::number) {
else if (ltype == Node::number && rtype == Node::number) {
acc = new_Node(list.path(), list.line(), operate(op, acc.numeric_value(), rhs.numeric_value())); acc = new_Node(list.path(), list.line(), operate(op, acc.numeric_value(), rhs.numeric_value()));
} }
else if (ltype == Node::number && rtype == Node::numeric_dimension) { else if (ltype == Node::number && rtype == Node::numeric_dimension) {
...@@ -536,8 +535,6 @@ namespace Sass { ...@@ -536,8 +535,6 @@ namespace Sass {
acc = (new_Node(Node::value_schema, list.path(), list.line(), 3) << acc); acc = (new_Node(Node::value_schema, list.path(), list.line(), 3) << acc);
acc << op; acc << op;
acc << rhs; acc << rhs;
acc.is_quoted() = false;
acc.is_unquoted() = true;
} }
} }
else if (ltype == Node::numeric_color && rtype == Node::number) { else if (ltype == Node::numeric_color && rtype == Node::number) {
...@@ -568,15 +565,16 @@ namespace Sass { ...@@ -568,15 +565,16 @@ namespace Sass {
if (optype != Node::add) acc << op; if (optype != Node::add) acc << op;
acc += rhs; acc += rhs;
acc.is_quoted() = acc[0].is_quoted(); acc.is_quoted() = acc[0].is_quoted();
acc.is_unquoted() = acc[0].is_unquoted();
} }
else if (acc.is_string() || rhs.is_string()) { else if (acc.is_string() || rhs.is_string()) {
acc = (new_Node(Node::concatenation, list.path(), list.line(), 2) << acc); acc = (new_Node(Node::concatenation, list.path(), list.line(), 2) << acc);
if (optype != Node::add) acc << op; if (optype != Node::add) acc << op;
acc << rhs; acc << rhs;
if (!acc[0].is_string()) { if (acc[0].is_quoted() || (ltype == Node::number && rhs.is_quoted())) {
acc.is_quoted() = true;
}
else {
acc.is_quoted() = false; acc.is_quoted() = false;
acc.is_unquoted() = true;
} }
} }
else { // lists or schemas else { // lists or schemas
...@@ -599,7 +597,6 @@ namespace Sass { ...@@ -599,7 +597,6 @@ namespace Sass {
acc << rhs; acc << rhs;
} }
acc.is_quoted() = false; acc.is_quoted() = false;
acc.is_unquoted() = true;
} }
return reduce(list, head + 2, acc, new_Node); return reduce(list, head + 2, acc, new_Node);
} }
......
...@@ -745,8 +745,7 @@ namespace Sass { ...@@ -745,8 +745,7 @@ namespace Sass {
extern Signature unquote_sig = "unquote($string)"; extern Signature unquote_sig = "unquote($string)";
Node unquote(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) { Node unquote(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) {
Node cpy(new_Node(path, line, bindings[parameter_names[0].token()])); Node cpy(new_Node(path, line, bindings[parameter_names[0].token()]));
cpy.is_unquoted() = true; // in case it happens to be a string cpy.is_quoted() = false;
cpy.is_quoted() = false; // in case it happens to be an identifier
return cpy; return cpy;
} }
...@@ -754,8 +753,7 @@ namespace Sass { ...@@ -754,8 +753,7 @@ namespace Sass {
Node quote(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) { Node quote(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) {
Node orig(arg(quote_sig, path, line, parameter_names, bindings, 0, Node::string_t)); Node orig(arg(quote_sig, path, line, parameter_names, bindings, 0, Node::string_t));
Node copy(new_Node(path, line, orig)); Node copy(new_Node(path, line, orig));
copy.is_unquoted() = false; // in case it happens to be a string copy.is_quoted() = true;
copy.is_quoted() = true; // in case it happens to be an identifier
return copy; return copy;
} }
...@@ -1082,9 +1080,7 @@ namespace Sass { ...@@ -1082,9 +1080,7 @@ namespace Sass {
type_name = Token::make(string_name); type_name = Token::make(string_name);
} break; } break;
} }
Node type(new_Node(Node::string_constant, path, line, type_name)); return new_Node(Node::identifier, path, line, type_name);
type.is_unquoted() = true;
return type;
} }
extern Signature unit_sig = "unit($number)"; extern Signature unit_sig = "unit($number)";
...@@ -1093,12 +1089,16 @@ namespace Sass { ...@@ -1093,12 +1089,16 @@ namespace Sass {
switch (val.type()) switch (val.type())
{ {
case Node::number: { case Node::number: {
return new_Node(Node::string_constant, path, line, Token::make(empty_str)); Node u(new_Node(Node::string_constant, path, line, Token::make(empty_str)));
u.is_quoted() = true;
return u;
} break; } break;
case Node::numeric_dimension: case Node::numeric_dimension:
case Node::numeric_percentage: { case Node::numeric_percentage: {
return new_Node(Node::string_constant, path, line, val.unit()); Node u(new_Node(Node::string_constant, path, line, val.unit()));
u.is_quoted() = true;
return u;
} break; } break;
// unreachable // unreachable
...@@ -1197,6 +1197,7 @@ namespace Sass { ...@@ -1197,6 +1197,7 @@ namespace Sass {
Node result(new_Node(Node::concatenation, path, line, 2)); Node result(new_Node(Node::concatenation, path, line, 2));
result << image_path_val; result << image_path_val;
result << base_path; result << base_path;
result.is_quoted() = true;
if (!only_path) result = (new_Node(Node::uri, path, line, 1) << result); if (!only_path) result = (new_Node(Node::uri, path, line, 1) << result);
return result; return result;
......
...@@ -189,8 +189,7 @@ namespace Sass { ...@@ -189,8 +189,7 @@ namespace Sass {
bool has_backref() const; bool has_backref() const;
bool from_variable() const; bool from_variable() const;
bool& should_eval() const; bool& should_eval() const;
bool& is_unquoted() const; // for strings bool& is_quoted() const;
bool& is_quoted() const; // for identifiers
bool is_numeric() const; bool is_numeric() const;
bool is_string() const; // for all string-like types bool is_string() const; // for all string-like types
bool is_schema() const; // for all interpolated data bool is_schema() const; // for all interpolated data
...@@ -269,7 +268,6 @@ namespace Sass { ...@@ -269,7 +268,6 @@ namespace Sass {
bool has_backref; bool has_backref;
bool from_variable; bool from_variable;
bool should_eval; bool should_eval;
bool is_unquoted;
bool is_quoted; bool is_quoted;
bool has_been_extended; bool has_been_extended;
...@@ -286,8 +284,7 @@ namespace Sass { ...@@ -286,8 +284,7 @@ namespace Sass {
has_backref(false), has_backref(false),
from_variable(false), from_variable(false),
should_eval(false), should_eval(false),
is_unquoted(false), // for strings is_quoted(false),
is_quoted(false), // for identifiers -- yeah, it's hacky for now
has_been_extended(false) has_been_extended(false)
{ } { }
...@@ -442,7 +439,6 @@ namespace Sass { ...@@ -442,7 +439,6 @@ namespace Sass {
inline bool Node::has_backref() const { return ip_->has_backref; } inline bool Node::has_backref() const { return ip_->has_backref; }
inline bool Node::from_variable() const { return ip_->from_variable; } inline bool Node::from_variable() const { return ip_->from_variable; }
inline bool& Node::should_eval() const { return ip_->should_eval; } inline bool& Node::should_eval() const { return ip_->should_eval; }
inline bool& Node::is_unquoted() const { return ip_->is_unquoted; }
inline bool& Node::is_quoted() const { return ip_->is_quoted; } inline bool& Node::is_quoted() const { return ip_->is_quoted; }
inline bool Node::is_numeric() const { return ip_->is_numeric(); } inline bool Node::is_numeric() const { return ip_->is_numeric(); }
inline bool Node::is_string() const { return ip_->is_string(); } inline bool Node::is_string() const { return ip_->is_string(); }
......
...@@ -285,7 +285,7 @@ namespace Sass { ...@@ -285,7 +285,7 @@ namespace Sass {
} break; } break;
case string_constant: { case string_constant: {
if (is_unquoted()) return token().unquote(); if (!is_quoted()) return token().unquote();
else { else {
string result(token().to_string()); string result(token().to_string());
if (result[0] != '"' && result[0] != '\'') return "\"" + result + "\""; if (result[0] != '"' && result[0] != '\'') return "\"" + result + "\"";
...@@ -334,51 +334,22 @@ namespace Sass { ...@@ -334,51 +334,22 @@ namespace Sass {
result += chunk; result += chunk;
} }
} }
if (is_unquoted()) result = result.substr(1, result.length() - 2); if (!is_quoted()) result = result.substr(1, result.length() - 2);
return result; return result;
} break; } break;
case concatenation: { case concatenation: {
string result; string result;
bool quoted /* = (at(0).type() == string_constant || at(0).type() == string_schema) ? true : false */;
if (at(0).type() == string_constant ||
at(0).type() == string_schema ||
(at(0).is_numeric() && (at(1).is_quoted() || !at(1).is_unquoted()))) {
quoted = true;
}
else {
quoted = false;
}
for (size_t i = 0, S = size(); i < S; ++i) { for (size_t i = 0, S = size(); i < S; ++i) {
// result += at(i).to_string().substr(1, at(i).token().length()-2); result += at(i).unquote();
Node::Type itype = at(i).type();
if (itype == Node::string_constant || itype == Node::string_schema) {
result += at(i).unquote();
}
else {
result += at(i).to_string();
}
} }
// if (inside_of == identifier_schema || inside_of == property) return result; if (!(inside_of == identifier_schema || inside_of == property) && is_quoted()) {
// else return "\"" + result + "\"";
if (!(inside_of == identifier_schema || inside_of == property) && quoted && !is_unquoted()) {
result = "\"" + result + "\""; result = "\"" + result + "\"";
} }
return result; return result;
} break; } break;
case warning: { case warning: {
// string prefix("WARNING: ");
// string indent(" ");
// Node contents(at(0));
// string result(contents.to_string());
// if (contents.type() == string_constant || contents.type() == string_schema) {
// result = result.substr(1, result.size()-2); // unquote if it's a single string
// }
// // These cerrs aren't log lines! They're supposed to be here!
// cerr << prefix << result << endl;
// cerr << indent << "on line " << at(0).line() << " of " << at(0).path();
// cerr << endl << endl;
return ""; return "";
} break; } break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment