coffee-script 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -26,7 +26,7 @@
26
26
  gem install coffee-script
27
27
 
28
28
  Compile a script:
29
- coffee-script /path/to/script.cs
29
+ coffee-script /path/to/script.coffee
30
30
 
31
31
  For documentation, usage, and examples, see:
32
32
  http://jashkenas.github.com/coffee-script/
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'coffee-script'
3
- s.version = '0.1.3' # Keep version in sync with coffee-script.rb
3
+ s.version = '0.1.4' # Keep version in sync with coffee-script.rb
4
4
  s.date = '2009-12-25'
5
5
 
6
6
  s.homepage = "http://jashkenas.github.com/coffee-script/"
@@ -62,8 +62,8 @@ race: =>
62
62
  race().
63
63
 
64
64
  # Conditional assignment:
65
- good ||: evil
66
- wine &&: cheese
65
+ good ||= evil
66
+ wine &&= cheese
67
67
 
68
68
  # Nested property access and calls.
69
69
  ((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
@@ -145,13 +145,13 @@ Animal.prototype.move: meters =>
145
145
  alert(this.name + " moved " + meters + "m.").
146
146
 
147
147
  Snake: name => this.name: name.
148
- Snake extends new Animal()
148
+ Snake extends Animal
149
149
  Snake.prototype.move: =>
150
150
  alert('Slithering...')
151
151
  super(5).
152
152
 
153
153
  Horse: name => this.name: name.
154
- Horse extends new Animal()
154
+ Horse extends Animal
155
155
  Horse.prototype.move: =>
156
156
  alert('Galloping...')
157
157
  super(45).
File without changes
@@ -81,9 +81,9 @@ Creature : {
81
81
  hit: damage =>
82
82
  p_up: Math.rand( this.charisma )
83
83
  if p_up % 9 is 7
84
- this.life +: p_up / 4
84
+ this.life += p_up / 4
85
85
  puts( "[" + this.name + " magick powers up " + p_up + "!]" ).
86
- this.life -: damage
86
+ this.life -= damage
87
87
  if this.life <= 0 then puts( "[" + this.name + " has died.]" )..
88
88
 
89
89
  # This method takes one turn in a fight.
File without changes
File without changes
data/lib/coffee-script.rb CHANGED
@@ -9,7 +9,7 @@ require "coffee_script/parse_error"
9
9
  # Namespace for all CoffeeScript internal classes.
10
10
  module CoffeeScript
11
11
 
12
- VERSION = '0.1.3' # Keep in sync with the gemspec.
12
+ VERSION = '0.1.4' # Keep in sync with the gemspec.
13
13
 
14
14
  # Compile a script (String or IO) to JavaScript.
15
15
  def self.compile(script, options={})
@@ -5,7 +5,7 @@
5
5
  <key>name</key>
6
6
  <string>comments</string>
7
7
  <key>scope</key>
8
- <string>source.cs</string>
8
+ <string>source.coffee</string>
9
9
  <key>settings</key>
10
10
  <dict>
11
11
  <key>shellVariables</key>
@@ -6,8 +6,7 @@
6
6
  <string>CoffeeScript Syntax: version 1</string>
7
7
  <key>fileTypes</key>
8
8
  <array>
9
- <string>cs</string>
10
- <string>coffeescript</string>
9
+ <string>coffee</string>
11
10
  </array>
12
11
  <key>name</key>
13
12
  <string>CoffeeScript</string>
@@ -19,22 +18,22 @@
19
18
  <key>1</key>
20
19
  <dict>
21
20
  <key>name</key>
22
- <string>entity.name.function.cs</string>
21
+ <string>entity.name.function.coffee</string>
23
22
  </dict>
24
23
  <key>2</key>
25
24
  <dict>
26
25
  <key>name</key>
27
- <string>keyword.operator.cs</string>
26
+ <string>keyword.operator.coffee</string>
28
27
  </dict>
29
28
  <key>3</key>
30
29
  <dict>
31
30
  <key>name</key>
32
- <string>variable.parameter.function.cs</string>
31
+ <string>variable.parameter.function.coffee</string>
33
32
  </dict>
34
33
  <key>4</key>
35
34
  <dict>
36
35
  <key>name</key>
37
- <string>storage.type.function.cs</string>
36
+ <string>storage.type.function.coffee</string>
38
37
  </dict>
39
38
  </dict>
40
39
  <key>comment</key>
@@ -42,7 +41,7 @@
42
41
  <key>match</key>
43
42
  <string>([a-zA-Z_?.$]*)\s*(=|:)\s*([\w,\s]*?)\s*(=&gt;)</string>
44
43
  <key>name</key>
45
- <string>meta.function.cs</string>
44
+ <string>meta.function.coffee</string>
46
45
  </dict>
47
46
  <dict>
48
47
  <key>captures</key>
@@ -50,12 +49,12 @@
50
49
  <key>1</key>
51
50
  <dict>
52
51
  <key>name</key>
53
- <string>variable.parameter.function.cs</string>
52
+ <string>variable.parameter.function.coffee</string>
54
53
  </dict>
55
54
  <key>2</key>
56
55
  <dict>
57
56
  <key>name</key>
58
- <string>storage.type.function.cs</string>
57
+ <string>storage.type.function.coffee</string>
59
58
  </dict>
60
59
  </dict>
61
60
  <key>comment</key>
@@ -63,7 +62,7 @@
63
62
  <key>match</key>
64
63
  <string>([a-zA-Z_?., $]*)\s*(=&gt;)</string>
65
64
  <key>name</key>
66
- <string>meta.inline.function.cs</string>
65
+ <string>meta.inline.function.coffee</string>
67
66
  </dict>
68
67
  <dict>
69
68
  <key>captures</key>
@@ -71,12 +70,12 @@
71
70
  <key>1</key>
72
71
  <dict>
73
72
  <key>name</key>
74
- <string>keyword.operator.new.cs</string>
73
+ <string>keyword.operator.new.coffee</string>
75
74
  </dict>
76
75
  <key>2</key>
77
76
  <dict>
78
77
  <key>name</key>
79
- <string>entity.name.type.instance.cs</string>
78
+ <string>entity.name.type.instance.coffee</string>
80
79
  </dict>
81
80
  </dict>
82
81
  <key>match</key>
@@ -88,7 +87,7 @@
88
87
  <key>match</key>
89
88
  <string>\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[+\-]?[0-9]+)?))\b</string>
