Commit 929307e8 by Aaron Leung

Fixing some quoting/unquoting and equality stuff.

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