Commit 66a0b283 by Aaron Leung

Working on @while. Need to redo environment handling.

parent a78ca00a
...@@ -163,7 +163,8 @@ namespace Sass { ...@@ -163,7 +163,8 @@ namespace Sass {
Node parse_if_directive(Node surrounding_ruleset); Node parse_if_directive(Node surrounding_ruleset);
Node parse_for_directive(Node surrounding_ruleset); Node parse_for_directive(Node surrounding_ruleset);
Node parse_each_directive(Node surrounding_ruleset); Node parse_each_directive(Node surrounding_ruleset);
Node parse_while_directive(Node surrounding_ruleset);
Selector_Lookahead lookahead_for_selector(const char* start = 0); Selector_Lookahead lookahead_for_selector(const char* start = 0);
void throw_syntax_error(string message, size_t ln = 0); void throw_syntax_error(string message, size_t ln = 0);
......
...@@ -45,6 +45,9 @@ namespace Sass { ...@@ -45,6 +45,9 @@ namespace Sass {
else if (peek< each_directive >()) { else if (peek< each_directive >()) {
root << parse_each_directive(Node()); root << parse_each_directive(Node());
} }
else if (peek< while_directive >()) {
root << parse_while_directive(Node());
}
else { else {
lex< spaces_and_comments >(); lex< spaces_and_comments >();
throw_syntax_error("invalid top-level expression"); throw_syntax_error("invalid top-level expression");
...@@ -502,6 +505,9 @@ namespace Sass { ...@@ -502,6 +505,9 @@ namespace Sass {
else if (peek< each_directive >()) { else if (peek< each_directive >()) {
block << parse_each_directive(surrounding_ruleset); block << parse_each_directive(surrounding_ruleset);
} }
else if (peek < while_directive >()) {
block << parse_while_directive(surrounding_ruleset);
}
else if (!peek< exactly<';'> >()) { else if (!peek< exactly<';'> >()) {
Node rule(parse_rule()); Node rule(parse_rule());
// check for lbrace; if it's there, we have a namespace property with a value // check for lbrace; if it's there, we have a namespace property with a value
...@@ -945,6 +951,17 @@ namespace Sass { ...@@ -945,6 +951,17 @@ namespace Sass {
each << var << list << body; each << var << list << body;
return each; return each;
} }
Node Document::parse_while_directive(Node surrounding_ruleset)
{
lex< while_directive >();
size_t while_line = line;
Node predicate(parse_list());
Node body(parse_block(surrounding_ruleset));
Node loop(context.new_Node(Node::while_directive, path, while_line, 2));
loop << predicate << body;
return loop;
}
Selector_Lookahead Document::lookahead_for_selector(const char* start) Selector_Lookahead Document::lookahead_for_selector(const char* start)
{ {
......
...@@ -347,6 +347,10 @@ namespace Sass { ...@@ -347,6 +347,10 @@ namespace Sass {
Node fake_param(new_Node(Node::parameters, expr.path(), expr.line(), 1)); Node fake_param(new_Node(Node::parameters, expr.path(), expr.line(), 1));
fake_mixin << new_Node(Node::none, "", 0, 0) << (fake_param << expr[0]) << expr[2]; fake_mixin << new_Node(Node::none, "", 0, 0) << (fake_param << expr[0]) << expr[2];
Node list(expr[1]); Node list(expr[1]);
// If the list isn't really a list, make a singleton out of it.
if (list.type() != Node::space_list && list.type() != Node::comma_list) {
list = (new_Node(Node::space_list, list.path(), list.line(), 1) << list);
}
expr.pop_back(); expr.pop_back();
expr.pop_back(); expr.pop_back();
expr.pop_back(); expr.pop_back();
...@@ -357,6 +361,21 @@ namespace Sass { ...@@ -357,6 +361,21 @@ namespace Sass {
} }
} break; } break;
case Node::while_directive: {
Node fake_mixin(new_Node(Node::mixin, expr.path(), expr.line(), 3));
Node fake_param(new_Node(Node::parameters, expr.path(), expr.line(), 0));
Node fake_arg(new_Node(Node::arguments, expr.path(), expr.line(), 0));
fake_mixin << new_Node(Node::none, "", 0, 0) << fake_param << expr[1];
Node pred(expr[0]);
expr.pop_back();
expr.pop_back();
Node ev_pred(eval(pred, prefix, env, f_env, new_Node, ctx));
while ((ev_pred.type() != Node::boolean) || ev_pred.boolean_value()) {
expr += apply_mixin(fake_mixin, fake_arg, prefix, env, f_env, new_Node, ctx);
ev_pred = eval(pred, prefix, env, f_env, new_Node, ctx);
}
} break;
default: { default: {
return expr; return expr;
} break; } break;
......
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