90
89
  <key>name</key>
91
- <string>constant.numeric.cs</string>
90
+ <string>constant.numeric.coffee</string>
92
91
  </dict>
93
92
  <dict>
94
93
  <key>begin</key>
@@ -98,7 +97,7 @@
98
97
  <key>0</key>
99
98
  <dict>
100
99
  <key>name</key>
101
- <string>punctuation.definition.string.begin.cs</string>
100
+ <string>punctuation.definition.string.begin.coffee</string>
102
101
  </dict>
103
102
  </dict>
104
103
  <key>end</key>
@@ -108,18 +107,18 @@
108
107
  <key>0</key>
109
108
  <dict>
110
109
  <key>name</key>
111
- <string>punctuation.definition.string.end.cs</string>
110
+ <string>punctuation.definition.string.end.coffee</string>
112
111
  </dict>
113
112
  </dict>
114
113
  <key>name</key>
115
- <string>string.quoted.single.cs</string>
114
+ <string>string.quoted.single.coffee</string>
116
115
  <key>patterns</key>
117
116
  <array>
118
117
  <dict>
119
118
  <key>match</key>
120
119
  <string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)</string>
121
120
  <key>name</key>
122
- <string>constant.character.escape.cs</string>
121
+ <string>constant.character.escape.coffee</string>
123
122
  </dict>
124
123
  </array>
125
124
  </dict>
@@ -131,7 +130,7 @@
131
130
  <key>0</key>
132
131
  <dict>
133
132
  <key>name</key>
134
- <string>punctuation.definition.string.begin.cs</string>
133
+ <string>punctuation.definition.string.begin.coffee</string>
135
134
  </dict>
136
135
  </dict>
137
136
  <key>end</key>
@@ -141,18 +140,18 @@
141
140
  <key>0</key>
142
141
  <dict>
143
142
  <key>name</key>
144
- <string>punctuation.definition.string.end.cs</string>
143
+ <string>punctuation.definition.string.end.coffee</string>
145
144
  </dict>
146
145
  </dict>
147
146
  <key>name</key>
148
- <string>string.quoted.double.cs</string>
147
+ <string>string.quoted.double.coffee</string>
149
148
  <key>patterns</key>
150
149
  <array>
151
150
  <dict>
152
151
  <key>match</key>
153
152
  <string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)</string>
154
153
  <key>name</key>
155
- <string>constant.character.escape.cs</string>
154
+ <string>constant.character.escape.coffee</string>
156
155
  </dict>
