Commit d7596999 by Aaron Leung

Working on selector combinators. Don't try to compile this.

parent 7fdf5765
a + b > c {
d e {
color: blue;
background: white;
}
color: red;
background: gray;
}
\ No newline at end of file
...@@ -47,8 +47,22 @@ namespace Sass { ...@@ -47,8 +47,22 @@ namespace Sass {
Node Document::parse_selector() Node Document::parse_selector()
{ {
Node selector(line_number, Node::selector, 1);
selector << parse_simple_selector_sequence();
while (lex< adjacent_to >() ||
lex< precedes >() ||
lex< parent_of >() ||
lex< sequence< ancestor_of, negate< exactly<'{'> > >()) {
selector << Node(line_number, Node::selector_combinator, lexed);
selector << parse_simple_selector_sequence();
}
return selector;
}
Node Document::parse_simple_selector_sequence()
{
lex<identifier>(); lex<identifier>();
return Node(line_number, Node::selector, lexed); return Node(line_number, Node::simple_selector_sequence, lexed);
} }
Node Document::parse_block() Node Document::parse_block()
......
...@@ -57,12 +57,10 @@ namespace Sass { ...@@ -57,12 +57,10 @@ namespace Sass {
} }
} }
void Node::emit_nested_css(stringstream& buf, void Node::emit_nested_css(stringstream& buf,
size_t depth, size_t depth,
const vector<string>& prefixes) const vector<string>& prefixes)
{ {
string indentation(2*depth, ' ');
switch (type) { switch (type) {
case ruleset: { case ruleset: {
Node sel_group(children->at(0)); Node sel_group(children->at(0));
...@@ -143,69 +141,6 @@ namespace Sass { ...@@ -143,69 +141,6 @@ namespace Sass {
} }
} }
// void Node::emit_nested_css(stringstream& buf,
// const string& prefix,
// size_t depth) {
// string indentation(2 * depth, ' ');
// vector<Node>* contents;
// if (type == ruleset) {
// Node block(children->at(1));
// contents = block.children;
// has_rules_or_comments = block.has_rules_or_comments;
// has_rulesets = block.has_rulesets;
// }
// switch (type) {
// case ruleset:
// if (has_rules_or_comments) {
// buf << indentation;
// children->at(0).emit_nested_css(buf, prefix, depth); // selector group
// buf << " {";
// for (int i = 0; i < contents->size(); ++i) {
// if (contents->at(i).type == comment || contents->at(i).type == rule) contents->at(i).emit_nested_css(buf, "", depth + 1); // rules
// }
// buf << " }" << endl;
// }
// if (has_rulesets) {
// for (int i = 0; i < contents->size(); ++i) { // do each nested ruleset
// if (contents->at(i).type == ruleset) contents->at(i).emit_nested_css(buf, prefix + (prefix.empty() ? "" : " ") + string((*children)[0].token), depth + (has_rules_or_comments ? 1 : 0));
// }
// }
// if (depth == 0 && prefix.empty()) buf << endl;
// break;
// case rule:
// buf << endl << indentation;
// children->at(0).emit_nested_css(buf, "", depth); // property
// children->at(1).emit_nested_css(buf, "", depth); // values
// buf << ";";
// break;
// case property:
// buf << string(token) << ":";
// break;
// case values:
// for (int i = 0; i < children->size(); ++i) {
// buf << " " << string((*children)[i].token);
// }
// break;
// case selector_group:
// children->at(0).emit_nested_css(buf, prefix, depth);
// for (int i = 1; i < children->size(); ++i) {
// children->at(i).emit_nested_css(buf, prefix, depth);
// }
// break;
// case selector:
// buf << prefix << (prefix.empty() ? "" : " ") << string(token);
// break;
// case comment:
// if (depth != 0) buf << endl;
// buf << indentation << string(token);
// if (depth == 0) buf << endl;
// break;
// }
// }
void Node::emit_expanded_css(stringstream& buf, const string& prefix) { void Node::emit_expanded_css(stringstream& buf, const string& prefix) {
// switch (type) { // switch (type) {
// case selector: // case selector:
......
...@@ -6,42 +6,6 @@ namespace Sass { ...@@ -6,42 +6,6 @@ namespace Sass {
using std::vector; using std::vector;
using std::stringstream; using std::stringstream;
// struct Node {
// enum Node_Type {
// nil,
// comment,
// ruleset,
// clauses,
// selector_group,
// selector,
// simple_selector_sequence,
// simple_selector,
// rule,
// property,
// values,
// value
// };
//
// static unsigned int fresh;
// static unsigned int copied;
//
// Node_Type type;
// Token token;
// vector<Node>* children;
// vector<Node>* opt_children;
//
// Node();
// Node(Node_Type _type);
// Node(Node_Type _type, Token& _token);
// Node(const Node& n);
//
// void push_child(const Node& node);
// void push_opt_child(const Node& node);
// void dump(unsigned int depth = 0);
// void emit_nested_css(stringstream& buf, const string& prefix, size_t depth);
// void emit_expanded_css(stringstream& buf, const string& prefix);
// };
struct Node { struct Node {
enum Type { enum Type {
nil, nil,
...@@ -50,6 +14,7 @@ namespace Sass { ...@@ -50,6 +14,7 @@ namespace Sass {
propset, propset,
selector_group, selector_group,
selector, selector,
selector_combinator,
simple_selector_sequence, simple_selector_sequence,
type_selector, type_selector,
class_selector, class_selector,
......
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