Commit a5080f4e by Aaron Leung

Handling class/id selectors, as well as simple selector sequences consisting of such.

parent 34cb35fd
a + b, .class {
blah: blah;
bleh: bleh;
d #id, f ~ g.other + h, > i#grar {
bloo: bloo;
blee: blee;
}
}
\ No newline at end of file
......@@ -32,7 +32,10 @@ namespace Sass {
after_whitespace =
zero_plus< alternatives<spaces, line_comment> >(start);
}
else if (mx == spaces || mx == ancestor_of) {
else if (mx == ancestor_of || mx == no_spaces) {
after_whitespace = position;
}
else if (mx == spaces) {
after_whitespace = spaces(start);
if (after_whitespace) {
return after_whitespace;
......@@ -64,7 +67,7 @@ namespace Sass {
after_whitespace =
zero_plus< alternatives<spaces, line_comment> >(position);
}
else if (mx == ancestor_of) {
else if (mx == ancestor_of || mx == no_spaces) {
after_whitespace = position;
}
else if (mx == spaces) {
......@@ -101,6 +104,7 @@ namespace Sass {
Node parse_selector_group();
Node parse_selector();
Node parse_simple_selector_sequence();
Node parse_simple_selector();
Node parse_block();
Node parse_rule();
Node parse_values();
......
......@@ -66,8 +66,29 @@ namespace Sass {
Node Document::parse_simple_selector_sequence()
{
lex<identifier>();
return Node(line_number, Node::simple_selector_sequence, lexed);
Node sequence(line_number, Node::simple_selector_sequence, 1);
if (lex< alternatives < type_selector, universal > >()) {
sequence << Node(line_number, Node::simple_selector, lexed);
}
else {
sequence << parse_simple_selector();
}
while (!peek< spaces >(position) &&
!(peek < exactly<'+'> >(position) ||
peek < exactly<'~'> >(position) ||
peek < exactly<'>'> >(position) ||
peek < exactly<','> >(position) ||
peek < exactly<'{'> >(position))) {
sequence << parse_simple_selector();
}
return sequence;
}
Node Document::parse_simple_selector()
{
lex< id_name >() || lex< class_name >() /*|| lex< attribute >() ||
lex< pseudo >() || lex< negation >()*/ ;
return Node(line_number, Node::simple_selector, lexed);
}
Node Document::parse_block()
......
......@@ -41,6 +41,11 @@ namespace Sass {
else buf << ' ' << string(token) << ' ';
break;
case simple_selector_sequence:
for (int i = 0; i < children->size(); ++i) {
buf << string(children->at(i));
}
break;
case simple_selector:
buf << string(token);
break;
case block:
......@@ -80,7 +85,6 @@ namespace Sass {
if (prefixes.empty()) {
new_prefixes.reserve(sel_group.children->size());
for (int i = 0; i < sel_group.children->size(); ++i) {
// new_prefixes.push_back(string(sel_group.children->at(i).token));
new_prefixes.push_back(string(sel_group.children->at(i)));
}
}
......
......@@ -17,6 +17,7 @@ namespace Sass {
selector,
selector_combinator,
simple_selector_sequence,
simple_selector,
type_selector,
class_selector,
id_selector,
......@@ -112,7 +113,6 @@ namespace Sass {
return *this;
}
// Node& operator+=(const Node& node);
Node& operator<<(const Node& n)
{
children->push_back(n);
......@@ -137,9 +137,13 @@ namespace Sass {
if (std::isspace(token.begin[0])) return string(" ");
else return string(" ") += string(token) += string(" ");
}
// else if (type == simple_selector_sequence) {
// return string(" ") += string(token);
// }
else if (type == simple_selector_sequence) {
string result;
for (int i = 0; i < children->size(); ++i) {
result += string(children->at(i));
}
return result;
}
else {
return string(token);
}
......
......@@ -64,6 +64,9 @@ namespace Sass {
char* spaces_and_comments(char* src) {
return zero_plus< alternatives<spaces, comment> >(src);
}
char* no_spaces(char *src) {
return negate< spaces >(src);
}
// Match CSS identifiers.
char* identifier(char* src) {
......@@ -82,6 +85,17 @@ namespace Sass {
exactly<'-'>,
exactly<'_'> > >(src);
}
// Match CSS type selectors
char* namespace_prefix(char* src) {
return sequence< optional< alternatives< identifier, exactly<'*'> > >,
exactly<'|'> >(src);
}
char* type_selector(char* src) {
return sequence< optional<namespace_prefix>, identifier>(src);
}
char* universal(char* src) {
return sequence< optional<namespace_prefix>, exactly<'*'> >(src);
}
// Match CSS id names.
char* id_name(char* src) {
return sequence<exactly<'#'>, name>(src);
......
......@@ -214,11 +214,16 @@ namespace Sass {
char* optional_spaces(char* src);
char* optional_comment(char* src);
char* spaces_and_comments(char* src);
char* no_spaces(char *src);
// Match a CSS identifier.
char* identifier(char* src);
// Match CSS '@' keywords.
char* at_keyword(char* src);
// Match CSS type selectors
char* namespace_prefix(char* src);
char* type_selector(char* src);
char* universal(char* src);
// Match CSS id names.
char* id_name(char* src);
// Match CSS class names.
......
a + b, .class {
blah: blah;
bleh: bleh;
d #id, f ~ g.other + h, > i#grar {
bloo: bloo;
blee: blee;
}
}
\ No newline at end of file
a + b, .class {
blah: blah;
bleh: bleh; }
a + b d #id, a + b f ~ g.other + h, a + b > i#grar, .class d #id, .class f ~ g.other + h, .class > i#grar {
bloo: bloo;
blee: blee; }
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