Permalink
Browse files

closes #67; made `from` optional

  • Loading branch information...
satyr committed Jun 25, 2011
1 parent c11977b commit 9880b4716d1d16b99e5294a43453b6b706ec1c26
Showing with 75 additions and 39 deletions.
  1. +1 −1 extras/coco.js
  2. +22 −7 lib/grammar.js
  3. +1 −1 lib/lexer.js
  4. +35 −20 lib/parser.js
  5. +9 −3 src/grammar.co
  6. +1 −1 src/lexer.co
  7. +1 −1 src/wsh.co
  8. +1 −1 test/function.co
  9. +3 −3 test/loop.co
  10. +1 −1 test/operator.co
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -288,13 +288,6 @@ bnf = {
name: $5,
source: $7
});
- }), o('FOR ID FROM Expression', function(){
- return new For({
- index: $2,
- from: Literal(0),
- op: 'til',
- to: $4
- });
}), o('FOR ID FROM Expression TO Expression', function(){
return new For({
index: $2,
@@ -310,6 +303,28 @@ bnf = {
to: $6,
step: $8
});
+ }), o('FOR ID TO Expression', function(){
+ return new For({
+ index: $2,
+ from: Literal(0),
+ op: $3,
+ to: $4
+ });
+ }), o('FOR ID TO Expression BY Expression', function(){
+ return new For({
+ index: $2,
+ from: Literal(0),
+ op: $3,
+ to: $4,
+ step: $6
+ });
+ }), o('FOR ID FROM Expression', function(){
+ return new For({
+ index: $2,
+ from: Literal(0),
+ op: 'til',
+ to: $4
+ });
}), o('WHILE Expression', function(){
return new While($2, $1 === 'until');
}), o('WHILE Expression , Expression', function(){
View
@@ -202,7 +202,7 @@ exports.doIdentifier = function(code, lastIndex){
break;
case 'to':
case 'til':
- if (this.seenFrom) {
+ if (this.seenFrom || ((_ref = (_ref = this.tokens)[_ref.length - 2]) != null ? _ref[0] : void 8) === 'FOR') {
this.seenFrom = false;
this.seenTo = true;
tag = 'TO';
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -277,12 +277,18 @@ bnf =
o 'FOR OWN ID , Assignable FORIN Expression'
, -> new For {+object, +own, index: $3, name: $5, source: $7}
- o 'FOR ID FROM Expression'
- , -> new For index: $2, from: Literal(0), op: \til, to: $4
o 'FOR ID FROM Expression TO Expression'
, -> new For index: $2, from: $4, op: $5, to: $6
o 'FOR ID FROM Expression TO Expression BY Expression'
- , -> new For index: $2, from: $4, op: $5, to: $6, step : $8
+ , -> new For index: $2, from: $4, op: $5, to: $6, step: $8
+ o 'FOR ID TO Expression'
+ , -> new For index: $2, from: Literal(0), op: $3, to: $4
+ o 'FOR ID TO Expression BY Expression'
+ , -> new For index: $2, from: Literal(0), op: $3, to: $4, step: $6
+ # _Deprecated_
+ # TODO: Remove this.
+ o 'FOR ID FROM Expression'
+ , -> new For index: $2, from: Literal(0), op: \til, to: $4
o 'WHILE Expression' -> new While $2, $1 is \until
o 'WHILE Expression , Expression' -> new While $2, $1 is \until, $4
View
@@ -139,7 +139,7 @@ exports import
@<<<{-seenFor, +seenFrom}
tag = \FROM
case \to \til
- if @seenFrom
+ if @seenFrom or @tokens[*-2]?0 is \FOR
@<<<{-seenFrom, +seenTo}
tag = \TO
else if last.0 is \STRNUM and not isNaN last.1
View
@@ -4,7 +4,7 @@
args = WSH.arguments
fso = WSH.createObject \Scripting.FileSystemObject
-for i from args.length
+for i til args.length
it = args.item i
co = fso.openTextFile(it, 1)readAll()
js = Coco.compile co
View
@@ -323,7 +323,7 @@ eq 1, do []= (a || 0 || 1) -> a
eq arguments,
switch case 1
- eq arguments, (arguments for i from 1)0
+ eq arguments, (arguments for i to 0)0
arguments
View
@@ -61,7 +61,7 @@ eq odds. join(' '), 'one! three!'
# Basic range comprehensions.
nums = (i * 3 for i from 1 to 3)
negs = (x for x from -20 to -5*2)
-four = (4 for x from 4)
+four = (4 for x to 3)
eq '3,6,9,-20,-19,-18,4,4,4,4', '' + nums.concat negs.slice(0, 3), four
eq '123', (i for i from 1 til 4 ).join ''
@@ -87,7 +87,7 @@ odds = (num for num of [0, 1, 2, 3, 4, 5] by -2)
eq odds + '', '5,3,1'
-# all/from/to/by aren't reserved.
+# all/from/to/by aren't reserved off-context.
all = from = to = by = 1
@@ -232,7 +232,7 @@ r = ''
:PLAIN
:WHILE while r.length < 9
break PLAIN if r.length > 1
- :FOR for i from 2
+ :FOR for i til 2
r += i
continue WHILE
ok 0
View
@@ -371,7 +371,7 @@ y = [7 to 10]
[[] ...x, []] += y
eq '6,8,9' ''+ x
-x += for i from 2 then i
+x += for i til 2 then i
eq '6,8,9,0,1' ''+ x
#### Join

0 comments on commit 9880b47

Please sign in to comment.