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 { ...@@ -32,7 +32,10 @@ namespace Sass {
after_whitespace = after_whitespace =
zero_plus< alternatives<spaces, line_comment> >(start); 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); after_whitespace = spaces(start);
if (after_whitespace) { if (after_whitespace) {
return after_whitespace; return after_whitespace;
...@@ -64,7 +67,7 @@ namespace Sass { ...@@ -64,7 +67,7 @@ namespace Sass {
after_whitespace = after_whitespace =
zero_plus< alternatives<spaces, line_comment> >(position); zero_plus< alternatives<spaces, line_comment> >(position);
} }
else if (mx == ancestor_of) { else if (mx == ancestor_of || mx == no_spaces) {
after_whitespace = position; after_whitespace = position;
} }
else if (mx == spaces) { else if (mx == spaces) {
...@@ -101,6 +104,7 @@ namespace Sass { ...@@ -101,6 +104,7 @@ namespace Sass {
Node parse_selector_group(); Node parse_selector_group();
Node parse_selector(); Node parse_selector();
Node parse_simple_selector_sequence(); Node parse_simple_selector_sequence();
Node parse_simple_selector();
Node parse_block(); Node parse_block();
Node parse_rule(); Node parse_rule();
Node parse_values(); Node parse_values();
......
...@@ -36,7 +36,7 @@ namespace Sass { ...@@ -36,7 +36,7 @@ namespace Sass {
ruleset << parse_block(); ruleset << parse_block();
return ruleset; return ruleset;
} }
Node Document::parse_selector_group() Node Document::parse_selector_group()
{ {
Node group(line_number, Node::selector_group, 1); Node group(line_number, Node::selector_group, 1);
...@@ -63,11 +63,32 @@ namespace Sass { ...@@ -63,11 +63,32 @@ namespace Sass {
} }
return selector; return selector;
} }
Node Document::parse_simple_selector_sequence() Node Document::parse_simple_selector_sequence()
{ {
lex<identifier>(); Node sequence(line_number, Node::simple_selector_sequence, 1);
return Node(line_number, Node::simple_selector_sequence, lexed); 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() Node Document::parse_block()
...@@ -103,7 +124,7 @@ namespace Sass { ...@@ -103,7 +124,7 @@ namespace Sass {
} }
return block; return block;
} }
Node Document::parse_rule() { Node Document::parse_rule() {
Node rule(line_number, Node::rule, 2); Node rule(line_number, Node::rule, 2);
lex< identifier >(); lex< identifier >();
...@@ -132,7 +153,7 @@ namespace Sass { ...@@ -132,7 +153,7 @@ namespace Sass {
} }
return values; return values;
} }
char* Document::look_for_rule(char* start) char* Document::look_for_rule(char* start)
{ {
char* p = start ? start : position; char* p = start ? start : position;
...@@ -142,7 +163,7 @@ namespace Sass { ...@@ -142,7 +163,7 @@ namespace Sass {
(p = peek< alternatives< exactly<';'>, exactly<'}'> > >(p)); (p = peek< alternatives< exactly<';'>, exactly<'}'> > >(p));
return p; return p;
} }
char* Document::look_for_values(char* start) char* Document::look_for_values(char* start)
{ {
char* p = start ? start : position; char* p = start ? start : position;
......
...@@ -41,6 +41,11 @@ namespace Sass { ...@@ -41,6 +41,11 @@ namespace Sass {
else buf << ' ' << string(token) << ' '; else buf << ' ' << string(token) << ' ';
break; break;
case simple_selector_sequence: case simple_selector_sequence:
for (int i = 0; i < children->size(); ++i) {
buf << string(children->at(i));
}
break;
case simple_selector:
buf << string(token); buf << string(token);
break; break;
case block: case block:
...@@ -80,7 +85,6 @@ namespace Sass { ...@@ -80,7 +85,6 @@ namespace Sass {
if (prefixes.empty()) { if (prefixes.empty()) {
new_prefixes.reserve(sel_group.children->size()); new_prefixes.reserve(sel_group.children->size());
for (int i = 0; i < sel_group.children->size(); ++i) { 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))); new_prefixes.push_back(string(sel_group.children->at(i)));
} }
} }
......
...@@ -17,6 +17,7 @@ namespace Sass { ...@@ -17,6 +17,7 @@ namespace Sass {
selector, selector,
selector_combinator, selector_combinator,
simple_selector_sequence, simple_selector_sequence,
simple_selector,
type_selector, type_selector,
class_selector, class_selector,
id_selector, id_selector,
...@@ -112,7 +113,6 @@ namespace Sass { ...@@ -112,7 +113,6 @@ namespace Sass {
return *this; return *this;
} }
// Node& operator+=(const Node& node);
Node& operator<<(const Node& n) Node& operator<<(const Node& n)
{ {
children->push_back(n); children->push_back(n);
...@@ -137,9 +137,13 @@ namespace Sass { ...@@ -137,9 +137,13 @@ namespace Sass {
if (std::isspace(token.begin[0])) return string(" "); if (std::isspace(token.begin[0])) return string(" ");
else return string(" ") += string(token) += string(" "); else return string(" ") += string(token) += string(" ");
} }
// else if (type == simple_selector_sequence) { else if (type == simple_selector_sequence) {
// return string(" ") += string(token); string result;
// } for (int i = 0; i < children->size(); ++i) {
result += string(children->at(i));
}
return result;
}
else { else {
return string(token); return string(token);
} }
......
...@@ -64,6 +64,9 @@ namespace Sass { ...@@ -64,6 +64,9 @@ namespace Sass {
char* spaces_and_comments(char* src) { char* spaces_and_comments(char* src) {
return zero_plus< alternatives<spaces, comment> >(src); return zero_plus< alternatives<spaces, comment> >(src);
} }
char* no_spaces(char *src) {
return negate< spaces >(src);
}
// Match CSS identifiers. // Match CSS identifiers.
char* identifier(char* src) { char* identifier(char* src) {
...@@ -82,6 +85,17 @@ namespace Sass { ...@@ -82,6 +85,17 @@ namespace Sass {
exactly<'-'>, exactly<'-'>,
exactly<'_'> > >(src); 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. // Match CSS id names.
char* id_name(char* src) { char* id_name(char* src) {
return sequence<exactly<'#'>, name>(src); return sequence<exactly<'#'>, name>(src);
......
...@@ -214,11 +214,16 @@ namespace Sass { ...@@ -214,11 +214,16 @@ namespace Sass {
char* optional_spaces(char* src); char* optional_spaces(char* src);
char* optional_comment(char* src); char* optional_comment(char* src);
char* spaces_and_comments(char* src); char* spaces_and_comments(char* src);
char* no_spaces(char *src);
// Match a CSS identifier. // Match a CSS identifier.
char* identifier(char* src); char* identifier(char* src);
// Match CSS '@' keywords. // Match CSS '@' keywords.
char* at_keyword(char* src); 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. // Match CSS id names.
char* id_name(char* src); char* id_name(char* src);
// Match CSS class names. // 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