Skip to content

Commit c7c745b

Browse files
committed
fixed #195
1 parent 5771465 commit c7c745b

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎lib/lexer.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ exports.doID = function(code, index){
137137
return this.token('LITERAL', id, true).length;
138138
case 'for':
139139
this.seenFor = true;
140-
// fallthrough
141-
case 'then':
142140
this.wantBy = false;
143141
break;
142+
case 'then':
143+
this.seenFor = this.wantBy = false;
144+
break;
144145
case 'catch':
145146
case 'function':
146147
id = '';
@@ -461,7 +462,7 @@ exports.doLine = function(code, index){
461462
this.newline();
462463
}
463464
}
464-
this.wantBy = false;
465+
this.seenFor = this.wantBy = false;
465466
return length;
466467
};
467468
exports.doSpace = function(code, lastIndex){
@@ -684,6 +685,7 @@ exports.doLiteral = function(code, index){
684685
break;
685686
case '=>':
686687
this.unline();
688+
this.seenFor = false;
687689
if (that = this.doInlinedent(code, index + 2)) {
688690
return 1 + that;
689691
}

‎src/lexer.co‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ exports import
105105
case \return \throw then tag = \HURL
106106
case \break \continue then tag = \JUMP
107107
case \this \eval \super then return @token(\LITERAL id, true)length
108-
case \for then @seenFor = true; fallthrough
109-
case \then then @wantBy = false
108+
case \for then @seenFor = true; @wantBy = false
109+
case \then then @seenFor = @wantBy = false
110110
case \catch \function then id = ''
111111
case \in \of
112112
if @seenFor
@@ -330,7 +330,7 @@ exports import
330330
IN OF TO BY FROM EXTENDS IMPLEMENTS ]>
331331
return length
332332
if delta then @indent delta else @newline!
333-
@wantBy = false
333+
@seenFor = @wantBy = false
334334
length
335335

336336
# Consumes non-newline whitespaces and/or a line comment.
@@ -440,6 +440,7 @@ exports import
440440
case \.. then @adi!; tag = \ID; val = up || \constructor
441441
case \=>
442442
@unline!
443+
@seenFor = false
443444
return 1 + that if @doInlinedent code, index+2
444445
tag = \THEN
445446
default if \< is val.charAt 0

‎test/loop.co‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ continue for, o.count!_ in [1 2]
210210
eq o.i, 4
211211

212212

213+
# [#195](https://github.com/satyr/coco/issues/195)
214+
for [0]
215+
ok 0 in {0}
216+
for [1] then ok 1 of [1]
217+
for [2] => ok 2 of [2]
218+
ok 3 not in []
219+
220+
213221
### Line folding before/after `for` prepositions
214222
for x
215223
in {2}

0 commit comments

Comments
 (0)