157
156
  </array>
158
157
  </dict>
@@ -164,7 +163,7 @@
164
163
  <key>0</key>
165
164
  <dict>
166
165
  <key>name</key>
167
- <string>punctuation.definition.string.begin.cs</string>
166
+ <string>punctuation.definition.string.begin.coffee</string>
168
167
  </dict>
169
168
  </dict>
170
169
  <key>end</key>
@@ -174,18 +173,18 @@
174
173
  <key>0</key>
175
174
  <dict>
176
175
  <key>name</key>
177
- <string>punctuation.definition.string.end.cs</string>
176
+ <string>punctuation.definition.string.end.coffee</string>
178
177
  </dict>
179
178
  </dict>
180
179
  <key>name</key>
181
- <string>string.quoted.script.cs</string>
180
+ <string>string.quoted.script.coffee</string>
182
181
  <key>patterns</key>
183
182
  <array>
184
183
  <dict>
185
184
  <key>match</key>
186
185
  <string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)</string>
187
186
  <key>name</key>
188
- <string>constant.character.escape.cs</string>
187
+ <string>constant.character.escape.coffee</string>
189
188
  </dict>
190
189
  </array>
191
190
  </dict>
@@ -195,61 +194,61 @@
195
194
  <key>1</key>
196
195
  <dict>
197
196
  <key>name</key>
198
- <string>punctuation.definition.comment.cs</string>
197
+ <string>punctuation.definition.comment.coffee</string>
199
198
  </dict>
200
199
  </dict>
201
200
  <key>match</key>
