Skip to content

Commit 49416ac

Browse files
committed
Merge pull request #837 from rhendric/for-by
support for <expr> by <expr> loops
2 parents 9bdd5df + 7ec14e0 commit 49416ac

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

lib/ast.js

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/command.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/lexer.js

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.ls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ exports <<<
155155
id = []
156156
@fset 'for' true
157157
@fset 'to' false
158+
@fset 'by' true
158159
case 'then'
159160
@fset 'for' false
160161
@fset 'to' false
@@ -264,7 +265,7 @@ exports <<<
264265
then tag = 'RANGE_BY'
265266
else if ']' in @closes
266267
tag = 'BY'
267-
else if @fget 'by'
268+
else if @fget 'by' and last.0 is not 'FOR'
268269
tag = 'BY'
269270
@fset 'by' false
270271
case 'ever' then if last.0 is 'FOR'

test/loop.ls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,13 @@ eq '0 1 2 3' [f! for til 4].join ' '
634634
i = 0
635635
eq '2 4 6' [f! for til 4 when f!].join ' '
636636

637+
x = []
638+
for <[one two three]> by -1 then x.push ..
639+
eq 'three two one' x.join ' '
640+
641+
x = [.. for <[one two three]> by -1]
642+
eq 'three two one' x.join ' '
643+
637644
# index var outside loop
638645
for v, k in [1]
639646
void

0 commit comments

Comments
 (0)