Commit c7f07857 by Aaron Leung

Implemented string interpolation.

parent d1dd655c
...@@ -848,15 +848,19 @@ namespace Sass { ...@@ -848,15 +848,19 @@ namespace Sass {
while (i < str.end) { while (i < str.end) {
p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly<hash_lbrace> > >(i, str.end); p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly<hash_lbrace> > >(i, str.end);
if (p) { if (p) {
if (i < p) schema << Node(Node::identifier, line_number, Token::make(i, p)); // accumulate the preceding segment if it's nonempty if (i < p) {
schema << Node(Node::identifier, line_number, Token::make(i, p-2)); // accumulate the preceding segment if it's nonempty
// cerr << '[' << Token::make(i,p-2).to_string() << ']' << endl;
}
const char* j = find_first_in_interval< exactly<rbrace> >(p, str.end); // find the closing brace const char* j = find_first_in_interval< exactly<rbrace> >(p, str.end); // find the closing brace
if (j) { if (j) {
// parse the interpolant and accumulate it // parse the interpolant and accumulate it
Document interp_doc(path, line_number, Token::make(p+2,j-1), context); // cerr << '[' << Token::make(p, j-1).to_string() << ']' << endl;
Document interp_doc(path, line_number, Token::make(p,j-1), context);
Node interp_node(interp_doc.parse_list()); Node interp_node(interp_doc.parse_list());
interp_node.eval_me = true; interp_node.eval_me = true;
schema << interp_node; schema << interp_node;
i = j + 1; i = j;
} }
else { else {
// throw an error if the interpolant is unterminated // throw an error if the interpolant is unterminated
......
...@@ -325,7 +325,15 @@ namespace Sass { ...@@ -325,7 +325,15 @@ namespace Sass {
case string_schema: { case string_schema: {
string result; string result;
for (size_t i = 0; i < size(); ++i) result += at(i).to_string(""); for (size_t i = 0; i < size(); ++i) {
string chunk(at(i).to_string(""));
if (at(i).type == string_constant) {
result += chunk.substr(1, chunk.size()-2);
}
else {
result += chunk;
}
}
return result; return result;
} 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