Commit cb03bb0b by Aaron Leung

Working on getting expressions to print out. Next step is evaluation.

parent 7ca92b95
...@@ -304,7 +304,8 @@ namespace Sass { ...@@ -304,7 +304,8 @@ namespace Sass {
// if it's a singleton, return it directly; don't wrap it // if it's a singleton, return it directly; don't wrap it
if (peek< exactly<';'> >(position) || if (peek< exactly<';'> >(position) ||
peek< exactly<'}'> >(position) || peek< exactly<'}'> >(position) ||
peek< exactly<')'> >(position)) peek< exactly<')'> >(position) ||
peek< exactly<','> >(position))
{ return expr1; } { return expr1; }
Node space_list(line_number, Node::space_list, 2); Node space_list(line_number, Node::space_list, 2);
...@@ -312,7 +313,8 @@ namespace Sass { ...@@ -312,7 +313,8 @@ namespace Sass {
while (!(peek< exactly<';'> >(position) || while (!(peek< exactly<';'> >(position) ||
peek< exactly<'}'> >(position) || peek< exactly<'}'> >(position) ||
peek< exactly<')'> >(position))) peek< exactly<')'> >(position) ||
peek< exactly<','> >(position)))
{ space_list << parse_expression(); } { space_list << parse_expression(); }
return space_list; return space_list;
...@@ -393,13 +395,6 @@ namespace Sass { ...@@ -393,13 +395,6 @@ namespace Sass {
} }
} }
// const char* Document::look_for_rule(const char* start) // const char* Document::look_for_rule(const char* start)
// { // {
// const char* p = start ? start : position; // const char* p = start ? start : position;
......
$x: 1 2 3; $x: 1 2 3;
div { div {
a: 42 $x 43;
b: 1, 2 3, 4;
c: 1/2;
d: (10px/3em);
d: (10 / 5px);
}
/*div {
a: a, b, c, d; a: a, b, c, d;
b: a b, c d; b: a b, c d;
c: a (b, c) d; c: a (b, c) d;
...@@ -11,3 +22,4 @@ div { ...@@ -11,3 +22,4 @@ div {
i: 4 - (2) 3; i: 4 - (2) 3;
j: 3 + $x; j: 3 + $x;
} }
*/
\ No newline at end of file
...@@ -13,6 +13,108 @@ namespace Sass { ...@@ -13,6 +13,108 @@ namespace Sass {
size_t Node::fresh = 0; size_t Node::fresh = 0;
size_t Node::copied = 0; size_t Node::copied = 0;
string Node::to_string(const string& prefix)
{
switch (type)
{
case selector_group: { // really only needed for arg to :not
string result(children->at(0).to_string(""));
for (int i = 1; i < children->size(); ++i) {
result += ", ";
result += children->at(i).to_string("");
}
return result;
} break;
case selector: {
string result;
if (!has_backref && !prefix.empty()) {
result += prefix;
result += ' ';
}
if (children->at(0).type == selector_combinator) {
result += string(children->at(0).token);
result += ' ';
}
else {
result += children->at(0).to_string(prefix);
}
for (int i = 1; i < children->size(); ++i) {
result += children->at(i).to_string(prefix);
}
return result;
} break;
case selector_combinator: {
if (std::isspace(token.begin[0])) return string(" ");
else return string(" ") += string(token) += string(" ");
} break;
case simple_selector_sequence: {
string result;
for (int i = 0; i < children->size(); ++i) {
result += children->at(i).to_string(prefix);
}
return result;
} break;
case pseudo_negation: {
string result(children->at(0).to_string(prefix));
result += children->at(1).to_string(prefix);
result += ')';
return result;
} break;
case functional_pseudo: {
string result(children->at(0).to_string(prefix));
for (int i = 1; i < children->size(); ++i) {
result += children->at(i).to_string(prefix);
}
result += ')';
return result;
} break;
case attribute_selector: {
string result("[");
result += children->at(0).to_string(prefix);
result += children->at(1).to_string(prefix);
result += children->at(2).to_string(prefix);
result += ']';
return result;
} break;
case backref: {
return prefix;
} break;
case comma_list: {
string result(children->at(0).to_string(prefix));
for (int i = 1; i < children->size(); ++i) {
result += ", ";
result += children->at(i).to_string(prefix);
}
return result;
} break;
case space_list: {
string result(children->at(0).to_string(prefix));
for (int i = 1; i < children->size(); ++i) {
result += " ";
result += children->at(i).to_string(prefix);
}
return result;
} break;
case value: {
return string(token);
} break;
default: {
// return string(token);
} break;
}
}
void Node::echo(stringstream& buf, size_t depth) { void Node::echo(stringstream& buf, size_t depth) {
string indentation(2*depth, ' '); string indentation(2*depth, ' ');
switch (type) { switch (type) {
...@@ -56,7 +158,7 @@ namespace Sass { ...@@ -56,7 +158,7 @@ namespace Sass {
case rule: case rule:
buf << indentation; buf << indentation;
children->at(0).echo(buf, depth); children->at(0).echo(buf, depth);
buf << ':'; buf << ": ";
children->at(1).echo(buf, depth); children->at(1).echo(buf, depth);
buf << ';' << endl; buf << ';' << endl;
break; break;
...@@ -142,7 +244,7 @@ namespace Sass { ...@@ -142,7 +244,7 @@ namespace Sass {
buf << ";"; buf << ";";
break; break;
case property: case property:
buf << string(token) << ":"; buf << string(token) << ": ";
break; break;
case values: case values:
for (int i = 0; i < children->size(); ++i) { for (int i = 0; i < children->size(); ++i) {
...@@ -155,6 +257,7 @@ namespace Sass { ...@@ -155,6 +257,7 @@ namespace Sass {
if (depth == 0) buf << endl; if (depth == 0) buf << endl;
break; break;
default: default:
buf << to_string("");
break; break;
} }
} }
......
...@@ -155,77 +155,7 @@ namespace Sass { ...@@ -155,77 +155,7 @@ namespace Sass {
return *this; return *this;
} }
string to_string(const string& prefix) string to_string(const string& prefix);
{
if (type == selector_group) { // really only needed for arg to :not
string result(children->at(0).to_string(""));
for (int i = 1; i < children->size(); ++i) {
result += ", ";
result += children->at(i).to_string("");
}
return result;
}
else if (type == selector) {
string result;
if (!has_backref && !prefix.empty()) {
result += prefix;
result += ' ';
}
if (children->at(0).type == selector_combinator) {
result += string(children->at(0).token);
result += ' ';
}
else {
result += children->at(0).to_string(prefix);
}
for (int i = 1; i < children->size(); ++i) {
result += children->at(i).to_string(prefix);
}
return result;
}
else if (type == selector_combinator) {
if (std::isspace(token.begin[0])) return string(" ");
else return string(" ") += string(token) += string(" ");
}
else if (type == simple_selector_sequence) {
string result;
for (int i = 0; i < children->size(); ++i) {
result += children->at(i).to_string(prefix);
}
return result;
}
else if (type == pseudo_negation) {
string result(children->at(0).to_string(prefix));
result += children->at(1).to_string(prefix);
// for (int i = 1; i < children->size(); ++i) {
// result += children->at(i).to_string("");
// }
result += ')';
return result;
}
else if (type == functional_pseudo) {
string result(children->at(0).to_string(prefix));
for (int i = 1; i < children->size(); ++i) {
result += children->at(i).to_string(prefix);
}
result += ')';
return result;
}
else if (type == attribute_selector) {
string result("[");
result += children->at(0).to_string(prefix);
result += children->at(1).to_string(prefix);
result += children->at(2).to_string(prefix);
result += ']';
return result;
}
else if (type == backref) {
return prefix;
}
else {
return string(token);
}
}
void release() const { children = 0; } void release() const { children = 0; }
......
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