Commit b9cfc227 by Aaron Leung

Properly handling selector combinators. Had to account for some subtleties in…

Properly handling selector combinators. Had to account for some subtleties in lexing significant whitespace.
parent d7596999
......@@ -64,7 +64,10 @@ namespace Sass {
after_whitespace =
zero_plus< alternatives<spaces, line_comment> >(position);
}
else if (mx == spaces || mx == ancestor_of) {
else if (mx == ancestor_of) {
after_whitespace = position;
}
else if (mx == spaces) {
after_whitespace = spaces(position);
if (after_whitespace) {
line_number += count_interval<'\n'>(position, after_whitespace);
......@@ -91,50 +94,13 @@ namespace Sass {
return 0;
}
}
// template <prelexer mx>
// bool lex() {
// char* after_whitespace;
// if (mx == block_comment) {
// after_whitespace =
// zero_plus< alternatives<spaces, line_comment> >(position);
// }
// else if (mx == spaces || mx == ancestor_of) {
// after_whitespace = spaces(position);
// if (after_whitespace) {
// lexed = Token(position, after_whitespace);
// line_number += count_interval<'\n'>(position, after_whitespace);
// position = after_whitespace;
// return true;
// }
// else {
// return false;
// }
// }
// else if (mx == optional_spaces) {
// after_whitespace = optional_spaces(position);
// }
// else {
// after_whitespace = spaces_and_comments(position);
// }
// line_number += count_interval<'\n'>(position, after_whitespace);
// char* after_token = mx(after_whitespace);
// if (after_token) {
// lexed = Token(after_whitespace, after_token);
// position = after_token;
// return true;
// }
// else {
// return false;
// }
// }
void parse_scss();
// Node parse_statement();
void parse_var_def();
Node parse_ruleset();
Node parse_selector_group();
Node parse_selector();
Node parse_simple_selector_sequence();
Node parse_block();
Node parse_rule();
Node parse_values();
......
......@@ -49,10 +49,10 @@ namespace Sass {
{
Node selector(line_number, Node::selector, 1);
selector << parse_simple_selector_sequence();
while (lex< adjacent_to >() ||
lex< precedes >() ||
lex< parent_of >() ||
lex< sequence< ancestor_of, negate< exactly<'{'> > >()) {
while (lex< exactly<'+'> >() ||
lex< exactly<'~'> >() ||
lex< exactly<'>'> >() ||
lex< ancestor_of >()) {
selector << Node(line_number, Node::selector_combinator, lexed);
selector << parse_simple_selector_sequence();
}
......
#include <iostream>
#include <string>
#include <cctype>
#include "node.hpp"
using std::string;
......@@ -31,6 +32,15 @@ namespace Sass {
}
break;
case selector:
for (int i = 0; i < children->size(); ++i) {
children->at(i).echo(buf, depth);
}
break;
case selector_combinator:
if (std::isspace(token.begin[0])) buf << ' ';
else buf << ' ' << string(token) << ' ';
break;
case simple_selector_sequence:
buf << string(token);
break;
case block:
......
......@@ -3,6 +3,7 @@
#include "token.hpp"
namespace Sass {
using std::string;
using std::vector;
using std::stringstream;
......
......@@ -148,7 +148,7 @@ namespace Sass {
return sequence< optional_spaces, exactly<'>'> >(src);
}
char* ancestor_of(char* src) {
return spaces(src);
return sequence< spaces, negate< exactly<'{'> > >(src);
}
// Match SCSS variable names.
......
......@@ -49,6 +49,8 @@ char nonhex1[] = "#ab blah";
char nonhex2[] = "#abc123blah";
char var1[] = "$hello blah";
char nonvar1[] = "$ hello";
char anc1[] = " div {";
char nonanc1[] = " { blah";
extern const char slash_star[] = "/*";
......@@ -59,6 +61,8 @@ void try_and_set(char* src) {
if (p) ptr = mx;
}
prelexer ancestor = sequence< ancestor_of, negate< exactly<'{'> > >;
int main() {
......@@ -91,6 +95,7 @@ int main() {
check_twice(hex, hex1, nonhex1);
check_twice(hex, hex2, nonhex2);
check_twice(variable, var1, nonvar1);
check_twice(ancestor_of, anc1, nonanc1);
cout << count_interval<'\n'>(ws1, spaces_and_comments(ws1)) << endl;
cout << count_interval<'*'>(ws1, spaces_and_comments(ws1)) << endl;
cout << count_interval<exactly<slash_star> >(ws1, spaces_and_comments(ws1)) << endl;
......
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