Commit b0693709 by Aaron Leung

Implemented the "quote" and "unquote" builtins.

parent ac99e122
......@@ -41,6 +41,9 @@ namespace Sass {
register_function(mix_3_descriptor, mix_3);
// HSL Functions
register_function(invert_descriptor, invert);
// String Functions
register_function(unquote_descriptor, unquote);
register_function(quote_descriptor, quote);
}
}
\ No newline at end of file
......@@ -102,10 +102,25 @@ namespace Sass {
orig[3].content.numeric_value);
}
// String Functions ////////////////////////////////////////////////////
Function_Descriptor unquote_descriptor =
{ "unquote", "$string", 0 };
Node unquote(const vector<Token>& parameters, map<Token, Node>& bindings) {
Node cpy(bindings[parameters[0]].clone());
cpy.unquoted = true;
return cpy;
}
Function_Descriptor quote_descriptor =
{ "quote", "$string", 0 };
Node quote(const vector<Token>& parameters, map<Token, Node>& bindings) {
Node cpy(bindings[parameters[0]].clone());
// check the types -- will probably be an identifier
cpy.type = Node::string_constant;
cpy.unquoted = false;
return cpy;
}
......
......@@ -43,6 +43,7 @@ namespace Sass {
};
namespace Functions {
// RGB Functions ///////////////////////////////////////////////////////
extern Function_Descriptor rgb_descriptor;
Node rgb(const vector<Token>& parameters, map<Token, Node>& bindings);
......@@ -67,8 +68,16 @@ namespace Sass {
extern Function_Descriptor mix_3_descriptor;
Node mix_3(const vector<Token>& parameters, map<Token, Node>& bindings);
// HSL Functions ///////////////////////////////////////////////////////
extern Function_Descriptor invert_descriptor;
Node invert(const vector<Token>& parameters, map<Token, Node>& bindings);
// String Functions ////////////////////////////////////////////////////
extern Function_Descriptor unquote_descriptor;
Node unquote(const vector<Token>& parameters, map<Token, Node>& bindings);
extern Function_Descriptor quote_descriptor;
Node quote(const vector<Token>& parameters, map<Token, Node>& bindings);
}
}
......@@ -220,7 +220,16 @@ namespace Sass {
// string result("MIXIN CALL: ");
// return result;
// } break;
case string_constant: {
if (unquoted) return content.token.unquote();
else {
string result(content.token.to_string());
if (result[0] != '"' && result[0] != '\'') return "\"" + result + "\"";
else return result;
}
} break;
default: {
// return content.token.to_string();
if (!has_children && type != flags) return content.token.to_string();
......
......@@ -87,6 +87,7 @@ namespace Sass {
bool has_backref;
bool from_variable;
bool eval_me;
bool unquoted;
union {
Token token;
......@@ -102,6 +103,7 @@ namespace Sass {
type = none; line_number = 0; has_children = false;
has_statements = false; has_blocks = false; has_expansions = false;
has_backref = false; from_variable = false; eval_me = false;
unquoted = false;
}
size_t size() const
......
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