Commit 929307e8 by Aaron Leung

Fixing some quoting/unquoting and equality stuff.

parent 74629fb4
......@@ -257,6 +257,7 @@ namespace Sass {
// throw_eval_error("argument to unquote must be a string", cpy.path(), cpy.line());
// }
cpy.is_unquoted() = true;
cpy.is_quoted() = false;
return cpy;
}
......@@ -264,12 +265,24 @@ namespace Sass {
{ "quote", "$string", 0 };
Node quote(const vector<Token>& parameters, map<Token, Node>& bindings, Node_Factory& new_Node) {
Node orig(bindings[parameters[0]]);
if (orig.type() != Node::string_constant && orig.type() != Node::identifier) {
switch (orig.type())
{
default: {
throw_eval_error("argument to quote must be a string or identifier", orig.path(), orig.line());
}
} break;
case Node::string_constant:
case Node::string_schema:
case Node::identifier:
case Node::identifier_schema:
case Node::concatenation: {
Node cpy(new_Node(orig));
cpy.is_unquoted() = false;
cpy.is_quoted() = true;
return cpy;
} break;
}
return orig;
}
// Number Functions ////////////////////////////////////////////////////
......
......@@ -55,10 +55,28 @@ namespace Sass {
}
}
string Node::unquote() const
{
string intermediate(to_string());
if (!intermediate.empty() && (intermediate[0] == '"' || intermediate[0] == '\'')) {
return intermediate.substr(1, intermediate.length() - 2);
}
else {
return intermediate;
}
}
bool Node::operator==(Node rhs) const
{
Type t = type();
if (t != rhs.type()) return false;
Type t = type(), u = rhs.type();
if ((t == identifier || t == string_constant || t == string_schema || t == concatenation) &&
(u == identifier || u == string_constant || u == string_schema || u == concatenation)) {
return unquote() == rhs.unquote();
}
else if (t != u) {
return false;
}
switch (t)
{
......
......@@ -183,6 +183,7 @@ namespace Sass {
bool from_variable() const;
bool& should_eval() const;
bool& is_unquoted() const;
bool& is_quoted() const;
bool is_numeric() const;
bool is_guarded() const;
bool& has_been_extended() const;
......@@ -217,6 +218,8 @@ namespace Sass {
void flatten();
string unquote() const;
bool operator==(Node rhs) const;
bool operator!=(Node rhs) const;
bool operator<(Node rhs) const;
......@@ -256,6 +259,7 @@ namespace Sass {
bool from_variable;
bool should_eval;
bool is_unquoted;
bool is_quoted;
bool has_been_extended;
Node_Impl()
......@@ -271,7 +275,8 @@ namespace Sass {
has_backref(false),
from_variable(false),
should_eval(false),
is_unquoted(false),
is_unquoted(false), // for strings
is_quoted(false), // for identifiers -- yeah, it's hacky for now
has_been_extended(false)
{ }
......@@ -387,6 +392,7 @@ namespace Sass {
inline bool Node::from_variable() const { return ip_->from_variable; }
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_numeric() const { return ip_->is_numeric(); }
inline bool Node::is_guarded() const { return (type() == assignment) && (size() == 3); }
inline bool& Node::has_been_extended() const { return ip_->has_been_extended; }
......
......@@ -287,6 +287,12 @@ namespace Sass {
}
} break;
case identifier: {
string result(token().to_string());
if (is_quoted()) return "\"" + result + "\"";
else return result;
} break;
case boolean: {
if (boolean_value()) return "true";
else return "false";
......
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