Skip to content

Commit 61d2f14

Browse files
committed
fixed the handling of 1 to i etc. (#143)
1 parent 87cb61c commit 61d2f14

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

lib/lexer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ function addImplicitBraces(tokens){
12351235
}
12361236
}
12371237
function expandLiterals(tokens){
1238-
var i, token, sig, lno, from, char, to, tochar, by, byp, ts, enc, add, n, word, that, __ref, __i, __len;
1238+
var i, token, sig, next, lno, from, char, to, tochar, by, byp, ts, enc, add, n, word, that, __ref, __i, __len;
12391239
i = 0;
12401240
while (token = tokens[++i]) {
12411241
switch (token[0]) {
@@ -1249,9 +1249,11 @@ function expandLiterals(tokens){
12491249
}
12501250
break;
12511251
case 'RANGE':
1252-
__ref = decode(token[1], lno = token[2]), from = __ref[0], char = __ref[1];
1253-
__ref = decode(tokens[i + 1][1], lno), to = __ref[0], tochar = __ref[1];
1254-
if (char ^ tochar) {
1252+
next = tokens[i + 1];
1253+
lno = token[2];
1254+
__ref = decode(token[1], lno), from = __ref[0], char = __ref[1];
1255+
__ref = next[0] === 'STRNUM' && decode(next[1], lno), to = __ref[0], tochar = __ref[1];
1256+
if (to == null || char ^ tochar) {
12551257
carp('bad "to" in range', lno);
12561258
}
12571259
by = 1;

src/lexer.co

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,11 @@ character = if JSON!? then uxxxx else ->
829829
tokens.splice i++ 0 [\+- sig, token.2]
830830
continue if token.callable
831831
case \RANGE
832-
[from, char] = decode token. 1, lno = token.2
833-
[to, tochar] = decode tokens[i+1]1, lno
834-
carp 'bad "to" in range' lno if char ^ tochar
832+
next = tokens[i+1]
833+
lno = token.2
834+
[from, char] = decode token.1, lno
835+
[to, tochar] = next.0 is \STRNUM and decode next.1, lno
836+
carp 'bad "to" in range' lno if to!? or char ^ tochar
835837
by = 1
836838
if byp = tokens[i+2]?0 is \RANGE_BY
837839
carp 'bad "by" in range' tokens[i+2]2 unless by = +tokens[i+3]?1

test/literal.co

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ compileThrows 'empty range' 2 '\n1 to 0'
431431
compileThrows 'empty range' 2 '\n1 til 1'
432432
compileThrows 'empty range' 2 '\n2 to 3 by -1'
433433
compileThrows 'bad "to" in range' 2 '\n0 to "q"'
434+
compileThrows 'bad "to" in range' 2 '\n1 to i'
434435
compileThrows 'bad "by" in range' 2 '\n0 to 9 by "2"'
435436
compileThrows 'bad string in range' 2 '\n"a" to "bc"'
436437

0 commit comments

Comments
 (0)