Commit 9bcf75f7 by Aaron Leung

Properly handling arbitrarily complicated args to :not. LET THIS BE THE END OF…

Properly handling arbitrarily complicated args to :not. LET THIS BE THE END OF SELECTOR PARSING (until interpolation).
parent ec60b24b
...@@ -110,6 +110,7 @@ namespace Sass { ...@@ -110,6 +110,7 @@ namespace Sass {
peek < exactly<'~'> >(position) || peek < exactly<'~'> >(position) ||
peek < exactly<'>'> >(position) || peek < exactly<'>'> >(position) ||
peek < exactly<','> >(position) || peek < exactly<','> >(position) ||
peek < exactly<')'> >(position) ||
peek < exactly<'{'> >(position))) { peek < exactly<'{'> >(position))) {
seq << parse_simple_selector(); seq << parse_simple_selector();
} }
...@@ -131,9 +132,9 @@ namespace Sass { ...@@ -131,9 +132,9 @@ namespace Sass {
Node Document::parse_pseudo() { Node Document::parse_pseudo() {
if (lex< pseudo_not >()) { if (lex< pseudo_not >()) {
Node ps_not(line_number, Node::functional_pseudo, 2); Node ps_not(line_number, Node::pseudo_negation, 2);
ps_not << Node(line_number, Node::value, lexed); ps_not << Node(line_number, Node::value, lexed);
ps_not << parse_simple_selector(); ps_not << parse_selector_group();
lex< exactly<')'> >(); lex< exactly<')'> >();
return ps_not; return ps_not;
} }
...@@ -227,7 +228,7 @@ namespace Sass { ...@@ -227,7 +228,7 @@ namespace Sass {
// block << parse_ruleset(); // block << parse_ruleset();
// block.has_rulesets = true; // block.has_rulesets = true;
// } // }
else if (look_for_selector_group(position)) { else if (const char* p = look_for_selector_group(position)) {
block << parse_ruleset(); block << parse_ruleset();
block.has_rulesets = true; block.has_rulesets = true;
} }
...@@ -270,27 +271,27 @@ namespace Sass { ...@@ -270,27 +271,27 @@ namespace Sass {
return values; return values;
} }
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;
(p = peek< identifier >(p)) && // (p = peek< identifier >(p)) &&
(p = peek< exactly<':'> >(p)) && // (p = peek< exactly<':'> >(p)) &&
(p = look_for_values(p)) && // (p = look_for_values(p)) &&
(p = peek< alternatives< exactly<';'>, exactly<'}'> > >(p)); // (p = peek< alternatives< exactly<';'>, exactly<'}'> > >(p));
return p; // return p;
} // }
//
const char* Document::look_for_values(const char* start) // const char* Document::look_for_values(const char* start)
{ // {
const char* p = start ? start : position; // const char* p = start ? start : position;
const char* q; // const char* q;
while ((q = peek< identifier >(p)) || (q = peek< dimension >(p)) || // while ((q = peek< identifier >(p)) || (q = peek< dimension >(p)) ||
(q = peek< percentage >(p)) || (q = peek< number >(p)) || // (q = peek< percentage >(p)) || (q = peek< number >(p)) ||
(q = peek< hex >(p)) || (q = peek< string_constant >(p)) || // (q = peek< hex >(p)) || (q = peek< string_constant >(p)) ||
(q = peek< variable >(p))) // (q = peek< variable >(p)))
{ p = q; } // { p = q; }
return p == start ? 0 : p; // return p == start ? 0 : p;
} // }
// NEW LOOKAHEAD FUNCTIONS. THIS ESSENTIALLY IMPLEMENTS A BACKTRACKING // NEW LOOKAHEAD FUNCTIONS. THIS ESSENTIALLY IMPLEMENTS A BACKTRACKING
// PARSER, BECAUSE SELECTORS AND VALUES ARE NOT EXPRESSIBLE IN A // PARSER, BECAUSE SELECTORS AND VALUES ARE NOT EXPRESSIBLE IN A
...@@ -306,7 +307,8 @@ namespace Sass { ...@@ -306,7 +307,8 @@ namespace Sass {
while ((q = peek< exactly<','> >(p)) && (q = look_for_selector(q))) while ((q = peek< exactly<','> >(p)) && (q = look_for_selector(q)))
{ p = q; } { p = q; }
return peek< exactly<'{'> >(p) ? p : 0; // return peek< exactly<'{'> >(p) ? p : 0;
return peek< alternatives< exactly<'{'>, exactly<')'> > >(p) ? p : 0;
} }
const char* Document::look_for_selector(const char* start) const char* Document::look_for_selector(const char* start)
...@@ -351,6 +353,7 @@ namespace Sass { ...@@ -351,6 +353,7 @@ namespace Sass {
peek < exactly<'~'> >(p) || peek < exactly<'~'> >(p) ||
peek < exactly<'>'> >(p) || peek < exactly<'>'> >(p) ||
peek < exactly<','> >(p) || peek < exactly<','> >(p) ||
peek < exactly<')'> >(p) ||
peek < exactly<'{'> >(p)) && peek < exactly<'{'> >(p)) &&
(q = look_for_simple_selector(p))) (q = look_for_simple_selector(p)))
{ p = q; } { p = q; }
...@@ -375,7 +378,8 @@ namespace Sass { ...@@ -375,7 +378,8 @@ namespace Sass {
const char* q; const char* q;
if (q = peek< pseudo_not >(p)) { if (q = peek< pseudo_not >(p)) {
(q = look_for_simple_selector(q)) && (q = peek< exactly<')'> >(q)); // (q = look_for_simple_selector(q)) && (q = peek< exactly<')'> >(q));
(q = look_for_selector_group(q)) && (q = peek< exactly<')'> >(q));
} }
else if (q = peek< sequence< pseudo_prefix, functional > >(p)) { else if (q = peek< sequence< pseudo_prefix, functional > >(p)) {
p = q; p = q;
...@@ -392,7 +396,6 @@ namespace Sass { ...@@ -392,7 +396,6 @@ namespace Sass {
else { else {
q = peek< sequence< pseudo_prefix, identifier > >(p); q = peek< sequence< pseudo_prefix, identifier > >(p);
} }
// cerr << "looked for a pseudo-thingie" << endl;
return q ? q : 0; return q ? q : 0;
} }
......
...@@ -148,7 +148,15 @@ namespace Sass { ...@@ -148,7 +148,15 @@ namespace Sass {
string to_string(const string& prefix) string to_string(const string& prefix)
{ {
if (type == selector) { 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; string result;
if (!has_backref && !prefix.empty()) { if (!has_backref && !prefix.empty()) {
result += prefix; result += prefix;
...@@ -177,6 +185,15 @@ namespace Sass { ...@@ -177,6 +185,15 @@ namespace Sass {
} }
return result; 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) { else if (type == functional_pseudo) {
string result(children->at(0).to_string(prefix)); string result(children->at(0).to_string(prefix));
for (int i = 1; i < children->size(); ++i) { for (int i = 1; i < children->size(); ++i) {
......
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