202
201
  <string>(#).*$\n?</string>
203
202
  <key>name</key>
204
- <string>comment.line.cs</string>
203
+ <string>comment.line.coffee</string>
205
204
  </dict>
206
205
  <dict>
207
206
  <key>match</key>
208
207
  <string>\b(break|when|catch|continue|else|finally|for|if|return|switch|then|throw|try|unless|while)\b</string>
209
208
  <key>name</key>
210
- <string>keyword.control.cs</string>
209
+ <string>keyword.control.coffee</string>
211
210
  </dict>
212
211
  <dict>
213
212
  <key>match</key>
214
213
  <string>\b(true|on|yes)\b</string>
215
214
  <key>name</key>
216
- <string>constant.language.boolean.true.cs</string>
215
+ <string>constant.language.boolean.true.coffee</string>
217
216
  </dict>
218
217
  <dict>
219
218
  <key>match</key>
220
219
  <string>\b(false|off|no)\b</string>
221
220
  <key>name</key>
222
- <string>constant.language.boolean.false.cs</string>
221
+ <string>constant.language.boolean.false.coffee</string>
223
222
  </dict>
224
223
  <dict>
225
224
  <key>match</key>
226
225
  <string>\bnull\b</string>
227
226
  <key>name</key>
228
- <string>constant.language.null.cs</string>
227
+ <string>constant.language.null.coffee</string>
229
228
  </dict>
230
229
  <dict>
231
230
  <key>match</key>
232
231
  <string>\b(super|this|extends)\b</string>
233
232
  <key>name</key>
234
- <string>variable.language.cs</string>
233
+ <string>variable.language.coffee</string>
235
234
  </dict>
236
235
  <dict>
237
236
  <key>match</key>
238
237
  <string>\b(debugger)\b</string>
239
238
  <key>name</key>
240
- <string>keyword.other.cs</string>
239
+ <string>keyword.other.coffee</string>
241
240
  </dict>
242
241
  <dict>
243
242
  <key>match</key>
244
- <string>!|\$|%|&amp;|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|&lt;=|&gt;=|&lt;&lt;=|&gt;&gt;=|&gt;&gt;&gt;=|&lt;&gt;|&lt;|&gt;|!|&amp;&amp;|\?|\|\||\:|\*:|(?&lt;!\()/=|%:|\+:|\-:|&amp;=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b</string>
243
+ <string>!|\$|%|&amp;|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|&lt;=|&gt;=|&lt;&lt;=|&gt;&gt;=|&gt;&gt;&gt;=|&lt;&gt;|&lt;|&gt;|!|&amp;&amp;|\?|\|\||\:|\*=|(?&lt;!\()/=|%=|\+=|\-=|&amp;=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b</string>
245
244
  <key>name</key>
246
- <string>keyword.operator.cs</string>
245
+ <string>keyword.operator.coffee</string>
247
246
  </dict>
248
247
  <dict>
249
248
  <key>match</key>
250
249
  <string>\b(Infinity|NaN|undefined)\b</string>
251
250
  <key>name</key>
252
- <string>constant.language.cs</string>
251
+ <string>constant.language.coffee</string>
253
252
  </dict>
254
253
  <dict>
255
254
  <key>begin</key>
@@ -259,7 +258,7 @@
259
258
  <key>1</key>
260
259
  <dict>
261
260
  <key>name</key>
262
- <string>punctuation.definition.string.begin.cs</string>
261
+ <string>punctuation.definition.string.begin.coffee</string>
263
262
  </dict>
264
263
  </dict>
265
264
  <key>end</key>
@@ -269,18 +268,18 @@
269
268
  <key>1</key>
270
269
  <dict>
271
270
  <key>name</key>
272
- <string>punctuation.definition.string.end.cs</string>
271
+ <string>punctuation.definition.string.end.coffee</string>
273
272
  </dict>
274
273
  </dict>
275
274
  <key>name</key>
276
- <string>string.regexp.cs</string>
275
+ <string>string.regexp.coffee</string>
277
276
  <key>patterns</key>
278
277
  <array>
279
278
  <dict>
280
279
  <key>match</key>
281
280
  <string>\\.</string>
282
281
  <key>name</key>
283
- <string>constant.character.escape.cs</string>
282
+ <string>constant.character.escape.coffee</string>
284
283
  </dict>
285
284
  </array>
286
285
  </dict>
@@ -288,41 +287,41 @@
288
287
  <key>match</key>
289
288
  <string>\;</string>
290
289
  <key>name</key>
291
- <string>punctuation.terminator.statement.cs</string>
290
+ <string>punctuation.terminator.statement.coffee</string>
292
291
  </dict>
293
292
  <dict>
294
293
  <key>match</key>
295
294
  <string>,[ |\t]*</string>
296
295
  <key>name</key>
297
- <string>meta.delimiter.object.comma.cs</string>
296
+ <string>meta.delimiter.object.comma.coffee</string>
298
297
  </dict>
299
298
  <dict>
300
299
  <key>match</key>
301
300
  <string>\.</string>
302
301
  <key>name</key>
303
- <string>meta.delimiter.method.period.cs</string>
302
+ <string>meta.delimiter.method.period.coffee</string>
304
303
  </dict>
305
304
  <dict>
306
305
  <key>match</key>
307
306
  <string>\{|\}</string>
308
307
  <key>name</key>
309
- <string>meta.brace.curly.cs</string>
308
+ <string>meta.brace.curly.coffee</string>
310
309
  </dict>
311
310
  <dict>
312
311
  <key>match</key>
313
312
  <string>\(|\)</string>
314
313
  <key>name</key>
315
- <string>meta.brace.round.cs</string>
314
+ <string>meta.brace.round.coffee</string>
316
315
  </dict>
317
316
  <dict>
318
317
  <key>match</key>
319
318
  <string>\[|\]</string>
320
319
  <key>name</key>
321
- <string>meta.brace.square.cs</string>
320
+ <string>meta.brace.square.coffee</string>
322
321
  </dict>
323
322
  </array>
324
323
  <key>scopeName</key>
325
- <string>source.cs</string>
324
+ <string>source.coffee</string>
326
325
  <key>uuid</key>
327
326
  <string>5B520980-A7D5-4E10-8582-1A4C889A8DE5</string>
328
327
  </dict>
@@ -13,7 +13,7 @@ module CoffeeScript
13
13
  coffee-script compiles CoffeeScript source files into JavaScript.
14
14
 
15
15
  Usage:
16
- coffee-script path/to/script.cs
16
+ coffee-script path/to/script.coffee
17
17
  EOS
18
18
 
19
19
  # Seconds to pause between checks for changed source files.
@@ -26,18 +26,18 @@ prechigh
26
26
  left '<=' '<' '>' '>='
27
27
  right '==' '!=' IS ISNT
28
28
  left '&&' '||' AND OR
29
- right '-:' '+:' '/:' '*:' '%:'
29
+ right '-=' '+=' '/=' '*=' '%='
30
30
  right DELETE INSTANCEOF TYPEOF
31
- left "."
31
+ left '.'
32
32
  right THROW FOR IN WHILE NEW SUPER
33
33
  left UNLESS IF ELSE EXTENDS
34
- left ":" '||:' '&&:'
34
+ left ASSIGN '||=' '&&='
35
35
  right RETURN
36
36
  preclow
37
37
 
38
- # We expect 4 shift/reduce errors for optional syntax.
38
+ # We expect 3 shift/reduce errors for optional syntax.
39
39
  # There used to be 252 -- greatly improved.
40
- expect 4
40
+ expect 3
41
41
 
42
42
  rule
43
43
 
@@ -115,13 +115,13 @@ rule
115
115
 
116
116
  # Assignment to a variable.
117
117
  Assign:
118
- Value ":" Expression { result = AssignNode.new(val[0], val[2]) }
118
+ Value ASSIGN Expression { result = AssignNode.new(val[0], val[2]) }
119
119
  ;
120
120
 
121
121
  # Assignment within an object literal.
122
122
  AssignObj:
123
- IDENTIFIER ":" Expression { result = AssignNode.new(val[0], val[2], :object) }
124
- | STRING ":" Expression { result = AssignNode.new(val[0], val[2], :object) }
123
+ IDENTIFIER ASSIGN Expression { result = AssignNode.new(val[0], val[2], :object) }
124
+ | STRING ASSIGN Expression { result = AssignNode.new(val[0], val[2], :object) }
125
125
  | Comment { result = val[0] }
126
126
  ;
127
127
 
@@ -179,13 +179,13 @@ rule
179
179
  | Expression AND Expression { result = OpNode.new(val[1], val[0], val[2]) }
180
180
  | Expression OR Expression { result = OpNode.new(val[1], val[0], val[2]) }
181
181
 
182
- | Expression '-:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
183
- | Expression '+:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
184
- | Expression '/:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
185
- | Expression '*:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
186
- | Expression '%:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
187
- | Expression '||:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
188
- | Expression '&&:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
182
+ | Expression '-=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
183
+ | Expression '+=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
184
+ | Expression '/=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
185
+ | Expression '*=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
186
+ | Expression '%=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
187
+ | Expression '||=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
188
+ | Expression '&&=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
189
189
 
190
190
  | DELETE Expression { result = OpNode.new(val[0], val[1]) }
191
191
  | TYPEOF Expression { result = OpNode.new(val[0], val[1]) }
@@ -259,12 +259,13 @@ rule
259
259
 
260
260
  # Extending an object's prototype.
261
261
  Extends:
262
- Value EXTENDS Expression { result = ExtendsNode.new(val[0], val[2]) }
262
+ Value EXTENDS Value { result = ExtendsNode.new(val[0], val[2]) }
263
263
  ;
264
264
 
265
265
  # A generic function invocation.
266
266
  Invocation:
267
267
  Value "(" ArgList ")" { result = CallNode.new(val[0], val[2]) }
268
+ | Invocation "(" ArgList ")" { result = CallNode.new(val[0], val[2]) }
268
269
  ;
269
270
 
270
271
  # Calling super.
@@ -315,19 +316,23 @@ rule
315
316
  ;
316
317
 
317
318
  # Array comprehensions, including guard and current index.
319
+ # Looks a little confusing, check nodes.rb for the arguments to ForNode.
318
320
  For:
319
- Expression FOR IDENTIFIER
320
- IN PureExpression "." { result = ForNode.new(val[0], val[4], val[2], nil) }
321
- | Expression FOR
322
- IDENTIFIER "," IDENTIFIER
323
- IN PureExpression "." { result = ForNode.new(val[0], val[6], val[2], nil, val[4]) }
324
- | Expression FOR IDENTIFIER
325
- IN PureExpression
326
- IF Expression "." { result = ForNode.new(val[0], val[4], val[2], val[6]) }
327
- | Expression FOR
328
- IDENTIFIER "," IDENTIFIER
329
- IN PureExpression
330
- IF Expression "." { result = ForNode.new(val[0], val[6], val[2], val[8], val[4]) }
321
+ Expression FOR
322
+ ForVariables ForSource { result = ForNode.new(val[0], val[3][0], val[2][0], val[3][1], val[2][1]) }
323
+ ;
324
+
325
+ # An array comprehension has variables for the current element and index.
326
+ ForVariables:
327
+ IDENTIFIER { result = val }
328
+ | IDENTIFIER "," IDENTIFIER { result = [val[0], val[2]] }
329
+ ;
330
+
331
+ # The source of the array comprehension can optionally be filtered.
332
+ ForSource:
333
+ IN PureExpression "." { result = [val[1]] }
334
+ | IN PureExpression
335
+ IF Expression "." { result = [val[1], val[3]] }
331
336
  ;
332
337
 
333
338
  # Switch/When blocks.