Skip to content
This repository was archived by the owner on Jun 14, 2019. It is now read-only.

Commit 66a0b28

Browse files
author
Aaron Leung
committed
Working on @while. Need to redo environment handling.
1 parent a78ca00 commit 66a0b28

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

document.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ namespace Sass {
163163
Node parse_if_directive(Node surrounding_ruleset);
164164
Node parse_for_directive(Node surrounding_ruleset);
165165
Node parse_each_directive(Node surrounding_ruleset);
166-
166+
Node parse_while_directive(Node surrounding_ruleset);
167+
167168
Selector_Lookahead lookahead_for_selector(const char* start = 0);
168169

169170
void throw_syntax_error(string message, size_t ln = 0);

document_parser.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ namespace Sass {
4545
else if (peek< each_directive >()) {
4646
root << parse_each_directive(Node());
4747
}
48+
else if (peek< while_directive >()) {
49+
root << parse_while_directive(Node());
50+
}
4851
else {
4952
lex< spaces_and_comments >();
5053
throw_syntax_error("invalid top-level expression");
@@ -502,6 +505,9 @@ namespace Sass {
502505
else if (peek< each_directive >()) {
503506
block << parse_each_directive(surrounding_ruleset);
504507
}
508+
else if (peek < while_directive >()) {
509+
block << parse_while_directive(surrounding_ruleset);
510+
}
505511
else if (!peek< exactly<';'> >()) {
506512
Node rule(parse_rule());
507513
// check for lbrace; if it's there, we have a namespace property with a value
@@ -945,6 +951,17 @@ namespace Sass {
945951
each << var << list << body;
946952
return each;
947953
}
954+
955+
Node Document::parse_while_directive(Node surrounding_ruleset)
956+
{
957+
lex< while_directive >();
958+
size_t while_line = line;
959+
Node predicate(parse_list());
960+
Node body(parse_block(surrounding_ruleset));
961+
Node loop(context.new_Node(Node::while_directive, path, while_line, 2));
962+
loop << predicate << body;
963+
return loop;
964+
}
948965

949966
Selector_Lookahead Document::lookahead_for_selector(const char* start)
950967
{

eval_apply.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ namespace Sass {
347347
Node fake_param(new_Node(Node::parameters, expr.path(), expr.line(), 1));
348348
fake_mixin << new_Node(Node::none, "", 0, 0) << (fake_param << expr[0]) << expr[2];
349349
Node list(expr[1]);
350+
// If the list isn't really a list, make a singleton out of it.
351+
if (list.type() != Node::space_list && list.type() != Node::comma_list) {
352+
list = (new_Node(Node::space_list, list.path(), list.line(), 1) << list);
353+
}
350354
expr.pop_back();
351355
expr.pop_back();
352356
expr.pop_back();
@@ -357,6 +361,21 @@ namespace Sass {
357361
}
358362
} break;
359363

364+
case Node::while_directive: {
365+
Node fake_mixin(new_Node(Node::mixin, expr.path(), expr.line(), 3));
366+
Node fake_param(new_Node(Node::parameters, expr.path(), expr.line(), 0));
367+
Node fake_arg(new_Node(Node::arguments, expr.path(), expr.line(), 0));
368+
fake_mixin << new_Node(Node::none, "", 0, 0) << fake_param << expr[1];
369+
Node pred(expr[0]);
370+
expr.pop_back();
371+
expr.pop_back();
372+
Node ev_pred(eval(pred, prefix, env, f_env, new_Node, ctx));
373+
while ((ev_pred.type() != Node::boolean) || ev_pred.boolean_value()) {
374+
expr += apply_mixin(fake_mixin, fake_arg, prefix, env, f_env, new_Node, ctx);
375+
ev_pred = eval(pred, prefix, env, f_env, new_Node, ctx);
376+
}
377+
} break;
378+
360379
default: {
361380
return expr;
362381
} break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy