@makano/rew 1.0.1

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.
Files changed (58) hide show
  1. package/bin/rew +9 -0
  2. package/bin/ui +0 -0
  3. package/bin/webkit_app +0 -0
  4. package/lib/coffeescript/browser.js +151 -0
  5. package/lib/coffeescript/cake.js +135 -0
  6. package/lib/coffeescript/coffeescript.js +409 -0
  7. package/lib/coffeescript/command.js +750 -0
  8. package/lib/coffeescript/grammar.js +2496 -0
  9. package/lib/coffeescript/helpers.js +477 -0
  10. package/lib/coffeescript/index.js +217 -0
  11. package/lib/coffeescript/lexer.js +1943 -0
  12. package/lib/coffeescript/nodes.js +9204 -0
  13. package/lib/coffeescript/optparse.js +230 -0
  14. package/lib/coffeescript/parser.js +1344 -0
  15. package/lib/coffeescript/register.js +100 -0
  16. package/lib/coffeescript/repl.js +305 -0
  17. package/lib/coffeescript/rewriter.js +1138 -0
  18. package/lib/coffeescript/scope.js +187 -0
  19. package/lib/coffeescript/sourcemap.js +229 -0
  20. package/lib/rew/cli/cli.js +117 -0
  21. package/lib/rew/cli/log.js +40 -0
  22. package/lib/rew/cli/run.js +20 -0
  23. package/lib/rew/cli/utils.js +122 -0
  24. package/lib/rew/const/default.js +35 -0
  25. package/lib/rew/const/files.js +15 -0
  26. package/lib/rew/css/theme.css +3 -0
  27. package/lib/rew/functions/core.js +85 -0
  28. package/lib/rew/functions/emitter.js +57 -0
  29. package/lib/rew/functions/export.js +9 -0
  30. package/lib/rew/functions/future.js +22 -0
  31. package/lib/rew/functions/id.js +13 -0
  32. package/lib/rew/functions/import.js +57 -0
  33. package/lib/rew/functions/map.js +17 -0
  34. package/lib/rew/functions/match.js +34 -0
  35. package/lib/rew/functions/sleep.js +5 -0
  36. package/lib/rew/functions/types.js +96 -0
  37. package/lib/rew/html/ui.html +223 -0
  38. package/lib/rew/main.js +17 -0
  39. package/lib/rew/models/enum.js +14 -0
  40. package/lib/rew/models/struct.js +41 -0
  41. package/lib/rew/modules/compiler.js +17 -0
  42. package/lib/rew/modules/context.js +50 -0
  43. package/lib/rew/modules/fs.js +19 -0
  44. package/lib/rew/modules/runtime.js +24 -0
  45. package/lib/rew/modules/utils.js +0 -0
  46. package/lib/rew/modules/yaml.js +36 -0
  47. package/lib/rew/pkgs/conf.js +92 -0
  48. package/lib/rew/pkgs/data.js +8 -0
  49. package/lib/rew/pkgs/date.js +98 -0
  50. package/lib/rew/pkgs/modules/data/bintree.js +66 -0
  51. package/lib/rew/pkgs/modules/data/doublylinked.js +100 -0
  52. package/lib/rew/pkgs/modules/data/linkedList.js +88 -0
  53. package/lib/rew/pkgs/modules/data/queue.js +28 -0
  54. package/lib/rew/pkgs/modules/data/stack.js +27 -0
  55. package/lib/rew/pkgs/modules/ui/classes.js +171 -0
  56. package/lib/rew/pkgs/pkgs.js +13 -0
  57. package/lib/rew/pkgs/ui.js +108 -0
  58. package/package.json +41 -0
