Commit 98f66158 by Aaron Leung

Workin' on the node struct.

parent 483fab5c
......@@ -92,31 +92,35 @@ namespace Sass {
string indentation(2 * depth, ' ');
bool has_rules, has_nested_rulesets;
if (type == ruleset) {
has_rules = !((*children)[1].children->empty());
has_nested_rulesets = !((*children)[1].opt_children->empty());
// has_rules = !((*children)[1].children->empty());
has_rules = !(children->at(1).children->empty());
// has_nested_rulesets = !((*children)[1].opt_children->empty());
has_nested_rulesets = !(children->at(1).opt_children->empty());
}
switch (type) {
case ruleset:
if (has_rules) {
buf << indentation;
(*children)[0].emit_nested_css(buf, prefix, depth); // selector
// (*children)[0].emit_nested_css(buf, prefix, depth); // selector
children->at(0).emit_nested_css(buf, prefix, depth); // selector
buf << " {";
for (int i = 0; i < (*children)[1].children->size(); ++i) {
(*(*children)[1].children)[i].emit_nested_css(buf, "", depth + 1); // rules
// (*(*children)[1].children)[i].emit_nested_css(buf, "", depth + 1); // rules
children->at(1).children->at(i).emit_nested_css(buf, "", depth + 1); // rules
}
buf << " }" << endl;
}
if (has_nested_rulesets) {
for (int i = 0; i < (*children)[1].opt_children->size(); ++i) { // do each nested ruleset
(*(*children)[1].opt_children)[i].emit_nested_css(buf, prefix + (prefix.empty() ? "" : " ") + string((*children)[0].token), depth + (has_rules ? 1 : 0));
for (int i = 0; i < children->at(1).opt_children->size(); ++i) { // do each nested ruleset
children->at(1).opt_children->at(i).emit_nested_css(buf, prefix + (prefix.empty() ? "" : " ") + string((*children)[0].token), depth + (has_rules ? 1 : 0));
}
}
if (depth == 0 && prefix.empty()) buf << endl;
break;
case rule:
buf << endl << indentation;
(*children)[0].emit_nested_css(buf, "", depth); // property
(*children)[1].emit_nested_css(buf, "", depth); // values
children->at(0).emit_nested_css(buf, "", depth); // property
children->at(1).emit_nested_css(buf, "", depth); // values
buf << ";";
break;
case property:
......
......@@ -42,44 +42,66 @@ namespace Sass {
void emit_expanded_css(stringstream& buf, const string& prefix);
};
// struct Node {
// enum Type {
// nil,
// comment,
// ruleset,
// selector_group,
// selector,
// simple_selector_sequence,
// type_selector,
// class_selector,
// id_selector,
// attribute_selector,
// clauses,
// rule,
// property,
// values,
// value
// };
//
struct Node {
enum Type {
nil,
comment,
ruleset,
selector_group,
selector,
simple_selector_sequence,
type_selector,
class_selector,
id_selector,
attribute_selector,
clauses,
rule,
property,
values,
value
};
// size_t line_number;
// mutable vector<Node>* children;
// Token token;
// Type type;
// bool has_rules;
// bool has_rulesets;
// Type type;
// Token token;
// vector<Node>* children;
// bool has_nested_properties;
//
// Node(const Node& n)
// : has_rules(n.has_rules), has_rulesets(n.has_rulesets),
// type(n.type), token(n.token), children(n.children)
// { n.children = 0; } // No joint custody.
// Node(Type type_)
// : has_rules(false), has_rulesets(false),
// type(type_), token(Token()), children(0)
// : line_number(n.line_number),
// children(n.children),
// token(n.token),
// type(n.type),
// has_rules(n.has_rules),
// has_rulesets(n.has_rulesets),
// has_nested_properties(n.has_nested_properties)
// { n.release(); } // No joint custody.
//
// Node(size_t line_number, Type type, size_t length = 0)
// : line_number(line_number),
// children(new vector<Node>),
// token(Token()),
// type(type),
// has_rules(false),
// has_rulesets(false),
// has_nested_properties(false)
// { children->reserve(length); }
//
// Node(size_t line_number, Type type, Token& token)
// : line_number(line_number),
// children(0),
// token(token),
// type(type),
// has_rules(false),
// has_rulesets(false),
// has_nested_properties(false)
// { }
// Node(Type type_, size_t size);
// Node(Type type_, Token& token_);
//
// Node& operator=(const Node& node);
// Node& operator+=(const Node& node);
// Node& operator<<(const Node& node);
// void release() const { children = 0; }
// };
}
\ No newline at end of file
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