1 | var utils = require('../utils')
|
2 | , nodes = require('../nodes');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function range(start, stop, step){
|
17 | utils.assertType(start, 'unit', 'start');
|
18 | utils.assertType(stop, 'unit', 'stop');
|
19 | if (step) {
|
20 | utils.assertType(step, 'unit', 'step');
|
21 | if (0 == step.val) {
|
22 | throw new Error('ArgumentError: "step" argument must not be zero');
|
23 | }
|
24 | } else {
|
25 | step = new nodes.Unit(1);
|
26 | }
|
27 | var list = new nodes.Expression;
|
28 | for (var i = start.val; i <= stop.val; i += step.val) {
|
29 | list.push(new nodes.Unit(i, start.type));
|
30 | }
|
31 | return list;
|
32 | }
|
33 | range.params = ['start', 'stop', 'step'];
|
34 | module.exports = range;
|