This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
@for loops
Ian Flanigan edited this page Jun 28, 2016
·
3 revisions
Loops will be defined with the new @-rule “@for”. The syntax will conceptually be as follows:
for_loop : “@for” <DOLLAR> IDENTIFIER “from” (IDENTIFIER | NUMBER) “to” (IDENTIFIER | NUMBER) [ “step” (IDENTIFIER | NUMBER) ] ruleblock;
ruleblock : ‘{‘ S\* block ‘}’ | ‘;’
Loops will be evaluated by unrolling the loop and replacing the loop variable with the iteration number.
For example:
@for $i from 0 to 4 step 2 {
@def A add(2px, $i);
.w-$i {
margin: A;
padding: mult(1px, $i);
}
}
Will be expanded to:
@def A_0 add(2px, 0); // A suffix is automatically added to @defs.
.w-0 {
margin: A_0;
padding: mult(1px, 0);
}
@def A_2 add(2px, 2);
.w-2 {
margin: A_2;
padding: mult(1px, 2);
}
@def A_4 add(2px, 4);
.w-4 {
margin: A_4;
padding: mult(1px, 4);
}
Note the special treatment of @defs. The current iteration number is automatically added to it so the definition is redefined per context.
Compile time constants will be introduced so they can be used as argument to for loops. They will passed by a command line flag, similar to boolean constants in conditionals.
This will allow defining:
@for $i from START to END {
}
Where a command line flag should be passed to compiler defining START and END.