@@ -0,0 +1,2496 @@
1
+ // Generated by CoffeeScript 2.7.0
2
+ (function() {
3
+ // The CoffeeScript parser is generated by [Jison](https://github.com/zaach/jison)
4
+ // from this grammar file. Jison is a bottom-up parser generator, similar in
5
+ // style to [Bison](http://www.gnu.org/software/bison), implemented in JavaScript.
6
+ // It can recognize [LALR(1), LR(0), SLR(1), and LR(1)](https://en.wikipedia.org/wiki/LR_grammar)
7
+ // type grammars. To create the Jison parser, we list the pattern to match
8
+ // on the left-hand side, and the action to take (usually the creation of syntax
9
+ // tree nodes) on the right. As the parser runs, it
10
+ // shifts tokens from our token stream, from left to right, and
11
+ // [attempts to match](https://en.wikipedia.org/wiki/Bottom-up_parsing)
12
+ // the token sequence against the rules below. When a match can be made, it
13
+ // reduces into the [nonterminal](https://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols)
14
+ // (the enclosing name at the top), and we proceed from there.
15
+
16
+ // If you run the `cake build:parser` command, Jison constructs a parse table
17
+ // from our rules and saves it into `lib/parser.js`.
18
+
19
+ // The only dependency is on the **Jison.Parser**.
20
+ var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
21
+
22
+ ({Parser} = require('jison'));
23
+
24
+ // Jison DSL
25
+ // ---------
26
+
27
+ // Since we're going to be wrapped in a function by Jison in any case, if our
28
+ // action immediately returns a value, we can optimize by removing the function
29
+ // wrapper and just returning the value directly.
30
+ unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
31
+
32
+ // Our handy DSL for Jison grammar generation, thanks to
33
+ // [Tim Caswell](https://github.com/creationix). For every rule in the grammar,
34
+ // we pass the pattern-defining string, the action to run, and extra options,
35
+ // optionally. If no action is specified, we simply pass the value of the
36
+ // previous nonterminal.
37
+ o = function(patternString, action, options) {
38
+ var getAddDataToNodeFunctionString, match, patternCount, performActionFunctionString, returnsLoc;
39
+ patternString = patternString.replace(/\s{2,}/g, ' ');
40
+ patternCount = patternString.split(' ').length;
41
+ if (action) {
42
+ // This code block does string replacements in the generated `parser.js`
43
+ // file, replacing the calls to the `LOC` function and other strings as
44
+ // listed below.
45
+ action = (match = unwrap.exec(action)) ? match[1] : `(${action}())`;
46
+ // All runtime functions we need are defined on `yy`
47
+ action = action.replace(/\bnew /g, '$&yy.');
48
+ action = action.replace(/\b(?:Block\.wrap|extend)\b/g, 'yy.$&');
49
+ // Returns strings of functions to add to `parser.js` which add extra data
50
+ // that nodes may have, such as comments or location data. Location data
51
+ // is added to the first parameter passed in, and the parameter is returned.
52
+ // If the parameter is not a node, it will just be passed through unaffected.
53
+ getAddDataToNodeFunctionString = function(first, last, forceUpdateLocation = true) {
54
+ return `yy.addDataToNode(yy, @${first}, ${first[0] === '$' ? '$$' : '$'}${first}, ${last ? `@${last}, ${last[0] === '$' ? '$$' : '$'}${last}` : 'null, null'}, ${forceUpdateLocation ? 'true' : 'false'})`;
55
+ };
56
+ // This code replaces the calls to `LOC` with the `yy.addDataToNode` string
57
+ // defined above. The `LOC` function, when used below in the grammar rules,
58
+ // is used to make sure that newly created node class objects get correct
59
+ // location data assigned to them. By default, the grammar will assign the
60
+ // location data spanned by *all* of the tokens on the left (e.g. a string
61
+ // such as `'Body TERMINATOR Line'`) to the “top-level” node returned by
62
+ // the grammar rule (the function on the right). But for “inner” node class
63
+ // objects created by grammar rules, they won’t get correct location data
64
+ // assigned to them without adding `LOC`.
65
+
66
+ // For example, consider the grammar rule `'NEW_TARGET . Property'`, which
67
+ // is handled by a function that returns
68
+ // `new MetaProperty LOC(1)(new IdentifierLiteral $1), LOC(3)(new Access $3)`.
69
+ // The `1` in `LOC(1)` refers to the first token (`NEW_TARGET`) and the `3`
70
+ // in `LOC(3)` refers to the third token (`Property`). In order for the
71
+ // `new IdentifierLiteral` to get assigned the location data corresponding
72
+ // to `new` in the source code, we use
73
+ // `LOC(1)(new IdentifierLiteral ...)` to mean “assign the location data of
74
+ // the *first* token of this grammar rule (`NEW_TARGET`) to this
75
+ // `new IdentifierLiteral`”. The `LOC(3)` means “assign the location data of
76
+ // the *third* token of this grammar rule (`Property`) to this
77
+ // `new Access`”.
78
+ returnsLoc = /^LOC/.test(action);
79
+ action = action.replace(/LOC\(([0-9]*)\)/g, getAddDataToNodeFunctionString('$1'));
80
+ // A call to `LOC` with two arguments, e.g. `LOC(2,4)`, sets the location
81
+ // data for the generated node on both of the referenced tokens (the second
82
+ // and fourth in this example).
83
+ action = action.replace(/LOC\(([0-9]*),\s*([0-9]*)\)/g, getAddDataToNodeFunctionString('$1', '$2'));
84
+ performActionFunctionString = `$$ = ${getAddDataToNodeFunctionString(1, patternCount, !returnsLoc)}(${action});`;
85
+ } else {
86
+ performActionFunctionString = '$$ = $1;';
87
+ }
88
+ return [patternString, performActionFunctionString, options];
89
+ };
90
+
91
+ // Grammatical Rules
92
+ // -----------------
93
+
94
+ // In all of the rules that follow, you'll see the name of the nonterminal as
95
+ // the key to a list of alternative matches. With each match's action, the
96
+ // dollar-sign variables are provided by Jison as references to the value of
97
+ // their numeric position, so in this rule:
98
+
99
+ // 'Expression UNLESS Expression'
100
+
101
+ // `$1` would be the value of the first `Expression`, `$2` would be the token
102
+ // for the `UNLESS` terminal, and `$3` would be the value of the second
103
+ // `Expression`.
104
+ grammar = {
105
+ // The **Root** is the top-level node in the syntax tree. Since we parse bottom-up,
106
+ // all parsing must end here.
107
+ Root: [
108
+ o('',
109
+ function() {
110
+ return new Root(new Block());
111
+ }),
112
+ o('Body',
113
+ function() {
114
+ return new Root($1);
115
+ })
116
+ ],
117
+ // Any list of statements and expressions, separated by line breaks or semicolons.
118
+ Body: [
119
+ o('Line',
120
+ function() {
121
+ return Block.wrap([$1]);
122
+ }),
123
+ o('Body TERMINATOR Line',
124
+ function() {
125
+ return $1.push($3);
126
+ }),
127
+ o('Body TERMINATOR')
128
+ ],
129
+ // Block and statements, which make up a line in a body. FuncDirective is a
130
+ // statement, but not included in Statement because that results in an ambiguous
131
+ // grammar.
132
+ Line: [o('Expression'), o('ExpressionLine'), o('Statement'), o('FuncDirective')],
133
+ FuncDirective: [o('YieldReturn'), o('AwaitReturn')],
134
+ // Pure statements which cannot be expressions.
135
+ Statement: [
136
+ o('Return'),
137
+ o('STATEMENT',
138
+ function() {
139
+ return new StatementLiteral($1);
140
+ }),
141
+ o('Import'),
142
+ o('Export')
143
+ ],
144
+ // All the different types of expressions in our language. The basic unit of
145
+ // CoffeeScript is the **Expression** -- everything that can be an expression
146
+ // is one. Blocks serve as the building blocks of many other rules, making
147
+ // them somewhat circular.
148
+ Expression: [o('Value'), o('Code'), o('Operation'), o('Assign'), o('If'), o('Try'), o('While'), o('For'), o('Switch'), o('Class'), o('Throw'), o('Yield')],
149
+ // Expressions which are written in single line and would otherwise require being
150
+ // wrapped in braces: E.g `a = b if do -> f a is 1`, `if f (a) -> a*2 then ...`,
151
+ // `for x in do (obj) -> f obj when x > 8 then f x`
152
+ ExpressionLine: [o('CodeLine'), o('IfLine'), o('OperationLine')],
153
+ Yield: [
154
+ o('YIELD',
155
+ function() {
156
+ return new Op($1,
157
+ new Value(new Literal('')));
158
+ }),
159
+ o('YIELD Expression',
160
+ function() {
161
+ return new Op($1,
162
+ $2);
163
+ }),
164
+ o('YIELD INDENT Object OUTDENT',
165
+ function() {
166
+ return new Op($1,
167
+ $3);
168
+ }),
169
+ o('YIELD FROM Expression',
170
+ function() {
171
+ return new Op($1.concat($2),
172
+ $3);
173
+ })
174
+ ],
175
+ // An indented block of expressions. Note that the [Rewriter](rewriter.html)
176
+ // will convert some postfix forms into blocks for us, by adjusting the
177
+ // token stream.
178
+ Block: [
179
+ o('INDENT OUTDENT',
180
+ function() {
181
+ return new Block();
182
+ }),
183
+ o('INDENT Body OUTDENT',
184
+ function() {
185
+ return $2;
186
+ })
187
+ ],
188
+ Identifier: [
189
+ o('IDENTIFIER',
190
+ function() {
191
+ return new IdentifierLiteral($1);
192
+ }),
193
+ o('JSX_TAG',
194
+ function() {
195
+ var ref,
196
+ ref1,
197
+ ref2,
198
+ ref3;
199
+ return new JSXTag($1.toString(),
200
+ {
201
+ tagNameLocationData: $1.tagNameToken[2],
202
+ closingTagOpeningBracketLocationData: (ref = $1.closingTagOpeningBracketToken) != null ? ref[2] : void 0,
203
+ closingTagSlashLocationData: (ref1 = $1.closingTagSlashToken) != null ? ref1[2] : void 0,
204
+ closingTagNameLocationData: (ref2 = $1.closingTagNameToken) != null ? ref2[2] : void 0,
205
+ closingTagClosingBracketLocationData: (ref3 = $1.closingTagClosingBracketToken) != null ? ref3[2] : void 0
206
+ });
207
+ })
208
+ ],
209
+ Property: [
210
+ o('PROPERTY',
211
+ function() {
212
+ return new PropertyName($1.toString());
213
+ })
214
+ ],
215
+ // Alphanumerics are separated from the other **Literal** matchers because
216
+ // they can also serve as keys in object literals.
217
+ AlphaNumeric: [
218
+ o('NUMBER',
219
+ function() {
220
+ return new NumberLiteral($1.toString(),
221
+ {
222
+ parsedValue: $1.parsedValue
223
+ });
224
+ }),
225
+ o('String')
226
+ ],
227
+ String: [
228
+ o('STRING',
229
+ function() {
230
+ return new StringLiteral($1.slice(1,
231
+ -1), // strip artificial quotes and unwrap to primitive string
232
+ {
233
+ quote: $1.quote,
234
+ initialChunk: $1.initialChunk,
235
+ finalChunk: $1.finalChunk,
236
+ indent: $1.indent,
237
+ double: $1.double,
238
+ heregex: $1.heregex
239
+ });
240
+ }),
241
+ o('STRING_START Interpolations STRING_END',
242
+ function() {
243
+ return new StringWithInterpolations(Block.wrap($2),
244
+ {
245
+ quote: $1.quote,
246
+ startQuote: LOC(1)(new Literal($1.toString()))
247
+ });
248
+ })
249
+ ],
250
+ Interpolations: [
251
+ o('InterpolationChunk',
252
+ function() {
253
+ return [$1];
254
+ }),
255
+ o('Interpolations InterpolationChunk',
256
+ function() {
257
+ return $1.concat($2);
258
+ })
259
+ ],
260
+ InterpolationChunk: [
261
+ o('INTERPOLATION_START Body INTERPOLATION_END',
262
+ function() {
263
+ return new Interpolation($2);
264
+ }),
265
+ o('INTERPOLATION_START INDENT Body OUTDENT INTERPOLATION_END',
266
+ function() {
267
+ return new Interpolation($3);
268
+ }),
269
+ o('INTERPOLATION_START INTERPOLATION_END',
270
+ function() {
271
+ return new Interpolation();
272
+ }),
273
+ o('String',
274
+ function() {
275
+ return $1;
276
+ })
277
+ ],
278
+ // The .toString() calls here and elsewhere are to convert `String` objects
279
+ // back to primitive strings now that we've retrieved stowaway extra properties
280
+ Regex: [
281
+ o('REGEX',
282
+ function() {
283
+ return new RegexLiteral($1.toString(),
284
+ {
285
+ delimiter: $1.delimiter,
286
+ heregexCommentTokens: $1.heregexCommentTokens
287
+ });
288
+ }),
289
+ o('REGEX_START Invocation REGEX_END',
290
+ function() {
291
+ return new RegexWithInterpolations($2,
292
+ {
293
+ heregexCommentTokens: $3.heregexCommentTokens
294
+ });
295
+ })
296
+ ],
297
+ // All of our immediate values. Generally these can be passed straight
298
+ // through and printed to JavaScript.
299
+ Literal: [
300
+ o('AlphaNumeric'),
301
+ o('JS',
302
+ function() {
303
+ return new PassthroughLiteral($1.toString(),
304
+ {
305
+ here: $1.here,
306
+ generated: $1.generated
307
+ });
308
+ }),
309
+ o('Regex'),
310
+ o('UNDEFINED',
311
+ function() {
312
+ return new UndefinedLiteral($1);
313
+ }),
314
+ o('NULL',
315
+ function() {
316
+ return new NullLiteral($1);
317
+ }),
318
+ o('BOOL',
319
+ function() {
320
+ return new BooleanLiteral($1.toString(),
321
+ {
322
+ originalValue: $1.original
323
+ });
324
+ }),
325
+ o('INFINITY',
326
+ function() {
327
+ return new InfinityLiteral($1.toString(),
328
+ {
329
+ originalValue: $1.original
330
+ });
331
+ }),
332
+ o('NAN',
333
+ function() {
334
+ return new NaNLiteral($1);
335
+ })
336
+ ],
337
+ // Assignment of a variable, property, or index to a value.
338
+ Assign: [
339
+ o('Assignable = Expression',
340
+ function() {
341
+ return new Assign($1,
342
+ $3);
343
+ }),
344
+ o('Assignable = TERMINATOR Expression',
345
+ function() {
346
+ return new Assign($1,
347
+ $4);
348
+ }),
349
+ o('Assignable = INDENT Expression OUTDENT',
350
+ function() {
351
+ return new Assign($1,
352
+ $4);
353
+ })
354
+ ],
355
+ // Assignment when it happens within an object literal. The difference from
356
+ // the ordinary **Assign** is that these allow numbers and strings as keys.
357
+ AssignObj: [
358
+ o('ObjAssignable',
359
+ function() {
360
+ return new Value($1);
361
+ }),
362
+ o('ObjRestValue'),
363
+ o('ObjAssignable : Expression',
364
+ function() {
365
+ return new Assign(LOC(1)(new Value($1)),
366
+ $3,
367
+ 'object',
368
+ {
369
+ operatorToken: LOC(2)(new Literal($2))
370
+ });
371
+ }),
372
+ o('ObjAssignable : INDENT Expression OUTDENT',
373
+ function() {
374
+ return new Assign(LOC(1)(new Value($1)),
375
+ $4,
376
+ 'object',
377
+ {
378
+ operatorToken: LOC(2)(new Literal($2))
379
+ });
380
+ }),
381
+ o('SimpleObjAssignable = Expression',
382
+ function() {
383
+ return new Assign(LOC(1)(new Value($1)),
384
+ $3,
385
+ null,
386
+ {
387
+ operatorToken: LOC(2)(new Literal($2))
388
+ });
389
+ }),
390
+ o('SimpleObjAssignable = INDENT Expression OUTDENT',
391
+ function() {
392
+ return new Assign(LOC(1)(new Value($1)),
393
+ $4,
394
+ null,
395
+ {
396
+ operatorToken: LOC(2)(new Literal($2))
397
+ });
398
+ })
399
+ ],
400
+ SimpleObjAssignable: [o('Identifier'), o('Property'), o('ThisProperty')],
401
+ ObjAssignable: [
402
+ o('SimpleObjAssignable'),
403
+ o('[ Expression ]',
404
+ function() {
405
+ return new Value(new ComputedPropertyName($2));
406
+ }),
407
+ o('@ [ Expression ]',
408
+ function() {
409
+ return new Value(LOC(1)(new ThisLiteral($1)),
410
+ [LOC(3)(new ComputedPropertyName($3))],
411
+ 'this');
412
+ }),
413
+ o('AlphaNumeric')
414
+ ],
415
+ // Object literal spread properties.
416
+ ObjRestValue: [
417
+ o('SimpleObjAssignable ...',
418
+ function() {
419
+ return new Splat(new Value($1));
420
+ }),
421
+ o('... SimpleObjAssignable',
422
+ function() {
423
+ return new Splat(new Value($2),
424
+ {
425
+ postfix: false
426
+ });
427
+ }),
428
+ o('ObjSpreadExpr ...',
429
+ function() {
430
+ return new Splat($1);
431
+ }),
432
+ o('... ObjSpreadExpr',
433
+ function() {
434
+ return new Splat($2,
435
+ {
436
+ postfix: false
437
+ });
438
+ })
439
+ ],
440
+ ObjSpreadExpr: [
441
+ o('ObjSpreadIdentifier'),
442
+ o('Object'),
443
+ o('Parenthetical'),
444
+ o('Super'),
445
+ o('This'),
446
+ o('SUPER OptFuncExist Arguments',
447
+ function() {
448
+ return new SuperCall(LOC(1)(new Super()),
449
+ $3,
450
+ $2.soak,
451
+ $1);
452
+ }),
453
+ o('DYNAMIC_IMPORT Arguments',
454
+ function() {
455
+ return new DynamicImportCall(LOC(1)(new DynamicImport()),
456
+ $2);
457
+ }),
458
+ o('SimpleObjAssignable OptFuncExist Arguments',
459
+ function() {
460
+ return new Call(new Value($1),
461
+ $3,
462
+ $2.soak);
463
+ }),
464
+ o('ObjSpreadExpr OptFuncExist Arguments',
465
+ function() {
466
+ return new Call($1,
467
+ $3,
468
+ $2.soak);
469
+ })
470
+ ],
471
+ ObjSpreadIdentifier: [
472
+ o('SimpleObjAssignable Accessor',
473
+ function() {
474
+ return (new Value($1)).add($2);
475
+ }),
476
+ o('ObjSpreadExpr Accessor',
477
+ function() {
478
+ return (new Value($1)).add($2);
479
+ })
480
+ ],
481
+ // A return statement from a function body.
482
+ Return: [
483
+ o('RETURN Expression',
484
+ function() {
485
+ return new Return($2);
486
+ }),
487
+ o('RETURN INDENT Object OUTDENT',
488
+ function() {
489
+ return new Return(new Value($3));
490
+ }),
491
+ o('RETURN',
492
+ function() {
493
+ return new Return();
494
+ })
495
+ ],
496
+ YieldReturn: [
497
+ o('YIELD RETURN Expression',
498
+ function() {
499
+ return new YieldReturn($3,
500
+ {
501
+ returnKeyword: LOC(2)(new Literal($2))
502
+ });
503
+ }),
504
+ o('YIELD RETURN',
505
+ function() {
506
+ return new YieldReturn(null,
507
+ {
508
+ returnKeyword: LOC(2)(new Literal($2))
509
+ });
510
+ })
511
+ ],
512
+ AwaitReturn: [
513
+ o('AWAIT RETURN Expression',
514
+ function() {
515
+ return new AwaitReturn($3,
516
+ {
517
+ returnKeyword: LOC(2)(new Literal($2))
518
+ });
519
+ }),
520
+ o('AWAIT RETURN',
521
+ function() {
522
+ return new AwaitReturn(null,
523
+ {
524
+ returnKeyword: LOC(2)(new Literal($2))
525
+ });
526
+ })
527
+ ],
528
+ // The **Code** node is the function literal. It’s defined by an indented block
529
+ // of **Block** preceded by a function arrow, with an optional parameter list.
530
+ Code: [
531
+ o('PARAM_START ParamList PARAM_END FuncGlyph Block',
532
+ function() {
533
+ return new Code($2,
534
+ $5,
535
+ $4,
536
+ LOC(1)(new Literal($1)));
537
+ }),
538
+ o('FuncGlyph Block',
539
+ function() {
540
+ return new Code([],
541
+ $2,
542
+ $1);
543
+ })
544
+ ],
545
+ // The Codeline is the **Code** node with **Line** instead of indented **Block**.
546
+ CodeLine: [
547
+ o('PARAM_START ParamList PARAM_END FuncGlyph Line',
548
+ function() {
549
+ return new Code($2,
550
+ LOC(5)(Block.wrap([$5])),
551
+ $4,
552
+ LOC(1)(new Literal($1)));
553
+ }),
554
+ o('FuncGlyph Line',
555
+ function() {
556
+ return new Code([],
557
+ LOC(2)(Block.wrap([$2])),
558
+ $1);
559
+ })
560
+ ],
561
+ // CoffeeScript has two different symbols for functions. `->` is for ordinary
562
+ // functions, and `=>` is for functions bound to the current value of *this*.
563
+ FuncGlyph: [
564
+ o('->',
565
+ function() {
566
+ return new FuncGlyph($1);
567
+ }),
568
+ o('=>',
569
+ function() {
570
+ return new FuncGlyph($1);
571
+ })
572
+ ],
573
+ // An optional, trailing comma.
574
+ OptComma: [o(''), o(',')],
575
+ // The list of parameters that a function accepts can be of any length.
576
+ ParamList: [
577
+ o('',
578
+ function() {
579
+ return [];
580
+ }),
581
+ o('Param',
582
+ function() {
583
+ return [$1];
584
+ }),
585
+ o('ParamList , Param',
586
+ function() {
587
+ return $1.concat($3);
588
+ }),
589
+ o('ParamList OptComma TERMINATOR Param',
590
+ function() {
591
+ return $1.concat($4);
592
+ }),
593
+ o('ParamList OptComma INDENT ParamList OptComma OUTDENT',
594
+ function() {
595
+ return $1.concat($4);
596
+ })
597
+ ],
598
+ // A single parameter in a function definition can be ordinary, or a splat
599
+ // that hoovers up the remaining arguments.
600
+ Param: [
601
+ o('ParamVar',
602
+ function() {
603
+ return new Param($1);
604
+ }),
605
+ o('ParamVar ...',
606
+ function() {
607
+ return new Param($1,
608
+ null,
609
+ true);
610
+ }),
611
+ o('... ParamVar',
612
+ function() {
613
+ return new Param($2,
614
+ null,
615
+ {
616
+ postfix: false
617
+ });
618
+ }),
619
+ o('ParamVar = Expression',
620
+ function() {
621
+ return new Param($1,
622
+ $3);
623
+ }),
624
+ o('...',
625
+ function() {
626
+ return new Expansion();
627
+ })
628
+ ],
629
+ // Function Parameters
630
+ ParamVar: [o('Identifier'), o('ThisProperty'), o('Array'), o('Object')],
631
+ // A splat that occurs outside of a parameter list.
632
+ Splat: [
633
+ o('Expression ...',
634
+ function() {
635
+ return new Splat($1);
636
+ }),
637
+ o('... Expression',
638
+ function() {
639
+ return new Splat($2,
640
+ {
641
+ postfix: false
642
+ });
643
+ })
644
+ ],
645
+ // Variables and properties that can be assigned to.
646
+ SimpleAssignable: [
647
+ o('Identifier',
648
+ function() {
649
+ return new Value($1);
650
+ }),
651
+ o('Value Accessor',
652
+ function() {
653
+ return $1.add($2);
654
+ }),
655
+ o('Code Accessor',
656
+ function() {
657
+ return new Value($1).add($2);
658
+ }),
659
+ o('ThisProperty')
660
+ ],
661
+ // Everything that can be assigned to.
662
+ Assignable: [
663
+ o('SimpleAssignable'),
664
+ o('Array',
665
+ function() {
666
+ return new Value($1);
667
+ }),
668
+ o('Object',
669
+ function() {
670
+ return new Value($1);
671
+ })
672
+ ],
673
+ // The types of things that can be treated as values -- assigned to, invoked
674
+ // as functions, indexed into, named as a class, etc.
675
+ Value: [
676
+ o('Assignable'),
677
+ o('Literal',
678
+ function() {
679
+ return new Value($1);
680
+ }),
681
+ o('Parenthetical',
682
+ function() {
683
+ return new Value($1);
684
+ }),
685
+ o('Range',
686
+ function() {
687
+ return new Value($1);
688
+ }),
689
+ o('Invocation',
690
+ function() {
691
+ return new Value($1);
692
+ }),
693
+ o('DoIife',
694
+ function() {
695
+ return new Value($1);
696
+ }),
697
+ o('This'),
698
+ o('Super',
699
+ function() {
700
+ return new Value($1);
701
+ }),
702
+ o('MetaProperty',
703
+ function() {
704
+ return new Value($1);
705
+ })
706
+ ],
707
+ // A `super`-based expression that can be used as a value.
708
+ Super: [
709
+ o('SUPER . Property',
710
+ function() {
711
+ return new Super(LOC(3)(new Access($3)),
712
+ LOC(1)(new Literal($1)));
713
+ }),
714
+ o('SUPER INDEX_START Expression INDEX_END',
715
+ function() {
716
+ return new Super(LOC(3)(new Index($3)),
717
+ LOC(1)(new Literal($1)));
718
+ }),
719
+ o('SUPER INDEX_START INDENT Expression OUTDENT INDEX_END',
720
+ function() {
721
+ return new Super(LOC(4)(new Index($4)),
722
+ LOC(1)(new Literal($1)));
723
+ })
724
+ ],
725
+ // A “meta-property” access e.g. `new.target` or `import.meta`, where
726
+ // something that looks like a property is referenced on a keyword.
727
+ MetaProperty: [
728
+ o('NEW_TARGET . Property',
729
+ function() {
730
+ return new MetaProperty(LOC(1)(new IdentifierLiteral($1)),
731
+ LOC(3)(new Access($3)));
732
+ }),
733
+ o('IMPORT_META . Property',
734
+ function() {
735
+ return new MetaProperty(LOC(1)(new IdentifierLiteral($1)),
736
+ LOC(3)(new Access($3)));
737
+ })
738
+ ],
739
+ // The general group of accessors into an object, by property, by prototype
740
+ // or by array index or slice.
741
+ Accessor: [
742
+ o('. Property',
743
+ function() {
744
+ return new Access($2);
745
+ }),
746
+ o('?. Property',
747
+ function() {
748
+ return new Access($2,
749
+ {
750
+ soak: true
751
+ });
752
+ }),
753
+ o(':: Property',
754
+ function() {
755
+ return [
756
+ LOC(1)(new Access(new PropertyName('prototype'),
757
+ {
758
+ shorthand: true
759
+ })),
760
+ LOC(2)(new Access($2))
761
+ ];
762
+ }),
763
+ o('?:: Property',
764
+ function() {
765
+ return [
766
+ LOC(1)(new Access(new PropertyName('prototype'),
767
+ {
768
+ shorthand: true,
769
+ soak: true
770
+ })),
771
+ LOC(2)(new Access($2))
772
+ ];
773
+ }),
774
+ o('::',
775
+ function() {
776
+ return new Access(new PropertyName('prototype'),
777
+ {
778
+ shorthand: true
779
+ });
780
+ }),
781
+ o('?::',
782
+ function() {
783
+ return new Access(new PropertyName('prototype'),
784
+ {
785
+ shorthand: true,
786
+ soak: true
787
+ });
788
+ }),
789
+ o('Index')
790
+ ],
791
+ // Indexing into an object or array using bracket notation.
792
+ Index: [
793
+ o('INDEX_START IndexValue INDEX_END',
794
+ function() {
795
+ return $2;
796
+ }),
797
+ o('INDEX_START INDENT IndexValue OUTDENT INDEX_END',
798
+ function() {
799
+ return $3;
800
+ }),
801
+ o('INDEX_SOAK Index',
802
+ function() {
803
+ return extend($2,
804
+ {
805
+ soak: true
806
+ });
807
+ })
808
+ ],
809
+ IndexValue: [
810
+ o('Expression',
811
+ function() {
812
+ return new Index($1);
813
+ }),
814
+ o('Slice',
815
+ function() {
816
+ return new Slice($1);
817
+ })
818
+ ],
819
+ // In CoffeeScript, an object literal is simply a list of assignments.
820
+ Object: [
821
+ o('{ AssignList OptComma }',
822
+ function() {
823
+ return new Obj($2,
824
+ $1.generated);
825
+ })
826
+ ],
827
+ // Assignment of properties within an object literal can be separated by
828
+ // comma, as in JavaScript, or simply by newline.
829
+ AssignList: [
830
+ o('',
831
+ function() {
832
+ return [];
833
+ }),
834
+ o('AssignObj',
835
+ function() {
836
+ return [$1];
837
+ }),
838
+ o('AssignList , AssignObj',
839
+ function() {
840
+ return $1.concat($3);
841
+ }),
842
+ o('AssignList OptComma TERMINATOR AssignObj',
843
+ function() {
844
+ return $1.concat($4);
845
+ }),
846
+ o('AssignList OptComma INDENT AssignList OptComma OUTDENT',
847
+ function() {
848
+ return $1.concat($4);
849
+ })
850
+ ],
851
+ // Class definitions have optional bodies of prototype property assignments,
852
+ // and optional references to the superclass.
853
+ Class: [
854
+ o('CLASS',
855
+ function() {
856
+ return new Class();
857
+ }),
858
+ o('CLASS Block',
859
+ function() {
860
+ return new Class(null,
861
+ null,
862
+ $2);
863
+ }),
864
+ o('CLASS EXTENDS Expression',
865
+ function() {
866
+ return new Class(null,
867
+ $3);
868
+ }),
869
+ o('CLASS EXTENDS Expression Block',
870
+ function() {
871
+ return new Class(null,
872
+ $3,
873
+ $4);
874
+ }),
875
+ o('CLASS SimpleAssignable',
876
+ function() {
877
+ return new Class($2);
878
+ }),
879
+ o('CLASS SimpleAssignable Block',
880
+ function() {
881
+ return new Class($2,
882
+ null,
883
+ $3);
884
+ }),
885
+ o('CLASS SimpleAssignable EXTENDS Expression',
886
+ function() {
887
+ return new Class($2,
888
+ $4);
889
+ }),
890
+ o('CLASS SimpleAssignable EXTENDS Expression Block',
891
+ function() {
892
+ return new Class($2,
893
+ $4,
894
+ $5);
895
+ })
896
+ ],
897
+ Import: [
898
+ o('IMPORT String',
899
+ function() {
900
+ return new ImportDeclaration(null,
901
+ $2);
902
+ }),
903
+ o('IMPORT String ASSERT Object',
904
+ function() {
905
+ return new ImportDeclaration(null,
906
+ $2,
907
+ $4);
908
+ }),
909
+ o('IMPORT ImportDefaultSpecifier FROM String',
910
+ function() {
911
+ return new ImportDeclaration(new ImportClause($2,
912
+ null),
913
+ $4);
914
+ }),
915
+ o('IMPORT ImportDefaultSpecifier FROM String ASSERT Object',
916
+ function() {
917
+ return new ImportDeclaration(new ImportClause($2,
918
+ null),
919
+ $4,
920
+ $6);
921
+ }),
922
+ o('IMPORT ImportNamespaceSpecifier FROM String',
923
+ function() {
924
+ return new ImportDeclaration(new ImportClause(null,
925
+ $2),
926
+ $4);
927
+ }),
928
+ o('IMPORT ImportNamespaceSpecifier FROM String ASSERT Object',
929
+ function() {
930
+ return new ImportDeclaration(new ImportClause(null,
931
+ $2),
932
+ $4,
933
+ $6);
934
+ }),
935
+ o('IMPORT { } FROM String',
936
+ function() {
937
+ return new ImportDeclaration(new ImportClause(null,
938
+ new ImportSpecifierList([])),
939
+ $5);
940
+ }),
941
+ o('IMPORT { } FROM String ASSERT Object',
942
+ function() {
943
+ return new ImportDeclaration(new ImportClause(null,
944
+ new ImportSpecifierList([])),
945
+ $5,
946
+ $7);
947
+ }),
948
+ o('IMPORT { ImportSpecifierList OptComma } FROM String',
949
+ function() {
950
+ return new ImportDeclaration(new ImportClause(null,
951
+ new ImportSpecifierList($3)),
952
+ $7);
953
+ }),
954
+ o('IMPORT { ImportSpecifierList OptComma } FROM String ASSERT Object',
955
+ function() {
956
+ return new ImportDeclaration(new ImportClause(null,
957
+ new ImportSpecifierList($3)),
958
+ $7,
959
+ $9);
960
+ }),
961
+ o('IMPORT ImportDefaultSpecifier , ImportNamespaceSpecifier FROM String',
962
+ function() {
963
+ return new ImportDeclaration(new ImportClause($2,
964
+ $4),
965
+ $6);
966
+ }),
967
+ o('IMPORT ImportDefaultSpecifier , ImportNamespaceSpecifier FROM String ASSERT Object',
968
+ function() {
969
+ return new ImportDeclaration(new ImportClause($2,
970
+ $4),
971
+ $6,
972
+ $8);
973
+ }),
974
+ o('IMPORT ImportDefaultSpecifier , { ImportSpecifierList OptComma } FROM String',
975
+ function() {
976
+ return new ImportDeclaration(new ImportClause($2,
977
+ new ImportSpecifierList($5)),
978
+ $9);
979
+ }),
980
+ o('IMPORT ImportDefaultSpecifier , { ImportSpecifierList OptComma } FROM String ASSERT Object',
981
+ function() {
982
+ return new ImportDeclaration(new ImportClause($2,
983
+ new ImportSpecifierList($5)),
984
+ $9,
985
+ $11);
986
+ })
987
+ ],
988
+ ImportSpecifierList: [
989
+ o('ImportSpecifier',
990
+ function() {
991
+ return [$1];
992
+ }),
993
+ o('ImportSpecifierList , ImportSpecifier',
994
+ function() {
995
+ return $1.concat($3);
996
+ }),
997
+ o('ImportSpecifierList OptComma TERMINATOR ImportSpecifier',
998
+ function() {
999
+ return $1.concat($4);
1000
+ }),
1001
+ o('INDENT ImportSpecifierList OptComma OUTDENT',
1002
+ function() {
1003
+ return $2;
1004
+ }),
1005
+ o('ImportSpecifierList OptComma INDENT ImportSpecifierList OptComma OUTDENT',
1006
+ function() {
1007
+ return $1.concat($4);
1008
+ })
1009
+ ],
1010
+ ImportSpecifier: [
1011
+ o('Identifier',
1012
+ function() {
1013
+ return new ImportSpecifier($1);
1014
+ }),
1015
+ o('Identifier AS Identifier',
1016
+ function() {
1017
+ return new ImportSpecifier($1,
1018
+ $3);
1019
+ }),
1020
+ o('DEFAULT',
1021
+ function() {
1022
+ return new ImportSpecifier(LOC(1)(new DefaultLiteral($1)));
1023
+ }),
1024
+ o('DEFAULT AS Identifier',
1025
+ function() {
1026
+ return new ImportSpecifier(LOC(1)(new DefaultLiteral($1)),
1027
+ $3);
1028
+ })
1029
+ ],
1030
+ ImportDefaultSpecifier: [
1031
+ o('Identifier',
1032
+ function() {
1033
+ return new ImportDefaultSpecifier($1);
1034
+ })
1035
+ ],
1036
+ ImportNamespaceSpecifier: [
1037
+ o('IMPORT_ALL AS Identifier',
1038
+ function() {
1039
+ return new ImportNamespaceSpecifier(new Literal($1),
1040
+ $3);
1041
+ })
1042
+ ],
1043
+ Export: [
1044
+ o('EXPORT { }',
1045
+ function() {
1046
+ return new ExportNamedDeclaration(new ExportSpecifierList([]));
1047
+ }),
1048
+ o('EXPORT { ExportSpecifierList OptComma }',
1049
+ function() {
1050
+ return new ExportNamedDeclaration(new ExportSpecifierList($3));
1051
+ }),
1052
+ o('EXPORT Class',
1053
+ function() {
1054
+ return new ExportNamedDeclaration($2);
1055
+ }),
1056
+ o('EXPORT Identifier = Expression',
1057
+ function() {
1058
+ return new ExportNamedDeclaration(LOC(2,
1059
+ 4)(new Assign($2,
1060
+ $4,
1061
+ null,
1062
+ {
1063
+ moduleDeclaration: 'export'
1064
+ })));
1065
+ }),
1066
+ o('EXPORT Identifier = TERMINATOR Expression',
1067
+ function() {
1068
+ return new ExportNamedDeclaration(LOC(2,
1069
+ 5)(new Assign($2,
1070
+ $5,
1071
+ null,
1072
+ {
1073
+ moduleDeclaration: 'export'
1074
+ })));
1075
+ }),
1076
+ o('EXPORT Identifier = INDENT Expression OUTDENT',
1077
+ function() {
1078
+ return new ExportNamedDeclaration(LOC(2,
1079
+ 6)(new Assign($2,
1080
+ $5,
1081
+ null,
1082
+ {
1083
+ moduleDeclaration: 'export'
1084
+ })));
1085
+ }),
1086
+ o('EXPORT DEFAULT Expression',
1087
+ function() {
1088
+ return new ExportDefaultDeclaration($3);
1089
+ }),
1090
+ o('EXPORT DEFAULT INDENT Object OUTDENT',
1091
+ function() {
1092
+ return new ExportDefaultDeclaration(new Value($4));
1093
+ }),
1094
+ o('EXPORT EXPORT_ALL FROM String',
1095
+ function() {
1096
+ return new ExportAllDeclaration(new Literal($2),
1097
+ $4);
1098
+ }),
1099
+ o('EXPORT EXPORT_ALL FROM String ASSERT Object',
1100
+ function() {
1101
+ return new ExportAllDeclaration(new Literal($2),
1102
+ $4,
1103
+ $6);
1104
+ }),
1105
+ o('EXPORT { } FROM String',
1106
+ function() {
1107
+ return new ExportNamedDeclaration(new ExportSpecifierList([]),
1108
+ $5);
1109
+ }),
1110
+ o('EXPORT { } FROM String ASSERT Object',
1111
+ function() {
1112
+ return new ExportNamedDeclaration(new ExportSpecifierList([]),
1113
+ $5,
1114
+ $7);
1115
+ }),
1116
+ o('EXPORT { ExportSpecifierList OptComma } FROM String',
1117
+ function() {
1118
+ return new ExportNamedDeclaration(new ExportSpecifierList($3),
1119
+ $7);
1120
+ }),
1121
+ o('EXPORT { ExportSpecifierList OptComma } FROM String ASSERT Object',
1122
+ function() {
1123
+ return new ExportNamedDeclaration(new ExportSpecifierList($3),
1124
+ $7,
1125
+ $9);
1126
+ })
1127
+ ],
1128
+ ExportSpecifierList: [
1129
+ o('ExportSpecifier',
1130
+ function() {
1131
+ return [$1];
1132
+ }),
1133
+ o('ExportSpecifierList , ExportSpecifier',
1134
+ function() {
1135
+ return $1.concat($3);
1136
+ }),
1137
+ o('ExportSpecifierList OptComma TERMINATOR ExportSpecifier',
1138
+ function() {
1139
+ return $1.concat($4);
1140
+ }),
1141
+ o('INDENT ExportSpecifierList OptComma OUTDENT',
1142
+ function() {
1143
+ return $2;
1144
+ }),
1145
+ o('ExportSpecifierList OptComma INDENT ExportSpecifierList OptComma OUTDENT',
1146
+ function() {
1147
+ return $1.concat($4);
1148
+ })
1149
+ ],
1150
+ ExportSpecifier: [
1151
+ o('Identifier',
1152
+ function() {
1153
+ return new ExportSpecifier($1);
1154
+ }),
1155
+ o('Identifier AS Identifier',
1156
+ function() {
1157
+ return new ExportSpecifier($1,
1158
+ $3);
1159
+ }),
1160
+ o('Identifier AS DEFAULT',
1161
+ function() {
1162
+ return new ExportSpecifier($1,
1163
+ LOC(3)(new DefaultLiteral($3)));
1164
+ }),
1165
+ o('DEFAULT',
1166
+ function() {
1167
+ return new ExportSpecifier(LOC(1)(new DefaultLiteral($1)));
1168
+ }),
1169
+ o('DEFAULT AS Identifier',
1170
+ function() {
1171
+ return new ExportSpecifier(LOC(1)(new DefaultLiteral($1)),
1172
+ $3);
1173
+ })
1174
+ ],
1175
+ // Ordinary function invocation, or a chained series of calls.
1176
+ Invocation: [
1177
+ o('Value OptFuncExist String',
1178
+ function() {
1179
+ return new TaggedTemplateCall($1,
1180
+ $3,
1181
+ $2.soak);
1182
+ }),
1183
+ o('Value OptFuncExist Arguments',
1184
+ function() {
1185
+ return new Call($1,
1186
+ $3,
1187
+ $2.soak);
1188
+ }),
1189
+ o('SUPER OptFuncExist Arguments',
1190
+ function() {
1191
+ return new SuperCall(LOC(1)(new Super()),
1192
+ $3,
1193
+ $2.soak,
1194
+ $1);
1195
+ }),
1196
+ o('DYNAMIC_IMPORT Arguments',
1197
+ function() {
1198
+ return new DynamicImportCall(LOC(1)(new DynamicImport()),
1199
+ $2);
1200
+ })
1201
+ ],
1202
+ // An optional existence check on a function.
1203
+ OptFuncExist: [
1204
+ o('',
1205
+ function() {
1206
+ return {
1207
+ soak: false
1208
+ };
1209
+ }),
1210
+ o('FUNC_EXIST',
1211
+ function() {
1212
+ return {
1213
+ soak: true
1214
+ };
1215
+ })
1216
+ ],
1217
+ // The list of arguments to a function call.
1218
+ Arguments: [
1219
+ o('CALL_START CALL_END',
1220
+ function() {
1221
+ return [];
1222
+ }),
1223
+ o('CALL_START ArgList OptComma CALL_END',
1224
+ function() {
1225
+ $2.implicit = $1.generated;
1226
+ return $2;
1227
+ })
1228
+ ],
1229
+ // A reference to the *this* current object.
1230
+ This: [
1231
+ o('THIS',
1232
+ function() {
1233
+ return new Value(new ThisLiteral($1));
1234
+ }),
1235
+ o('@',
1236
+ function() {
1237
+ return new Value(new ThisLiteral($1));
1238
+ })
1239
+ ],
1240
+ // A reference to a property on *this*.
1241
+ ThisProperty: [
1242
+ o('@ Property',
1243
+ function() {
1244
+ return new Value(LOC(1)(new ThisLiteral($1)),
1245
+ [LOC(2)(new Access($2))],
1246
+ 'this');
1247
+ })
1248
+ ],
1249
+ // The array literal.
1250
+ Array: [
1251
+ o('[ ]',
1252
+ function() {
1253
+ return new Arr([]);
1254
+ }),
1255
+ o('[ Elisions ]',
1256
+ function() {
1257
+ return new Arr($2);
1258
+ }),
1259
+ o('[ ArgElisionList OptElisions ]',
1260
+ function() {
1261
+ return new Arr([].concat($2,
1262
+ $3));
1263
+ })
1264
+ ],
1265
+ // Inclusive and exclusive range dots.
1266
+ RangeDots: [
1267
+ o('..',
1268
+ function() {
1269
+ return {
1270
+ exclusive: false
1271
+ };
1272
+ }),
1273
+ o('...',
1274
+ function() {
1275
+ return {
1276
+ exclusive: true
1277
+ };
1278
+ })
1279
+ ],
1280
+ // The CoffeeScript range literal.
1281
+ Range: [
1282
+ o('[ Expression RangeDots Expression ]',
1283
+ function() {
1284
+ return new Range($2,
1285
+ $4,
1286
+ $3.exclusive ? 'exclusive' : 'inclusive');
1287
+ }),
1288
+ o('[ ExpressionLine RangeDots Expression ]',
1289
+ function() {
1290
+ return new Range($2,
1291
+ $4,
1292
+ $3.exclusive ? 'exclusive' : 'inclusive');
1293
+ })
1294
+ ],
1295
+ // Array slice literals.
1296
+ Slice: [
1297
+ o('Expression RangeDots Expression',
1298
+ function() {
1299
+ return new Range($1,
1300
+ $3,
1301
+ $2.exclusive ? 'exclusive' : 'inclusive');
1302
+ }),
1303
+ o('Expression RangeDots',
1304
+ function() {
1305
+ return new Range($1,
1306
+ null,
1307
+ $2.exclusive ? 'exclusive' : 'inclusive');
1308
+ }),
1309
+ o('ExpressionLine RangeDots Expression',
1310
+ function() {
1311
+ return new Range($1,
1312
+ $3,
1313
+ $2.exclusive ? 'exclusive' : 'inclusive');
1314
+ }),
1315
+ o('ExpressionLine RangeDots',
1316
+ function() {
1317
+ return new Range($1,
1318
+ null,
1319
+ $2.exclusive ? 'exclusive' : 'inclusive');
1320
+ }),
1321
+ o('RangeDots Expression',
1322
+ function() {
1323
+ return new Range(null,
1324
+ $2,
1325
+ $1.exclusive ? 'exclusive' : 'inclusive');
1326
+ }),
1327
+ o('RangeDots',
1328
+ function() {
1329
+ return new Range(null,
1330
+ null,
1331
+ $1.exclusive ? 'exclusive' : 'inclusive');
1332
+ })
1333
+ ],
1334
+ // The **ArgList** is the list of objects passed into a function call
1335
+ // (i.e. comma-separated expressions). Newlines work as well.
1336
+ ArgList: [
1337
+ o('Arg',
1338
+ function() {
1339
+ return [$1];
1340
+ }),
1341
+ o('ArgList , Arg',
1342
+ function() {
1343
+ return $1.concat($3);
1344
+ }),
1345
+ o('ArgList OptComma TERMINATOR Arg',
1346
+ function() {
1347
+ return $1.concat($4);
1348
+ }),
1349
+ o('INDENT ArgList OptComma OUTDENT',
1350
+ function() {
1351
+ return $2;
1352
+ }),
1353
+ o('ArgList OptComma INDENT ArgList OptComma OUTDENT',
1354
+ function() {
1355
+ return $1.concat($4);
1356
+ })
1357
+ ],
1358
+ // Valid arguments are Blocks or Splats.
1359
+ Arg: [
1360
+ o('Expression'),
1361
+ o('ExpressionLine'),
1362
+ o('Splat'),
1363
+ o('...',
1364
+ function() {
1365
+ return new Expansion();
1366
+ })
1367
+ ],
1368
+ // The **ArgElisionList** is the list of objects, contents of an array literal
1369
+ // (i.e. comma-separated expressions and elisions). Newlines work as well.
1370
+ ArgElisionList: [
1371
+ o('ArgElision'),
1372
+ o('ArgElisionList , ArgElision',
1373
+ function() {
1374
+ return $1.concat($3);
1375
+ }),
1376
+ o('ArgElisionList OptComma TERMINATOR ArgElision',
1377
+ function() {
1378
+ return $1.concat($4);
1379
+ }),
1380
+ o('INDENT ArgElisionList OptElisions OUTDENT',
1381
+ function() {
1382
+ return $2.concat($3);
1383
+ }),
1384
+ o('ArgElisionList OptElisions INDENT ArgElisionList OptElisions OUTDENT',
1385
+ function() {
1386
+ return $1.concat($2,
1387
+ $4,
1388
+ $5);
1389
+ })
1390
+ ],
1391
+ ArgElision: [
1392
+ o('Arg',
1393
+ function() {
1394
+ return [$1];
1395
+ }),
1396
+ o('Elisions Arg',
1397
+ function() {
1398
+ return $1.concat($2);
1399
+ })
1400
+ ],
1401
+ OptElisions: [
1402
+ o('OptComma',
1403
+ function() {
1404
+ return [];
1405
+ }),
1406
+ o(', Elisions',
1407
+ function() {
1408
+ return [].concat($2);
1409
+ })
1410
+ ],
1411
+ Elisions: [
1412
+ o('Elision',
1413
+ function() {
1414
+ return [$1];
1415
+ }),
1416
+ o('Elisions Elision',
1417
+ function() {
1418
+ return $1.concat($2);
1419
+ })
1420
+ ],
1421
+ Elision: [
1422
+ o(',',
1423
+ function() {
1424
+ return new Elision();
1425
+ }),
1426
+ o('Elision TERMINATOR',
1427
+ function() {
1428
+ return $1;
1429
+ })
1430
+ ],
1431
+ // Just simple, comma-separated, required arguments (no fancy syntax). We need
1432
+ // this to be separate from the **ArgList** for use in **Switch** blocks, where
1433
+ // having the newlines wouldn't make sense.
1434
+ SimpleArgs: [
1435
+ o('Expression'),
1436
+ o('ExpressionLine'),
1437
+ o('SimpleArgs , Expression',
1438
+ function() {
1439
+ return [].concat($1,
1440
+ $3);
1441
+ }),
1442
+ o('SimpleArgs , ExpressionLine',
1443
+ function() {
1444
+ return [].concat($1,
1445
+ $3);
1446
+ })
1447
+ ],
1448
+ // The variants of *try/catch/finally* exception handling blocks.
1449
+ Try: [
1450
+ o('TRY Block',
1451
+ function() {
1452
+ return new Try($2);
1453
+ }),
1454
+ o('TRY Block Catch',
1455
+ function() {
1456
+ return new Try($2,
1457
+ $3);
1458
+ }),
1459
+ o('TRY Block FINALLY Block',
1460
+ function() {
1461
+ return new Try($2,
1462
+ null,
1463
+ $4,
1464
+ LOC(3)(new Literal($3)));
1465
+ }),
1466
+ o('TRY Block Catch FINALLY Block',
1467
+ function() {
1468
+ return new Try($2,
1469
+ $3,
1470
+ $5,
1471
+ LOC(4)(new Literal($4)));
1472
+ })
1473
+ ],
1474
+ // A catch clause names its error and runs a block of code.
1475
+ Catch: [
1476
+ o('CATCH Identifier Block',
1477
+ function() {
1478
+ return new Catch($3,
1479
+ $2);
1480
+ }),
1481
+ o('CATCH Object Block',
1482
+ function() {
1483
+ return new Catch($3,
1484
+ LOC(2)(new Value($2)));
1485
+ }),
1486
+ o('CATCH Block',
1487
+ function() {
1488
+ return new Catch($2);
1489
+ })
1490
+ ],
1491
+ // Throw an exception object.
1492
+ Throw: [
1493
+ o('THROW Expression',
1494
+ function() {
1495
+ return new Throw($2);
1496
+ }),
1497
+ o('THROW INDENT Object OUTDENT',
1498
+ function() {
1499
+ return new Throw(new Value($3));
1500
+ })
1501
+ ],
1502
+ // Parenthetical expressions. Note that the **Parenthetical** is a **Value**,
1503
+ // not an **Expression**, so if you need to use an expression in a place
1504
+ // where only values are accepted, wrapping it in parentheses will always do
1505
+ // the trick.
1506
+ Parenthetical: [
1507
+ o('( Body )',
1508
+ function() {
1509
+ return new Parens($2);
1510
+ }),
1511
+ o('( INDENT Body OUTDENT )',
1512
+ function() {
1513
+ return new Parens($3);
1514
+ })
1515
+ ],
1516
+ // The condition portion of a while loop.
1517
+ WhileLineSource: [
1518
+ o('WHILE ExpressionLine',
1519
+ function() {
1520
+ return new While($2);
1521
+ }),
1522
+ o('WHILE ExpressionLine WHEN ExpressionLine',
1523
+ function() {
1524
+ return new While($2,
1525
+ {
1526
+ guard: $4
1527
+ });
1528
+ }),
1529
+ o('UNTIL ExpressionLine',
1530
+ function() {
1531
+ return new While($2,
1532
+ {
1533
+ invert: true
1534
+ });
1535
+ }),
1536
+ o('UNTIL ExpressionLine WHEN ExpressionLine',
1537
+ function() {
1538
+ return new While($2,
1539
+ {
1540
+ invert: true,
1541
+ guard: $4
1542
+ });
1543
+ })
1544
+ ],
1545
+ WhileSource: [
1546
+ o('WHILE Expression',
1547
+ function() {
1548
+ return new While($2);
1549
+ }),
1550
+ o('WHILE Expression WHEN Expression',
1551
+ function() {
1552
+ return new While($2,
1553
+ {
1554
+ guard: $4
1555
+ });
1556
+ }),
1557
+ o('WHILE ExpressionLine WHEN Expression',
1558
+ function() {
1559
+ return new While($2,
1560
+ {
1561
+ guard: $4
1562
+ });
1563
+ }),
1564
+ o('UNTIL Expression',
1565
+ function() {
1566
+ return new While($2,
1567
+ {
1568
+ invert: true
1569
+ });
1570
+ }),
1571
+ o('UNTIL Expression WHEN Expression',
1572
+ function() {
1573
+ return new While($2,
1574
+ {
1575
+ invert: true,
1576
+ guard: $4
1577
+ });
1578
+ }),
1579
+ o('UNTIL ExpressionLine WHEN Expression',
1580
+ function() {
1581
+ return new While($2,
1582
+ {
1583
+ invert: true,
1584
+ guard: $4
1585
+ });
1586
+ })
1587
+ ],
1588
+ // The while loop can either be normal, with a block of expressions to execute,
1589
+ // or postfix, with a single expression. There is no do..while.
1590
+ While: [
1591
+ o('WhileSource Block',
1592
+ function() {
1593
+ return $1.addBody($2);
1594
+ }),
1595
+ o('WhileLineSource Block',
1596
+ function() {
1597
+ return $1.addBody($2);
1598
+ }),
1599
+ o('Statement WhileSource',
1600
+ function() {
1601
+ return (Object.assign($2,
1602
+ {
1603
+ postfix: true
1604
+ })).addBody(LOC(1)(Block.wrap([$1])));
1605
+ }),
1606
+ o('Expression WhileSource',
1607
+ function() {
1608
+ return (Object.assign($2,
1609
+ {
1610
+ postfix: true
1611
+ })).addBody(LOC(1)(Block.wrap([$1])));
1612
+ }),
1613
+ o('Loop',
1614
+ function() {
1615
+ return $1;
1616
+ })
1617
+ ],
1618
+ Loop: [
1619
+ o('LOOP Block',
1620
+ function() {
1621
+ return new While(LOC(1)(new BooleanLiteral('true')),
1622
+ {
1623
+ isLoop: true
1624
+ }).addBody($2);
1625
+ }),
1626
+ o('LOOP Expression',
1627
+ function() {
1628
+ return new While(LOC(1)(new BooleanLiteral('true')),
1629
+ {
1630
+ isLoop: true
1631
+ }).addBody(LOC(2)(Block.wrap([$2])));
1632
+ })
1633
+ ],
1634
+ // Array, object, and range comprehensions, at the most generic level.
1635
+ // Comprehensions can either be normal, with a block of expressions to execute,
1636
+ // or postfix, with a single expression.
1637
+ For: [
1638
+ o('Statement ForBody',
1639
+ function() {
1640
+ $2.postfix = true;
1641
+ return $2.addBody($1);
1642
+ }),
1643
+ o('Expression ForBody',
1644
+ function() {
1645
+ $2.postfix = true;
1646
+ return $2.addBody($1);
1647
+ }),
1648
+ o('ForBody Block',
1649
+ function() {
1650
+ return $1.addBody($2);
1651
+ }),
1652
+ o('ForLineBody Block',
1653
+ function() {
1654
+ return $1.addBody($2);
1655
+ })
1656
+ ],
1657
+ ForBody: [
1658
+ o('FOR Range',
1659
+ function() {
1660
+ return new For([],
1661
+ {
1662
+ source: LOC(2)(new Value($2))
1663
+ });
1664
+ }),
1665
+ o('FOR Range BY Expression',
1666
+ function() {
1667
+ return new For([],
1668
+ {
1669
+ source: LOC(2)(new Value($2)),
1670
+ step: $4
1671
+ });
1672
+ }),
1673
+ o('ForStart ForSource',
1674
+ function() {
1675
+ return $1.addSource($2);
1676
+ })
1677
+ ],
1678
+ ForLineBody: [
1679
+ o('FOR Range BY ExpressionLine',
1680
+ function() {
1681
+ return new For([],
1682
+ {
1683
+ source: LOC(2)(new Value($2)),
1684
+ step: $4
1685
+ });
1686
+ }),
1687
+ o('ForStart ForLineSource',
1688
+ function() {
1689
+ return $1.addSource($2);
1690
+ })
1691
+ ],
1692
+ ForStart: [
1693
+ o('FOR ForVariables',
1694
+ function() {
1695
+ return new For([],
1696
+ {
1697
+ name: $2[0],
1698
+ index: $2[1]
1699
+ });
1700
+ }),
1701
+ o('FOR AWAIT ForVariables',
1702
+ function() {
1703
+ var index,
1704
+ name;
1705
+ [name,
1706
+ index] = $3;
1707
+ return new For([],
1708
+ {
1709
+ name,
1710
+ index,
1711
+ await: true,
1712
+ awaitTag: LOC(2)(new Literal($2))
1713
+ });
1714
+ }),
1715
+ o('FOR OWN ForVariables',
1716
+ function() {
1717
+ var index,
1718
+ name;
1719
+ [name,
1720
+ index] = $3;
1721
+ return new For([],
1722
+ {
1723
+ name,
1724
+ index,
1725
+ own: true,
1726
+ ownTag: LOC(2)(new Literal($2))
1727
+ });
1728
+ })
1729
+ ],
1730
+ // An array of all accepted values for a variable inside the loop.
1731
+ // This enables support for pattern matching.
1732
+ ForValue: [
1733
+ o('Identifier'),
1734
+ o('ThisProperty'),
1735
+ o('Array',
1736
+ function() {
1737
+ return new Value($1);
1738
+ }),
1739
+ o('Object',
1740
+ function() {
1741
+ return new Value($1);
1742
+ })
1743
+ ],
1744
+ // An array or range comprehension has variables for the current element
1745
+ // and (optional) reference to the current index. Or, *key, value*, in the case
1746
+ // of object comprehensions.
1747
+ ForVariables: [
1748
+ o('ForValue',
1749
+ function() {
1750
+ return [$1];
1751
+ }),
1752
+ o('ForValue , ForValue',
1753
+ function() {
1754
+ return [$1,
1755
+ $3];
1756
+ })
1757
+ ],
1758
+ // The source of a comprehension is an array or object with an optional guard
1759
+ // clause. If it’s an array comprehension, you can also choose to step through
1760
+ // in fixed-size increments.
1761
+ ForSource: [
1762
+ o('FORIN Expression',
1763
+ function() {
1764
+ return {
1765
+ source: $2
1766
+ };
1767
+ }),
1768
+ o('FOROF Expression',
1769
+ function() {
1770
+ return {
1771
+ source: $2,
1772
+ object: true
1773
+ };
1774
+ }),
1775
+ o('FORIN Expression WHEN Expression',
1776
+ function() {
1777
+ return {
1778
+ source: $2,
1779
+ guard: $4
1780
+ };
1781
+ }),
1782
+ o('FORIN ExpressionLine WHEN Expression',
1783
+ function() {
1784
+ return {
1785
+ source: $2,
1786
+ guard: $4
1787
+ };
1788
+ }),
1789
+ o('FOROF Expression WHEN Expression',
1790
+ function() {
1791
+ return {
1792
+ source: $2,
1793
+ guard: $4,
1794
+ object: true
1795
+ };
1796
+ }),
1797
+ o('FOROF ExpressionLine WHEN Expression',
1798
+ function() {
1799
+ return {
1800
+ source: $2,
1801
+ guard: $4,
1802
+ object: true
1803
+ };
1804
+ }),
1805
+ o('FORIN Expression BY Expression',
1806
+ function() {
1807
+ return {
1808
+ source: $2,
1809
+ step: $4
1810
+ };
1811
+ }),
1812
+ o('FORIN ExpressionLine BY Expression',
1813
+ function() {
1814
+ return {
1815
+ source: $2,
1816
+ step: $4
1817
+ };
1818
+ }),
1819
+ o('FORIN Expression WHEN Expression BY Expression',
1820
+ function() {
1821
+ return {
1822
+ source: $2,
1823
+ guard: $4,
1824
+ step: $6
1825
+ };
1826
+ }),
1827
+ o('FORIN ExpressionLine WHEN Expression BY Expression',
1828
+ function() {
1829
+ return {
1830
+ source: $2,
1831
+ guard: $4,
1832
+ step: $6
1833
+ };
1834
+ }),
1835
+ o('FORIN Expression WHEN ExpressionLine BY Expression',
1836
+ function() {
1837
+ return {
1838
+ source: $2,
1839
+ guard: $4,
1840
+ step: $6
1841
+ };
1842
+ }),
1843
+ o('FORIN ExpressionLine WHEN ExpressionLine BY Expression',
1844
+ function() {
1845
+ return {
1846
+ source: $2,
1847
+ guard: $4,
1848
+ step: $6
1849
+ };
1850
+ }),
1851
+ o('FORIN Expression BY Expression WHEN Expression',
1852
+ function() {
1853
+ return {
1854
+ source: $2,
1855
+ step: $4,
1856
+ guard: $6
1857
+ };
1858
+ }),
1859
+ o('FORIN ExpressionLine BY Expression WHEN Expression',
1860
+ function() {
1861
+ return {
1862
+ source: $2,
1863
+ step: $4,
1864
+ guard: $6
1865
+ };
1866
+ }),
1867
+ o('FORIN Expression BY ExpressionLine WHEN Expression',
1868
+ function() {
1869
+ return {
1870
+ source: $2,
1871
+ step: $4,
1872
+ guard: $6
1873
+ };
1874
+ }),
1875
+ o('FORIN ExpressionLine BY ExpressionLine WHEN Expression',
1876
+ function() {
1877
+ return {
1878
+ source: $2,
1879
+ step: $4,
1880
+ guard: $6
1881
+ };
1882
+ }),
1883
+ o('FORFROM Expression',
1884
+ function() {
1885
+ return {
1886
+ source: $2,
1887
+ from: true
1888
+ };
1889
+ }),
1890
+ o('FORFROM Expression WHEN Expression',
1891
+ function() {
1892
+ return {
1893
+ source: $2,
1894
+ guard: $4,
1895
+ from: true
1896
+ };
1897
+ }),
1898
+ o('FORFROM ExpressionLine WHEN Expression',
1899
+ function() {
1900
+ return {
1901
+ source: $2,
1902
+ guard: $4,
1903
+ from: true
1904
+ };
1905
+ })
1906
+ ],
1907
+ ForLineSource: [
1908
+ o('FORIN ExpressionLine',
1909
+ function() {
1910
+ return {
1911
+ source: $2
1912
+ };
1913
+ }),
1914
+ o('FOROF ExpressionLine',
1915
+ function() {
1916
+ return {
1917
+ source: $2,
1918
+ object: true
1919
+ };
1920
+ }),
1921
+ o('FORIN Expression WHEN ExpressionLine',
1922
+ function() {
1923
+ return {
1924
+ source: $2,
1925
+ guard: $4
1926
+ };
1927
+ }),
1928
+ o('FORIN ExpressionLine WHEN ExpressionLine',
1929
+ function() {
1930
+ return {
1931
+ source: $2,
1932
+ guard: $4
1933
+ };
1934
+ }),
1935
+ o('FOROF Expression WHEN ExpressionLine',
1936
+ function() {
1937
+ return {
1938
+ source: $2,
1939
+ guard: $4,
1940
+ object: true
1941
+ };
1942
+ }),
1943
+ o('FOROF ExpressionLine WHEN ExpressionLine',
1944
+ function() {
1945
+ return {
1946
+ source: $2,
1947
+ guard: $4,
1948
+ object: true
1949
+ };
1950
+ }),
1951
+ o('FORIN Expression BY ExpressionLine',
1952
+ function() {
1953
+ return {
1954
+ source: $2,
1955
+ step: $4
1956
+ };
1957
+ }),
1958
+ o('FORIN ExpressionLine BY ExpressionLine',
1959
+ function() {
1960
+ return {
1961
+ source: $2,
1962
+ step: $4
1963
+ };
1964
+ }),
1965
+ o('FORIN Expression WHEN Expression BY ExpressionLine',
1966
+ function() {
1967
+ return {
1968
+ source: $2,
1969
+ guard: $4,
1970
+ step: $6
1971
+ };
1972
+ }),
1973
+ o('FORIN ExpressionLine WHEN Expression BY ExpressionLine',
1974
+ function() {
1975
+ return {
1976
+ source: $2,
1977
+ guard: $4,
1978
+ step: $6
1979
+ };
1980
+ }),
1981
+ o('FORIN Expression WHEN ExpressionLine BY ExpressionLine',
1982
+ function() {
1983
+ return {
1984
+ source: $2,
1985
+ guard: $4,
1986
+ step: $6
1987
+ };
1988
+ }),
1989
+ o('FORIN ExpressionLine WHEN ExpressionLine BY ExpressionLine',
1990
+ function() {
1991
+ return {
1992
+ source: $2,
1993
+ guard: $4,
1994
+ step: $6
1995
+ };
1996
+ }),
1997
+ o('FORIN Expression BY Expression WHEN ExpressionLine',
1998
+ function() {
1999
+ return {
2000
+ source: $2,
2001
+ step: $4,
2002
+ guard: $6
2003
+ };
2004
+ }),
2005
+ o('FORIN ExpressionLine BY Expression WHEN ExpressionLine',
2006
+ function() {
2007
+ return {
2008
+ source: $2,
2009
+ step: $4,
2010
+ guard: $6
2011
+ };
2012
+ }),
2013
+ o('FORIN Expression BY ExpressionLine WHEN ExpressionLine',
2014
+ function() {
2015
+ return {
2016
+ source: $2,
2017
+ step: $4,
2018
+ guard: $6
2019
+ };
2020
+ }),
2021
+ o('FORIN ExpressionLine BY ExpressionLine WHEN ExpressionLine',
2022
+ function() {
2023
+ return {
2024
+ source: $2,
2025
+ step: $4,
2026
+ guard: $6
2027
+ };
2028
+ }),
2029
+ o('FORFROM ExpressionLine',
2030
+ function() {
2031
+ return {
2032
+ source: $2,
2033
+ from: true
2034
+ };
2035
+ }),
2036
+ o('FORFROM Expression WHEN ExpressionLine',
2037
+ function() {
2038
+ return {
2039
+ source: $2,
2040
+ guard: $4,
2041
+ from: true
2042
+ };
2043
+ }),
2044
+ o('FORFROM ExpressionLine WHEN ExpressionLine',
2045
+ function() {
2046
+ return {
2047
+ source: $2,
2048
+ guard: $4,
2049
+ from: true
2050
+ };
2051
+ })
2052
+ ],
2053
+ Switch: [
2054
+ o('SWITCH Expression INDENT Whens OUTDENT',
2055
+ function() {
2056
+ return new Switch($2,
2057
+ $4);
2058
+ }),
2059
+ o('SWITCH ExpressionLine INDENT Whens OUTDENT',
2060
+ function() {
2061
+ return new Switch($2,
2062
+ $4);
2063
+ }),
2064
+ o('SWITCH Expression INDENT Whens ELSE Block OUTDENT',
2065
+ function() {
2066
+ return new Switch($2,
2067
+ $4,
2068
+ LOC(5,
2069
+ 6)($6));
2070
+ }),
2071
+ o('SWITCH ExpressionLine INDENT Whens ELSE Block OUTDENT',
2072
+ function() {
2073
+ return new Switch($2,
2074
+ $4,
2075
+ LOC(5,
2076
+ 6)($6));
2077
+ }),
2078
+ o('SWITCH INDENT Whens OUTDENT',
2079
+ function() {
2080
+ return new Switch(null,
2081
+ $3);
2082
+ }),
2083
+ o('SWITCH INDENT Whens ELSE Block OUTDENT',
2084
+ function() {
2085
+ return new Switch(null,
2086
+ $3,
2087
+ LOC(4,
2088
+ 5)($5));
2089
+ })
2090
+ ],
2091
+ Whens: [
2092
+ o('When',
2093
+ function() {
2094
+ return [$1];
2095
+ }),
2096
+ o('Whens When',
2097
+ function() {
2098
+ return $1.concat($2);
2099
+ })
2100
+ ],
2101
+ // An individual **When** clause, with action.
2102
+ When: [
2103
+ o('LEADING_WHEN SimpleArgs Block',
2104
+ function() {
2105
+ return new SwitchWhen($2,
2106
+ $3);
2107
+ }),
2108
+ o('LEADING_WHEN SimpleArgs Block TERMINATOR',
2109
+ function() {
2110
+ return LOC(1,
2111
+ 3)(new SwitchWhen($2,
2112
+ $3));
2113
+ })
2114
+ ],
2115
+ // The most basic form of *if* is a condition and an action. The following
2116
+ // if-related rules are broken up along these lines in order to avoid
2117
+ // ambiguity.
2118
+ IfBlock: [
2119
+ o('IF Expression Block',
2120
+ function() {
2121
+ return new If($2,
2122
+ $3,
2123
+ {
2124
+ type: $1
2125
+ });
2126
+ }),
2127
+ o('IfBlock ELSE IF Expression Block',
2128
+ function() {
2129
+ return $1.addElse(LOC(3,
2130
+ 5)(new If($4,
2131
+ $5,
2132
+ {
2133
+ type: $3
2134
+ })));
2135
+ })
2136
+ ],
2137
+ // The full complement of *if* expressions, including postfix one-liner
2138
+ // *if* and *unless*.
2139
+ If: [
2140
+ o('IfBlock'),
2141
+ o('IfBlock ELSE Block',
2142
+ function() {
2143
+ return $1.addElse($3);
2144
+ }),
2145
+ o('Statement POST_IF Expression',
2146
+ function() {
2147
+ return new If($3,
2148
+ LOC(1)(Block.wrap([$1])),
2149
+ {
2150
+ type: $2,
2151
+ postfix: true
2152
+ });
2153
+ }),
2154
+ o('Expression POST_IF Expression',
2155
+ function() {
2156
+ return new If($3,
2157
+ LOC(1)(Block.wrap([$1])),
2158
+ {
2159
+ type: $2,
2160
+ postfix: true
2161
+ });
2162
+ })
2163
+ ],
2164
+ IfBlockLine: [
2165
+ o('IF ExpressionLine Block',
2166
+ function() {
2167
+ return new If($2,
2168
+ $3,
2169
+ {
2170
+ type: $1
2171
+ });
2172
+ }),
2173
+ o('IfBlockLine ELSE IF ExpressionLine Block',
2174
+ function() {
2175
+ return $1.addElse(LOC(3,
2176
+ 5)(new If($4,
2177
+ $5,
2178
+ {
2179
+ type: $3
2180
+ })));
2181
+ })
2182
+ ],
2183
+ IfLine: [
2184
+ o('IfBlockLine'),
2185
+ o('IfBlockLine ELSE Block',
2186
+ function() {
2187
+ return $1.addElse($3);
2188
+ }),
2189
+ o('Statement POST_IF ExpressionLine',
2190
+ function() {
2191
+ return new If($3,
2192
+ LOC(1)(Block.wrap([$1])),
2193
+ {
2194
+ type: $2,
2195
+ postfix: true
2196
+ });
2197
+ }),
2198
+ o('Expression POST_IF ExpressionLine',
2199
+ function() {
2200
+ return new If($3,
2201
+ LOC(1)(Block.wrap([$1])),
2202
+ {
2203
+ type: $2,
2204
+ postfix: true
2205
+ });
2206
+ })
2207
+ ],
2208
+ // Arithmetic and logical operators, working on one or more operands.
2209
+ // Here they are grouped by order of precedence. The actual precedence rules
2210
+ // are defined at the bottom of the page. It would be shorter if we could
2211
+ // combine most of these rules into a single generic *Operand OpSymbol Operand*
2212
+ // -type rule, but in order to make the precedence binding possible, separate
2213
+ // rules are necessary.
2214
+ OperationLine: [
2215
+ o('UNARY ExpressionLine',
2216
+ function() {
2217
+ return new Op($1,
2218
+ $2);
2219
+ }),
2220
+ o('DO ExpressionLine',
2221
+ function() {
2222
+ return new Op($1,
2223
+ $2);
2224
+ }),
2225
+ o('DO_IIFE CodeLine',
2226
+ function() {
2227
+ return new Op($1,
2228
+ $2);
2229
+ })
2230
+ ],
2231
+ Operation: [
2232
+ o('UNARY Expression',
2233
+ function() {
2234
+ return new Op($1.toString(),
2235
+ $2,
2236
+ void 0,
2237
+ void 0,
2238
+ {
2239
+ originalOperator: $1.original
2240
+ });
2241
+ }),
2242
+ o('DO Expression',
2243
+ function() {
2244
+ return new Op($1,
2245
+ $2);
2246
+ }),
2247
+ o('UNARY_MATH Expression',
2248
+ function() {
2249
+ return new Op($1,
2250
+ $2);
2251
+ }),
2252
+ o('- Expression',
2253
+ (function() {
2254
+ return new Op('-',
2255
+ $2);
2256
+ }),
2257
+ {
2258
+ prec: 'UNARY_MATH'
2259
+ }),
2260
+ o('+ Expression',
2261
+ (function() {
2262
+ return new Op('+',
2263
+ $2);
2264
+ }),
2265
+ {
2266
+ prec: 'UNARY_MATH'
2267
+ }),
2268
+ o('AWAIT Expression',
2269
+ function() {
2270
+ return new Op($1,
2271
+ $2);
2272
+ }),
2273
+ o('AWAIT INDENT Object OUTDENT',
2274
+ function() {
2275
+ return new Op($1,
2276
+ $3);
2277
+ }),
2278
+ o('-- SimpleAssignable',
2279
+ function() {
2280
+ return new Op('--',
2281
+ $2);
2282
+ }),
2283
+ o('++ SimpleAssignable',
2284
+ function() {
2285
+ return new Op('++',
2286
+ $2);
2287
+ }),
2288
+ o('SimpleAssignable --',
2289
+ function() {
2290
+ return new Op('--',
2291
+ $1,
2292
+ null,
2293
+ true);
2294
+ }),
2295
+ o('SimpleAssignable ++',
2296
+ function() {
2297
+ return new Op('++',
2298
+ $1,
2299
+ null,
2300
+ true);
2301
+ }),
2302
+ // [The existential operator](https://coffeescript.org/#existential-operator).
2303
+ o('Expression ?',
2304
+ function() {
2305
+ return new Existence($1);
2306
+ }),
2307
+ o('Expression + Expression',
2308
+ function() {
2309
+ return new Op('+',
2310
+ $1,
2311
+ $3);
2312
+ }),
2313
+ o('Expression - Expression',
2314
+ function() {
2315
+ return new Op('-',
2316
+ $1,
2317
+ $3);
2318
+ }),
2319
+ o('Expression MATH Expression',
2320
+ function() {
2321
+ return new Op($2,
2322
+ $1,
2323
+ $3);
2324
+ }),
2325
+ o('Expression ** Expression',
2326
+ function() {
2327
+ return new Op($2,
2328
+ $1,
2329
+ $3);
2330
+ }),
2331
+ o('Expression SHIFT Expression',
2332
+ function() {
2333
+ return new Op($2,
2334
+ $1,
2335
+ $3);
2336
+ }),
2337
+ o('Expression COMPARE Expression',
2338
+ function() {
2339
+ return new Op($2.toString(),
2340
+ $1,
2341
+ $3,
2342
+ void 0,
2343
+ {
2344
+ originalOperator: $2.original
2345
+ });
2346
+ }),
2347
+ o('Expression & Expression',
2348
+ function() {
2349
+ return new Op($2,
2350
+ $1,
2351
+ $3);
2352
+ }),
2353
+ o('Expression ^ Expression',
2354
+ function() {
2355
+ return new Op($2,
2356
+ $1,
2357
+ $3);
2358
+ }),
2359
+ o('Expression | Expression',
2360
+ function() {
2361
+ return new Op($2,
2362
+ $1,
2363
+ $3);
2364
+ }),
2365
+ o('Expression && Expression',
2366
+ function() {
2367
+ return new Op($2.toString(),
2368
+ $1,
2369
+ $3,
2370
+ void 0,
2371
+ {
2372
+ originalOperator: $2.original
2373
+ });
2374
+ }),
2375
+ o('Expression || Expression',
2376
+ function() {
2377
+ return new Op($2.toString(),
2378
+ $1,
2379
+ $3,
2380
+ void 0,
2381
+ {
2382
+ originalOperator: $2.original
2383
+ });
2384
+ }),
2385
+ o('Expression BIN? Expression',
2386
+ function() {
2387
+ return new Op($2,
2388
+ $1,
2389
+ $3);
2390
+ }),
2391
+ o('Expression RELATION Expression',
2392
+ function() {
2393
+ var ref,
2394
+ ref1;
2395
+ return new Op($2.toString(),
2396
+ $1,
2397
+ $3,
2398
+ void 0,
2399
+ {
2400
+ invertOperator: (ref = (ref1 = $2.invert) != null ? ref1.original : void 0) != null ? ref : $2.invert
2401
+ });
2402
+ }),
2403
+ o('SimpleAssignable COMPOUND_ASSIGN Expression',
2404
+ function() {
2405
+ return new Assign($1,
2406
+ $3,
2407
+ $2.toString(),
2408
+ {
2409
+ originalContext: $2.original
2410
+ });
2411
+ }),
2412
+ o('SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT',
2413
+ function() {
2414
+ return new Assign($1,
2415
+ $4,
2416
+ $2.toString(),
2417
+ {
2418
+ originalContext: $2.original
2419
+ });
2420
+ }),
2421
+ o('SimpleAssignable COMPOUND_ASSIGN TERMINATOR Expression',
2422
+ function() {
2423
+ return new Assign($1,
2424
+ $4,
2425
+ $2.toString(),
2426
+ {
2427
+ originalContext: $2.original
2428
+ });
2429
+ })
2430
+ ],
2431
+ DoIife: [
2432
+ o('DO_IIFE Code',
2433
+ function() {
2434
+ return new Op($1,
2435
+ $2);
2436
+ })
2437
+ ]
2438
+ };
2439
+
2440
+ // Precedence
2441
+ // ----------
2442
+
2443
+ // Operators at the top of this list have higher precedence than the ones lower
2444
+ // down. Following these rules is what makes `2 + 3 * 4` parse as:
2445
+
2446
+ // 2 + (3 * 4)
2447
+
2448
+ // And not:
2449
+
2450
+ // (2 + 3) * 4
2451
+ operators = [['right', 'DO_IIFE'], ['left', '.', '?.', '::', '?::'], ['left', 'CALL_START', 'CALL_END'], ['nonassoc', '++', '--'], ['left', '?'], ['right', 'UNARY', 'DO'], ['right', 'AWAIT'], ['right', '**'], ['right', 'UNARY_MATH'], ['left', 'MATH'], ['left', '+', '-'], ['left', 'SHIFT'], ['left', 'RELATION'], ['left', 'COMPARE'], ['left', '&'], ['left', '^'], ['left', '|'], ['left', '&&'], ['left', '||'], ['left', 'BIN?'], ['nonassoc', 'INDENT', 'OUTDENT'], ['right', 'YIELD'], ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS'], ['right', 'FORIN', 'FOROF', 'FORFROM', 'BY', 'WHEN'], ['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'IMPORT', 'EXPORT', 'DYNAMIC_IMPORT'], ['left', 'POST_IF']];
2452
+
2453
+ // Wrapping Up
2454
+ // -----------
2455
+
2456
+ // Finally, now that we have our **grammar** and our **operators**, we can create
2457
+ // our **Jison.Parser**. We do this by processing all of our rules, recording all
2458
+ // terminals (every symbol which does not appear as the name of a rule above)
2459
+ // as "tokens".
2460
+ tokens = [];
2461
+
2462
+ for (name in grammar) {
2463
+ alternatives = grammar[name];
2464
+ grammar[name] = (function() {
2465
+ var i, j, len, len1, ref, results;
2466
+ results = [];
2467
+ for (i = 0, len = alternatives.length; i < len; i++) {
2468
+ alt = alternatives[i];
2469
+ ref = alt[0].split(' ');
2470
+ for (j = 0, len1 = ref.length; j < len1; j++) {
2471
+ token = ref[j];
2472
+ if (!grammar[token]) {
2473
+ tokens.push(token);
2474
+ }
2475
+ }
2476
+ if (name === 'Root') {
2477
+ alt[1] = `return ${alt[1]}`;
2478
+ }
2479
+ results.push(alt);
2480
+ }
2481
+ return results;
2482
+ })();
2483
+ }
2484
+
2485
+ // Initialize the **Parser** with our list of terminal **tokens**, our **grammar**
2486
+ // rules, and the name of the root. Reverse the operators because Jison orders
2487
+ // precedence from low to high, and we have it high to low
2488
+ // (as in [Yacc](http://dinosaur.compilertools.net/yacc/index.html)).
2489
+ exports.parser = new Parser({
2490
+ tokens: tokens.join(' '),
2491
+ bnf: grammar,
2492
+ operators: operators.reverse(),
2493
+ startSymbol: 'Root'
2494
+ });
2495
+
2496
+ }).call(this);