Commit 3663a724 by Aaron Leung

Working on namespaced properties. Still trying to get them to emit correctly.

parent ce72880f
...@@ -118,6 +118,7 @@ namespace Sass { ...@@ -118,6 +118,7 @@ namespace Sass {
Node parse_arguments(); Node parse_arguments();
Node parse_argument(); Node parse_argument();
Node parse_assignment(); Node parse_assignment();
Node parse_propset();
Node parse_ruleset(bool definition = false); Node parse_ruleset(bool definition = false);
Node parse_selector_group(); Node parse_selector_group();
Node parse_selector(); Node parse_selector();
......
...@@ -38,10 +38,9 @@ namespace Sass { ...@@ -38,10 +38,9 @@ namespace Sass {
root << parse_assignment(); root << parse_assignment();
if (!lex< exactly<';'> >()) syntax_error("top-level variable binding must be terminated by ';'"); if (!lex< exactly<';'> >()) syntax_error("top-level variable binding must be terminated by ';'");
} }
// else if (peek< sequence< identifier, optional_spaces, exactly<':'> > >(position)) { else if (peek< sequence< identifier, optional_spaces, exactly<':'>, optional_spaces, exactly<'{'> > >(position)) {
// root << parse_propset(); root << parse_propset();
// } }
// else if (look_for_selector_group(position)) {
else if (lookahead_for_selector(position)) { else if (lookahead_for_selector(position)) {
root << parse_ruleset(); root << parse_ruleset();
} }
...@@ -184,6 +183,29 @@ namespace Sass { ...@@ -184,6 +183,29 @@ namespace Sass {
assn << var << val; assn << var << val;
return assn; return assn;
} }
Node Document::parse_propset()
{
lex< identifier >();
Node property_segment(Node::identifier, line_number, lexed);
lex< exactly<':'> >();
lex< exactly<'{'> >();
Node block(Node::block, context.registry, line_number, 1);
while (!lex< exactly<'}'> >()) {
if (peek< sequence< identifier, optional_spaces, exactly<':'>, optional_spaces, exactly<'{'> > >(position)) {
block << parse_propset();
}
else {
block << parse_rule();
lex< exactly<';'> >();
}
}
if (block.size() == 0) syntax_error("namespaced property cannot be empty");
Node propset(Node::propset, context.registry, line_number, 2);
propset << property_segment;
propset << block;
return propset;
}
Node Document::parse_ruleset(bool definition) Node Document::parse_ruleset(bool definition)
{ {
...@@ -473,9 +495,10 @@ namespace Sass { ...@@ -473,9 +495,10 @@ namespace Sass {
block << parse_assignment(); block << parse_assignment();
semicolon = true; semicolon = true;
} }
// else if (peek< sequence< identifier, optional_spaces, exactly<':'> > >(position)) { else if (peek< sequence< identifier, optional_spaces, exactly<':'>, optional_spaces, exactly<'{'> > >(position)) {
// block << parse_propset(); block << parse_propset();
// } block[0].has_statements = true;
}
// else if (look_for_rule(position)) { // else if (look_for_rule(position)) {
// block << parse_rule(); // block << parse_rule();
// block.has_statements = true; // block.has_statements = true;
...@@ -485,7 +508,6 @@ namespace Sass { ...@@ -485,7 +508,6 @@ namespace Sass {
// block << parse_ruleset(); // block << parse_ruleset();
// block.has_blocks = true; // block.has_blocks = true;
// } // }
//else if (const char* p = look_for_selector_group(position)) {
else if (const char* p = lookahead_for_selector(position)) { else if (const char* p = lookahead_for_selector(position)) {
block << parse_ruleset(definition); block << parse_ruleset(definition);
block[0].has_blocks = true; block[0].has_blocks = true;
......
...@@ -443,9 +443,12 @@ namespace Sass { ...@@ -443,9 +443,12 @@ namespace Sass {
buf << " {"; buf << " {";
for (int i = 0; i < block.size(); ++i) { for (int i = 0; i < block.size(); ++i) {
Type stm_type = block[i].type; Type stm_type = block[i].type;
if (stm_type == comment || stm_type == rule || stm_type == css_import) { if (stm_type == comment || stm_type == rule || stm_type == css_import || stm_type == propset) {
block[i].emit_nested_css(buf, depth+1); // NEED OVERLOADED VERSION FOR COMMENTS AND RULES block[i].emit_nested_css(buf, depth+1); // NEED OVERLOADED VERSION FOR COMMENTS AND RULES
} }
// else if (stm_type == propset) {
// block[i].emit_nested_css(buf, depth, new_prefixes);
// }
} }
buf << " }" << endl; buf << " }" << endl;
++depth; // if we printed content at this level, we need to indent any nested rulesets ++depth; // if we printed content at this level, we need to indent any nested rulesets
...@@ -471,6 +474,23 @@ namespace Sass { ...@@ -471,6 +474,23 @@ namespace Sass {
{ {
switch (type) switch (type)
{ {
case propset: {
emit_propset(buf, depth, "");
// string prefix(string(2*depth, ' ') + at(0).content.token.to_string() + "-");
// Node rules(at(1));
// for (int i = 0; i < rules.size(); ++i) {
// buf << prefix;
// if (rules[i].type == propset) {
// rules[i].emit_nested_css(buf, depth+1);
// }
// else {
// rules[i][0].emit_nested_css(buf, depth);
// rules[i][1].emit_nested_css(buf, depth);
// buf << ';';
// }
// }
} break;
case rule: case rule:
buf << endl << string(2*depth, ' '); buf << endl << string(2*depth, ' ');
at(0).emit_nested_css(buf, depth); // property at(0).emit_nested_css(buf, depth); // property
...@@ -505,6 +525,26 @@ namespace Sass { ...@@ -505,6 +525,26 @@ namespace Sass {
break; break;
} }
} }
void Node::emit_propset(stringstream& buf, size_t depth, const string& prefix) {
string new_prefix(prefix);
if (new_prefix.empty()) new_prefix += "\n";
else new_prefix += "-";
new_prefix += at(0).content.token.to_string();
Node rules(at(1));
for (int i = 0; i < rules.size(); ++i) {
buf << new_prefix;
if (rules[i].type == propset) {
rules[i].emit_propset(buf, depth+1, new_prefix);
}
else {
rules[i][0].emit_nested_css(buf, depth);
rules[i][1].emit_nested_css(buf, depth);
buf << ';';
}
}
}
void Node::emit_expanded_css(stringstream& buf, const string& prefix) { void Node::emit_expanded_css(stringstream& buf, const string& prefix) {
// switch (type) { // switch (type) {
......
...@@ -210,6 +210,7 @@ namespace Sass { ...@@ -210,6 +210,7 @@ namespace Sass {
size_t depth, size_t depth,
const vector<string>& prefixes); const vector<string>& prefixes);
void emit_nested_css(stringstream& buf, size_t depth); void emit_nested_css(stringstream& buf, size_t depth);
void emit_propset(stringstream& buf, size_t depth, const string& prefix);
void emit_expanded_css(stringstream& buf, const string& prefix); void emit_expanded_css(stringstream& buf, const string& prefix);
Node clone(vector<vector<Node>*>& registry) const; Node clone(vector<vector<Node>*>& registry) 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