@makano/rew 1.2.56 → 1.2.58

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1930 +0,0 @@
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('', function () {
109
- return new Root(new Block());
110
- }),
111
- o('Body', function () {
112
- return new Root($1);
113
- }),
114
- ],
115
- // Any list of statements and expressions, separated by line breaks or semicolons.
116
- Body: [
117
- o('Line', function () {
118
- return Block.wrap([$1]);
119
- }),
120
- o('Body TERMINATOR Line', function () {
121
- return $1.push($3);
122
- }),
123
- o('Body TERMINATOR'),
124
- ],
125
- // Block and statements, which make up a line in a body. FuncDirective is a
126
- // statement, but not included in Statement because that results in an ambiguous
127
- // grammar.
128
- Line: [o('Expression'), o('ExpressionLine'), o('Statement'), o('FuncDirective')],
129
- FuncDirective: [o('YieldReturn'), o('AwaitReturn')],
130
- // Pure statements which cannot be expressions.
131
- Statement: [
132
- o('Return'),
133
- o('STATEMENT', function () {
134
- return new StatementLiteral($1);
135
- }),
136
- o('Import'),
137
- o('Export'),
138
- ],
139
- // All the different types of expressions in our language. The basic unit of
140
- // CoffeeScript is the **Expression** -- everything that can be an expression
141
- // is one. Blocks serve as the building blocks of many other rules, making
142
- // them somewhat circular.
143
- Expression: [
144
- o('Value'),
145
- o('Code'),
146
- o('Operation'),
147
- o('Assign'),
148
- o('If'),
149
- o('Try'),
150
- o('While'),
151
- o('For'),
152
- o('Switch'),
153
- o('Class'),
154
- o('Throw'),
155
- o('Yield'),
156
- ],
157
- // Expressions which are written in single line and would otherwise require being
158
- // wrapped in braces: E.g `a = b if do -> f a is 1`, `if f (a) -> a*2 then ...`,
159
- // `for x in do (obj) -> f obj when x > 8 then f x`
160
- ExpressionLine: [o('CodeLine'), o('IfLine'), o('OperationLine')],
161
- Yield: [
162
- o('YIELD', function () {
163
- return new Op($1, new Value(new Literal('')));
164
- }),
165
- o('YIELD Expression', function () {
166
- return new Op($1, $2);
167
- }),
168
- o('YIELD INDENT Object OUTDENT', function () {
169
- return new Op($1, $3);
170
- }),
171
- o('YIELD FROM Expression', function () {
172
- return new Op($1.concat($2), $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', function () {
180
- return new Block();
181
- }),
182
- o('INDENT Body OUTDENT', function () {
183
- return $2;
184
- }),
185
- ],
186
- Identifier: [
187
- o('IDENTIFIER', function () {
188
- return new IdentifierLiteral($1);
189
- }),
190
- o('JSX_TAG', function () {
191
- var ref, ref1, ref2, ref3;
192
- return new JSXTag($1.toString(), {
193
- tagNameLocationData: $1.tagNameToken[2],
194
- closingTagOpeningBracketLocationData: (ref = $1.closingTagOpeningBracketToken) != null ? ref[2] : void 0,
195
- closingTagSlashLocationData: (ref1 = $1.closingTagSlashToken) != null ? ref1[2] : void 0,
196
- closingTagNameLocationData: (ref2 = $1.closingTagNameToken) != null ? ref2[2] : void 0,
197
- closingTagClosingBracketLocationData: (ref3 = $1.closingTagClosingBracketToken) != null ? ref3[2] : void 0,
198
- });
199
- }),
200
- ],
201
- Property: [
202
- o('PROPERTY', function () {
203
- return new PropertyName($1.toString());
204
- }),
205
- ],
206
- // Alphanumerics are separated from the other **Literal** matchers because
207
- // they can also serve as keys in object literals.
208
- AlphaNumeric: [
209
- o('NUMBER', function () {
210
- return new NumberLiteral($1.toString(), {
211
- parsedValue: $1.parsedValue,
212
- });
213
- }),
214
- o('String'),
215
- ],
216
- String: [
217
- o('STRING', function () {
218
- return new StringLiteral(
219
- $1.slice(1, -1), // strip artificial quotes and unwrap to primitive string
220
- {
221
- quote: $1.quote,
222
- initialChunk: $1.initialChunk,
223
- finalChunk: $1.finalChunk,
224
- indent: $1.indent,
225
- double: $1.double,
226
- heregex: $1.heregex,
227
- },
228
- );
229
- }),
230
- o('STRING_START Interpolations STRING_END', function () {
231
- return new StringWithInterpolations(Block.wrap($2), {
232
- quote: $1.quote,
233
- startQuote: LOC(1)(new Literal($1.toString())),
234
- });
235
- }),
236
- ],
237
- Interpolations: [
238
- o('InterpolationChunk', function () {
239
- return [$1];
240
- }),
241
- o('Interpolations InterpolationChunk', function () {
242
- return $1.concat($2);
243
- }),
244
- ],
245
- InterpolationChunk: [
246
- o('INTERPOLATION_START Body INTERPOLATION_END', function () {
247
- return new Interpolation($2);
248
- }),
249
- o('INTERPOLATION_START INDENT Body OUTDENT INTERPOLATION_END', function () {
250
- return new Interpolation($3);
251
- }),
252
- o('INTERPOLATION_START INTERPOLATION_END', function () {
253
- return new Interpolation();
254
- }),
255
- o('String', function () {
256
- return $1;
257
- }),
258
- ],
259
- // The .toString() calls here and elsewhere are to convert `String` objects
260
- // back to primitive strings now that we've retrieved stowaway extra properties
261
- Regex: [
262
- o('REGEX', function () {
263
- return new RegexLiteral($1.toString(), {
264
- delimiter: $1.delimiter,
265
- heregexCommentTokens: $1.heregexCommentTokens,
266
- });
267
- }),
268
- o('REGEX_START Invocation REGEX_END', function () {
269
- return new RegexWithInterpolations($2, {
270
- heregexCommentTokens: $3.heregexCommentTokens,
271
- });
272
- }),
273
- ],
274
- // All of our immediate values. Generally these can be passed straight
275
- // through and printed to JavaScript.
276
- Literal: [
277
- o('AlphaNumeric'),
278
- o('JS', function () {
279
- return new PassthroughLiteral($1.toString(), {
280
- here: $1.here,
281
- generated: $1.generated,
282
- });
283
- }),
284
- o('Regex'),
285
- o('UNDEFINED', function () {
286
- return new UndefinedLiteral($1);
287
- }),
288
- o('NULL', function () {
289
- return new NullLiteral($1);
290
- }),
291
- o('BOOL', function () {
292
- return new BooleanLiteral($1.toString(), {
293
- originalValue: $1.original,
294
- });
295
- }),
296
- o('INFINITY', function () {
297
- return new InfinityLiteral($1.toString(), {
298
- originalValue: $1.original,
299
- });
300
- }),
301
- o('NAN', function () {
302
- return new NaNLiteral($1);
303
- }),
304
- ],
305
- // Assignment of a variable, property, or index to a value.
306
- Assign: [
307
- o('Assignable = Expression', function () {
308
- return new Assign($1, $3);
309
- }),
310
- o('Assignable = TERMINATOR Expression', function () {
311
- return new Assign($1, $4);
312
- }),
313
- o('Assignable = INDENT Expression OUTDENT', function () {
314
- return new Assign($1, $4);
315
- }),
316
- ],
317
- // Assignment when it happens within an object literal. The difference from
318
- // the ordinary **Assign** is that these allow numbers and strings as keys.
319
- AssignObj: [
320
- o('ObjAssignable', function () {
321
- return new Value($1);
322
- }),
323
- o('ObjRestValue'),
324
- o('ObjAssignable : Expression', function () {
325
- return new Assign(LOC(1)(new Value($1)), $3, 'object', {
326
- operatorToken: LOC(2)(new Literal($2)),
327
- });
328
- }),
329
- o('ObjAssignable : INDENT Expression OUTDENT', function () {
330
- return new Assign(LOC(1)(new Value($1)), $4, 'object', {
331
- operatorToken: LOC(2)(new Literal($2)),
332
- });
333
- }),
334
- o('SimpleObjAssignable = Expression', function () {
335
- return new Assign(LOC(1)(new Value($1)), $3, null, {
336
- operatorToken: LOC(2)(new Literal($2)),
337
- });
338
- }),
339
- o('SimpleObjAssignable = INDENT Expression OUTDENT', function () {
340
- return new Assign(LOC(1)(new Value($1)), $4, null, {
341
- operatorToken: LOC(2)(new Literal($2)),
342
- });
343
- }),
344
- ],
345
- SimpleObjAssignable: [o('Identifier'), o('Property'), o('ThisProperty')],
346
- ObjAssignable: [
347
- o('SimpleObjAssignable'),
348
- o('[ Expression ]', function () {
349
- return new Value(new ComputedPropertyName($2));
350
- }),
351
- o('@ [ Expression ]', function () {
352
- return new Value(LOC(1)(new ThisLiteral($1)), [LOC(3)(new ComputedPropertyName($3))], 'this');
353
- }),
354
- o('AlphaNumeric'),
355
- ],
356
- // Object literal spread properties.
357
- ObjRestValue: [
358
- o('SimpleObjAssignable ...', function () {
359
- return new Splat(new Value($1));
360
- }),
361
- o('... SimpleObjAssignable', function () {
362
- return new Splat(new Value($2), {
363
- postfix: false,
364
- });
365
- }),
366
- o('ObjSpreadExpr ...', function () {
367
- return new Splat($1);
368
- }),
369
- o('... ObjSpreadExpr', function () {
370
- return new Splat($2, {
371
- postfix: false,
372
- });
373
- }),
374
- ],
375
- ObjSpreadExpr: [
376
- o('ObjSpreadIdentifier'),
377
- o('Object'),
378
- o('Parenthetical'),
379
- o('Super'),
380
- o('This'),
381
- o('SUPER OptFuncExist Arguments', function () {
382
- return new SuperCall(LOC(1)(new Super()), $3, $2.soak, $1);
383
- }),
384
- o('DYNAMIC_IMPORT Arguments', function () {
385
- return new DynamicImportCall(LOC(1)(new DynamicImport()), $2);
386
- }),
387
- o('SimpleObjAssignable OptFuncExist Arguments', function () {
388
- return new Call(new Value($1), $3, $2.soak);
389
- }),
390
- o('ObjSpreadExpr OptFuncExist Arguments', function () {
391
- return new Call($1, $3, $2.soak);
392
- }),
393
- ],
394
- ObjSpreadIdentifier: [
395
- o('SimpleObjAssignable Accessor', function () {
396
- return new Value($1).add($2);
397
- }),
398
- o('ObjSpreadExpr Accessor', function () {
399
- return new Value($1).add($2);
400
- }),
401
- ],
402
- // A return statement from a function body.
403
- Return: [
404
- o('RETURN Expression', function () {
405
- return new Return($2);
406
- }),
407
- o('RETURN INDENT Object OUTDENT', function () {
408
- return new Return(new Value($3));
409
- }),
410
- o('RETURN', function () {
411
- return new Return();
412
- }),
413
- ],
414
- YieldReturn: [
415
- o('YIELD RETURN Expression', function () {
416
- return new YieldReturn($3, {
417
- returnKeyword: LOC(2)(new Literal($2)),
418
- });
419
- }),
420
- o('YIELD RETURN', function () {
421
- return new YieldReturn(null, {
422
- returnKeyword: LOC(2)(new Literal($2)),
423
- });
424
- }),
425
- ],
426
- AwaitReturn: [
427
- o('AWAIT RETURN Expression', function () {
428
- return new AwaitReturn($3, {
429
- returnKeyword: LOC(2)(new Literal($2)),
430
- });
431
- }),
432
- o('AWAIT RETURN', function () {
433
- return new AwaitReturn(null, {
434
- returnKeyword: LOC(2)(new Literal($2)),
435
- });
436
- }),
437
- ],
438
- // The **Code** node is the function literal. It’s defined by an indented block
439
- // of **Block** preceded by a function arrow, with an optional parameter list.
440
- Code: [
441
- o('PARAM_START ParamList PARAM_END FuncGlyph Block', function () {
442
- return new Code($2, $5, $4, LOC(1)(new Literal($1)));
443
- }),
444
- o('FuncGlyph Block', function () {
445
- return new Code([], $2, $1);
446
- }),
447
- ],
448
- // The Codeline is the **Code** node with **Line** instead of indented **Block**.
449
- CodeLine: [
450
- o('PARAM_START ParamList PARAM_END FuncGlyph Line', function () {
451
- return new Code($2, LOC(5)(Block.wrap([$5])), $4, LOC(1)(new Literal($1)));
452
- }),
453
- o('FuncGlyph Line', function () {
454
- return new Code([], LOC(2)(Block.wrap([$2])), $1);
455
- }),
456
- ],
457
- // CoffeeScript has two different symbols for functions. `->` is for ordinary
458
- // functions, and `=>` is for functions bound to the current value of *this*.
459
- FuncGlyph: [
460
- o('->', function () {
461
- return new FuncGlyph($1);
462
- }),
463
- o('=>', function () {
464
- return new FuncGlyph($1);
465
- }),
466
- ],
467
- // An optional, trailing comma.
468
- OptComma: [o(''), o(',')],
469
- // The list of parameters that a function accepts can be of any length.
470
- ParamList: [
471
- o('', function () {
472
- return [];
473
- }),
474
- o('Param', function () {
475
- return [$1];
476
- }),
477
- o('ParamList , Param', function () {
478
- return $1.concat($3);
479
- }),
480
- o('ParamList OptComma TERMINATOR Param', function () {
481
- return $1.concat($4);
482
- }),
483
- o('ParamList OptComma INDENT ParamList OptComma OUTDENT', function () {
484
- return $1.concat($4);
485
- }),
486
- ],
487
- // A single parameter in a function definition can be ordinary, or a splat
488
- // that hoovers up the remaining arguments.
489
- Param: [
490
- o('ParamVar', function () {
491
- return new Param($1);
492
- }),
493
- o('ParamVar ...', function () {
494
- return new Param($1, null, true);
495
- }),
496
- o('... ParamVar', function () {
497
- return new Param($2, null, {
498
- postfix: false,
499
- });
500
- }),
501
- o('ParamVar = Expression', function () {
502
- return new Param($1, $3);
503
- }),
504
- o('...', function () {
505
- return new Expansion();
506
- }),
507
- ],
508
- // Function Parameters
509
- ParamVar: [o('Identifier'), o('ThisProperty'), o('Array'), o('Object')],
510
- // A splat that occurs outside of a parameter list.
511
- Splat: [
512
- o('Expression ...', function () {
513
- return new Splat($1);
514
- }),
515
- o('... Expression', function () {
516
- return new Splat($2, {
517
- postfix: false,
518
- });
519
- }),
520
- ],
521
- // Variables and properties that can be assigned to.
522
- SimpleAssignable: [
523
- o('Identifier', function () {
524
- return new Value($1);
525
- }),
526
- o('Value Accessor', function () {
527
- return $1.add($2);
528
- }),
529
- o('Code Accessor', function () {
530
- return new Value($1).add($2);
531
- }),
532
- o('ThisProperty'),
533
- ],
534
- // Everything that can be assigned to.
535
- Assignable: [
536
- o('SimpleAssignable'),
537
- o('Array', function () {
538
- return new Value($1);
539
- }),
540
- o('Object', function () {
541
- return new Value($1);
542
- }),
543
- ],
544
- // The types of things that can be treated as values -- assigned to, invoked
545
- // as functions, indexed into, named as a class, etc.
546
- Value: [
547
- o('Assignable'),
548
- o('Literal', function () {
549
- return new Value($1);
550
- }),
551
- o('Parenthetical', function () {
552
- return new Value($1);
553
- }),
554
- o('Range', function () {
555
- return new Value($1);
556
- }),
557
- o('Invocation', function () {
558
- return new Value($1);
559
- }),
560
- o('DoIife', function () {
561
- return new Value($1);
562
- }),
563
- o('This'),
564
- o('Super', function () {
565
- return new Value($1);
566
- }),
567
- o('MetaProperty', function () {
568
- return new Value($1);
569
- }),
570
- ],
571
- // A `super`-based expression that can be used as a value.
572
- Super: [
573
- o('SUPER . Property', function () {
574
- return new Super(LOC(3)(new Access($3)), LOC(1)(new Literal($1)));
575
- }),
576
- o('SUPER INDEX_START Expression INDEX_END', function () {
577
- return new Super(LOC(3)(new Index($3)), LOC(1)(new Literal($1)));
578
- }),
579
- o('SUPER INDEX_START INDENT Expression OUTDENT INDEX_END', function () {
580
- return new Super(LOC(4)(new Index($4)), LOC(1)(new Literal($1)));
581
- }),
582
- ],
583
- // A “meta-property” access e.g. `new.target` or `import.meta`, where
584
- // something that looks like a property is referenced on a keyword.
585
- MetaProperty: [
586
- o('NEW_TARGET . Property', function () {
587
- return new MetaProperty(LOC(1)(new IdentifierLiteral($1)), LOC(3)(new Access($3)));
588
- }),
589
- o('IMPORT_META . Property', function () {
590
- return new MetaProperty(LOC(1)(new IdentifierLiteral($1)), LOC(3)(new Access($3)));
591
- }),
592
- ],
593
- // The general group of accessors into an object, by property, by prototype
594
- // or by array index or slice.
595
- Accessor: [
596
- o('. Property', function () {
597
- return new Access($2);
598
- }),
599
- o('?. Property', function () {
600
- return new Access($2, {
601
- soak: true,
602
- });
603
- }),
604
- o(':: Property', function () {
605
- return [
606
- LOC(1)(
607
- new Access(new PropertyName('prototype'), {
608
- shorthand: true,
609
- }),
610
- ),
611
- LOC(2)(new Access($2)),
612
- ];
613
- }),
614
- o('?:: Property', function () {
615
- return [
616
- LOC(1)(
617
- new Access(new PropertyName('prototype'), {
618
- shorthand: true,
619
- soak: true,
620
- }),
621
- ),
622
- LOC(2)(new Access($2)),
623
- ];
624
- }),
625
- o('::', function () {
626
- return new Access(new PropertyName('prototype'), {
627
- shorthand: true,
628
- });
629
- }),
630
- o('?::', function () {
631
- return new Access(new PropertyName('prototype'), {
632
- shorthand: true,
633
- soak: true,
634
- });
635
- }),
636
- o('Index'),
637
- ],
638
- // Indexing into an object or array using bracket notation.
639
- Index: [
640
- o('INDEX_START IndexValue INDEX_END', function () {
641
- return $2;
642
- }),
643
- o('INDEX_START INDENT IndexValue OUTDENT INDEX_END', function () {
644
- return $3;
645
- }),
646
- o('INDEX_SOAK Index', function () {
647
- return extend($2, {
648
- soak: true,
649
- });
650
- }),
651
- ],
652
- IndexValue: [
653
- o('Expression', function () {
654
- return new Index($1);
655
- }),
656
- o('Slice', function () {
657
- return new Slice($1);
658
- }),
659
- ],
660
- // In CoffeeScript, an object literal is simply a list of assignments.
661
- Object: [
662
- o('{ AssignList OptComma }', function () {
663
- return new Obj($2, $1.generated);
664
- }),
665
- ],
666
- // Assignment of properties within an object literal can be separated by
667
- // comma, as in JavaScript, or simply by newline.
668
- AssignList: [
669
- o('', function () {
670
- return [];
671
- }),
672
- o('AssignObj', function () {
673
- return [$1];
674
- }),
675
- o('AssignList , AssignObj', function () {
676
- return $1.concat($3);
677
- }),
678
- o('AssignList OptComma TERMINATOR AssignObj', function () {
679
- return $1.concat($4);
680
- }),
681
- o('AssignList OptComma INDENT AssignList OptComma OUTDENT', function () {
682
- return $1.concat($4);
683
- }),
684
- ],
685
- // Class definitions have optional bodies of prototype property assignments,
686
- // and optional references to the superclass.
687
- Class: [
688
- o('CLASS', function () {
689
- return new Class();
690
- }),
691
- o('CLASS Block', function () {
692
- return new Class(null, null, $2);
693
- }),
694
- o('CLASS EXTENDS Expression', function () {
695
- return new Class(null, $3);
696
- }),
697
- o('CLASS EXTENDS Expression Block', function () {
698
- return new Class(null, $3, $4);
699
- }),
700
- o('CLASS SimpleAssignable', function () {
701
- return new Class($2);
702
- }),
703
- o('CLASS SimpleAssignable Block', function () {
704
- return new Class($2, null, $3);
705
- }),
706
- o('CLASS SimpleAssignable EXTENDS Expression', function () {
707
- return new Class($2, $4);
708
- }),
709
- o('CLASS SimpleAssignable EXTENDS Expression Block', function () {
710
- return new Class($2, $4, $5);
711
- }),
712
- ],
713
- Import: [
714
- o('IMPORT String', function () {
715
- return new ImportDeclaration(null, $2);
716
- }),
717
- o('IMPORT String ASSERT Object', function () {
718
- return new ImportDeclaration(null, $2, $4);
719
- }),
720
- o('IMPORT ImportDefaultSpecifier FROM String', function () {
721
- return new ImportDeclaration(new ImportClause($2, null), $4);
722
- }),
723
- o('IMPORT ImportDefaultSpecifier FROM String ASSERT Object', function () {
724
- return new ImportDeclaration(new ImportClause($2, null), $4, $6);
725
- }),
726
- o('IMPORT ImportNamespaceSpecifier FROM String', function () {
727
- return new ImportDeclaration(new ImportClause(null, $2), $4);
728
- }),
729
- o('IMPORT ImportNamespaceSpecifier FROM String ASSERT Object', function () {
730
- return new ImportDeclaration(new ImportClause(null, $2), $4, $6);
731
- }),
732
- o('IMPORT { } FROM String', function () {
733
- return new ImportDeclaration(new ImportClause(null, new ImportSpecifierList([])), $5);
734
- }),
735
- o('IMPORT { } FROM String ASSERT Object', function () {
736
- return new ImportDeclaration(new ImportClause(null, new ImportSpecifierList([])), $5, $7);
737
- }),
738
- o('IMPORT { ImportSpecifierList OptComma } FROM String', function () {
739
- return new ImportDeclaration(new ImportClause(null, new ImportSpecifierList($3)), $7);
740
- }),
741
- o('IMPORT { ImportSpecifierList OptComma } FROM String ASSERT Object', function () {
742
- return new ImportDeclaration(new ImportClause(null, new ImportSpecifierList($3)), $7, $9);
743
- }),
744
- o('IMPORT ImportDefaultSpecifier , ImportNamespaceSpecifier FROM String', function () {
745
- return new ImportDeclaration(new ImportClause($2, $4), $6);
746
- }),
747
- o('IMPORT ImportDefaultSpecifier , ImportNamespaceSpecifier FROM String ASSERT Object', function () {
748
- return new ImportDeclaration(new ImportClause($2, $4), $6, $8);
749
- }),
750
- o('IMPORT ImportDefaultSpecifier , { ImportSpecifierList OptComma } FROM String', function () {
751
- return new ImportDeclaration(new ImportClause($2, new ImportSpecifierList($5)), $9);
752
- }),
753
- o('IMPORT ImportDefaultSpecifier , { ImportSpecifierList OptComma } FROM String ASSERT Object', function () {
754
- return new ImportDeclaration(new ImportClause($2, new ImportSpecifierList($5)), $9, $11);
755
- }),
756
- ],
757
- ImportSpecifierList: [
758
- o('ImportSpecifier', function () {
759
- return [$1];
760
- }),
761
- o('ImportSpecifierList , ImportSpecifier', function () {
762
- return $1.concat($3);
763
- }),
764
- o('ImportSpecifierList OptComma TERMINATOR ImportSpecifier', function () {
765
- return $1.concat($4);
766
- }),
767
- o('INDENT ImportSpecifierList OptComma OUTDENT', function () {
768
- return $2;
769
- }),
770
- o('ImportSpecifierList OptComma INDENT ImportSpecifierList OptComma OUTDENT', function () {
771
- return $1.concat($4);
772
- }),
773
- ],
774
- ImportSpecifier: [
775
- o('Identifier', function () {
776
- return new ImportSpecifier($1);
777
- }),
778
- o('Identifier AS Identifier', function () {
779
- return new ImportSpecifier($1, $3);
780
- }),
781
- o('DEFAULT', function () {
782
- return new ImportSpecifier(LOC(1)(new DefaultLiteral($1)));
783
- }),
784
- o('DEFAULT AS Identifier', function () {
785
- return new ImportSpecifier(LOC(1)(new DefaultLiteral($1)), $3);
786
- }),
787
- ],
788
- ImportDefaultSpecifier: [
789
- o('Identifier', function () {
790
- return new ImportDefaultSpecifier($1);
791
- }),
792
- ],
793
- ImportNamespaceSpecifier: [
794
- o('IMPORT_ALL AS Identifier', function () {
795
- return new ImportNamespaceSpecifier(new Literal($1), $3);
796
- }),
797
- ],
798
- Export: [
799
- o('EXPORT { }', function () {
800
- return new ExportNamedDeclaration(new ExportSpecifierList([]));
801
- }),
802
- o('EXPORT { ExportSpecifierList OptComma }', function () {
803
- return new ExportNamedDeclaration(new ExportSpecifierList($3));
804
- }),
805
- o('EXPORT Class', function () {
806
- return new ExportNamedDeclaration($2);
807
- }),
808
- o('EXPORT Identifier = Expression', function () {
809
- return new ExportNamedDeclaration(
810
- LOC(
811
- 2,
812
- 4,
813
- )(
814
- new Assign($2, $4, null, {
815
- moduleDeclaration: 'export',
816
- }),
817
- ),
818
- );
819
- }),
820
- o('EXPORT Identifier = TERMINATOR Expression', function () {
821
- return new ExportNamedDeclaration(
822
- LOC(
823
- 2,
824
- 5,
825
- )(
826
- new Assign($2, $5, null, {
827
- moduleDeclaration: 'export',
828
- }),
829
- ),
830
- );
831
- }),
832
- o('EXPORT Identifier = INDENT Expression OUTDENT', function () {
833
- return new ExportNamedDeclaration(
834
- LOC(
835
- 2,
836
- 6,
837
- )(
838
- new Assign($2, $5, null, {
839
- moduleDeclaration: 'export',
840
- }),
841
- ),
842
- );
843
- }),
844
- o('EXPORT DEFAULT Expression', function () {
845
- return new ExportDefaultDeclaration($3);
846
- }),
847
- o('EXPORT DEFAULT INDENT Object OUTDENT', function () {
848
- return new ExportDefaultDeclaration(new Value($4));
849
- }),
850
- o('EXPORT EXPORT_ALL FROM String', function () {
851
- return new ExportAllDeclaration(new Literal($2), $4);
852
- }),
853
- o('EXPORT EXPORT_ALL FROM String ASSERT Object', function () {
854
- return new ExportAllDeclaration(new Literal($2), $4, $6);
855
- }),
856
- o('EXPORT { } FROM String', function () {
857
- return new ExportNamedDeclaration(new ExportSpecifierList([]), $5);
858
- }),
859
- o('EXPORT { } FROM String ASSERT Object', function () {
860
- return new ExportNamedDeclaration(new ExportSpecifierList([]), $5, $7);
861
- }),
862
- o('EXPORT { ExportSpecifierList OptComma } FROM String', function () {
863
- return new ExportNamedDeclaration(new ExportSpecifierList($3), $7);
864
- }),
865
- o('EXPORT { ExportSpecifierList OptComma } FROM String ASSERT Object', function () {
866
- return new ExportNamedDeclaration(new ExportSpecifierList($3), $7, $9);
867
- }),
868
- ],
869
- ExportSpecifierList: [
870
- o('ExportSpecifier', function () {
871
- return [$1];
872
- }),
873
- o('ExportSpecifierList , ExportSpecifier', function () {
874
- return $1.concat($3);
875
- }),
876
- o('ExportSpecifierList OptComma TERMINATOR ExportSpecifier', function () {
877
- return $1.concat($4);
878
- }),
879
- o('INDENT ExportSpecifierList OptComma OUTDENT', function () {
880
- return $2;
881
- }),
882
- o('ExportSpecifierList OptComma INDENT ExportSpecifierList OptComma OUTDENT', function () {
883
- return $1.concat($4);
884
- }),
885
- ],
886
- ExportSpecifier: [
887
- o('Identifier', function () {
888
- return new ExportSpecifier($1);
889
- }),
890
- o('Identifier AS Identifier', function () {
891
- return new ExportSpecifier($1, $3);
892
- }),
893
- o('Identifier AS DEFAULT', function () {
894
- return new ExportSpecifier($1, LOC(3)(new DefaultLiteral($3)));
895
- }),
896
- o('DEFAULT', function () {
897
- return new ExportSpecifier(LOC(1)(new DefaultLiteral($1)));
898
- }),
899
- o('DEFAULT AS Identifier', function () {
900
- return new ExportSpecifier(LOC(1)(new DefaultLiteral($1)), $3);
901
- }),
902
- ],
903
- // Ordinary function invocation, or a chained series of calls.
904
- Invocation: [
905
- o('Value OptFuncExist String', function () {
906
- return new TaggedTemplateCall($1, $3, $2.soak);
907
- }),
908
- o('Value OptFuncExist Arguments', function () {
909
- return new Call($1, $3, $2.soak);
910
- }),
911
- o('SUPER OptFuncExist Arguments', function () {
912
- return new SuperCall(LOC(1)(new Super()), $3, $2.soak, $1);
913
- }),
914
- o('DYNAMIC_IMPORT Arguments', function () {
915
- return new DynamicImportCall(LOC(1)(new DynamicImport()), $2);
916
- }),
917
- ],
918
- // An optional existence check on a function.
919
- OptFuncExist: [
920
- o('', function () {
921
- return {
922
- soak: false,
923
- };
924
- }),
925
- o('FUNC_EXIST', function () {
926
- return {
927
- soak: true,
928
- };
929
- }),
930
- ],
931
- // The list of arguments to a function call.
932
- Arguments: [
933
- o('CALL_START CALL_END', function () {
934
- return [];
935
- }),
936
- o('CALL_START ArgList OptComma CALL_END', function () {
937
- $2.implicit = $1.generated;
938
- return $2;
939
- }),
940
- ],
941
- // A reference to the *this* current object.
942
- This: [
943
- o('THIS', function () {
944
- return new Value(new ThisLiteral($1));
945
- }),
946
- o('@', function () {
947
- return new Value(new ThisLiteral($1));
948
- }),
949
- ],
950
- // A reference to a property on *this*.
951
- ThisProperty: [
952
- o('@ Property', function () {
953
- return new Value(LOC(1)(new ThisLiteral($1)), [LOC(2)(new Access($2))], 'this');
954
- }),
955
- ],
956
- // The array literal.
957
- Array: [
958
- o('[ ]', function () {
959
- return new Arr([]);
960
- }),
961
- o('[ Elisions ]', function () {
962
- return new Arr($2);
963
- }),
964
- o('[ ArgElisionList OptElisions ]', function () {
965
- return new Arr([].concat($2, $3));
966
- }),
967
- ],
968
- // Inclusive and exclusive range dots.
969
- RangeDots: [
970
- o('..', function () {
971
- return {
972
- exclusive: false,
973
- };
974
- }),
975
- o('...', function () {
976
- return {
977
- exclusive: true,
978
- };
979
- }),
980
- ],
981
- // The CoffeeScript range literal.
982
- Range: [
983
- o('[ Expression RangeDots Expression ]', function () {
984
- return new Range($2, $4, $3.exclusive ? 'exclusive' : 'inclusive');
985
- }),
986
- o('[ ExpressionLine RangeDots Expression ]', function () {
987
- return new Range($2, $4, $3.exclusive ? 'exclusive' : 'inclusive');
988
- }),
989
- ],
990
- // Array slice literals.
991
- Slice: [
992
- o('Expression RangeDots Expression', function () {
993
- return new Range($1, $3, $2.exclusive ? 'exclusive' : 'inclusive');
994
- }),
995
- o('Expression RangeDots', function () {
996
- return new Range($1, null, $2.exclusive ? 'exclusive' : 'inclusive');
997
- }),
998
- o('ExpressionLine RangeDots Expression', function () {
999
- return new Range($1, $3, $2.exclusive ? 'exclusive' : 'inclusive');
1000
- }),
1001
- o('ExpressionLine RangeDots', function () {
1002
- return new Range($1, null, $2.exclusive ? 'exclusive' : 'inclusive');
1003
- }),
1004
- o('RangeDots Expression', function () {
1005
- return new Range(null, $2, $1.exclusive ? 'exclusive' : 'inclusive');
1006
- }),
1007
- o('RangeDots', function () {
1008
- return new Range(null, null, $1.exclusive ? 'exclusive' : 'inclusive');
1009
- }),
1010
- ],
1011
- // The **ArgList** is the list of objects passed into a function call
1012
- // (i.e. comma-separated expressions). Newlines work as well.
1013
- ArgList: [
1014
- o('Arg', function () {
1015
- return [$1];
1016
- }),
1017
- o('ArgList , Arg', function () {
1018
- return $1.concat($3);
1019
- }),
1020
- o('ArgList OptComma TERMINATOR Arg', function () {
1021
- return $1.concat($4);
1022
- }),
1023
- o('INDENT ArgList OptComma OUTDENT', function () {
1024
- return $2;
1025
- }),
1026
- o('ArgList OptComma INDENT ArgList OptComma OUTDENT', function () {
1027
- return $1.concat($4);
1028
- }),
1029
- ],
1030
- // Valid arguments are Blocks or Splats.
1031
- Arg: [
1032
- o('Expression'),
1033
- o('ExpressionLine'),
1034
- o('Splat'),
1035
- o('...', function () {
1036
- return new Expansion();
1037
- }),
1038
- ],
1039
- // The **ArgElisionList** is the list of objects, contents of an array literal
1040
- // (i.e. comma-separated expressions and elisions). Newlines work as well.
1041
- ArgElisionList: [
1042
- o('ArgElision'),
1043
- o('ArgElisionList , ArgElision', function () {
1044
- return $1.concat($3);
1045
- }),
1046
- o('ArgElisionList OptComma TERMINATOR ArgElision', function () {
1047
- return $1.concat($4);
1048
- }),
1049
- o('INDENT ArgElisionList OptElisions OUTDENT', function () {
1050
- return $2.concat($3);
1051
- }),
1052
- o('ArgElisionList OptElisions INDENT ArgElisionList OptElisions OUTDENT', function () {
1053
- return $1.concat($2, $4, $5);
1054
- }),
1055
- ],
1056
- ArgElision: [
1057
- o('Arg', function () {
1058
- return [$1];
1059
- }),
1060
- o('Elisions Arg', function () {
1061
- return $1.concat($2);
1062
- }),
1063
- ],
1064
- OptElisions: [
1065
- o('OptComma', function () {
1066
- return [];
1067
- }),
1068
- o(', Elisions', function () {
1069
- return [].concat($2);
1070
- }),
1071
- ],
1072
- Elisions: [
1073
- o('Elision', function () {
1074
- return [$1];
1075
- }),
1076
- o('Elisions Elision', function () {
1077
- return $1.concat($2);
1078
- }),
1079
- ],
1080
- Elision: [
1081
- o(',', function () {
1082
- return new Elision();
1083
- }),
1084
- o('Elision TERMINATOR', function () {
1085
- return $1;
1086
- }),
1087
- ],
1088
- // Just simple, comma-separated, required arguments (no fancy syntax). We need
1089
- // this to be separate from the **ArgList** for use in **Switch** blocks, where
1090
- // having the newlines wouldn't make sense.
1091
- SimpleArgs: [
1092
- o('Expression'),
1093
- o('ExpressionLine'),
1094
- o('SimpleArgs , Expression', function () {
1095
- return [].concat($1, $3);
1096
- }),
1097
- o('SimpleArgs , ExpressionLine', function () {
1098
- return [].concat($1, $3);
1099
- }),
1100
- ],
1101
- // The variants of *try/catch/finally* exception handling blocks.
1102
- Try: [
1103
- o('TRY Block', function () {
1104
- return new Try($2);
1105
- }),
1106
- o('TRY Block Catch', function () {
1107
- return new Try($2, $3);
1108
- }),
1109
- o('TRY Block FINALLY Block', function () {
1110
- return new Try($2, null, $4, LOC(3)(new Literal($3)));
1111
- }),
1112
- o('TRY Block Catch FINALLY Block', function () {
1113
- return new Try($2, $3, $5, LOC(4)(new Literal($4)));
1114
- }),
1115
- ],
1116
- // A catch clause names its error and runs a block of code.
1117
- Catch: [
1118
- o('CATCH Identifier Block', function () {
1119
- return new Catch($3, $2);
1120
- }),
1121
- o('CATCH Object Block', function () {
1122
- return new Catch($3, LOC(2)(new Value($2)));
1123
- }),
1124
- o('CATCH Block', function () {
1125
- return new Catch($2);
1126
- }),
1127
- ],
1128
- // Throw an exception object.
1129
- Throw: [
1130
- o('THROW Expression', function () {
1131
- return new Throw($2);
1132
- }),
1133
- o('THROW INDENT Object OUTDENT', function () {
1134
- return new Throw(new Value($3));
1135
- }),
1136
- ],
1137
- // Parenthetical expressions. Note that the **Parenthetical** is a **Value**,
1138
- // not an **Expression**, so if you need to use an expression in a place
1139
- // where only values are accepted, wrapping it in parentheses will always do
1140
- // the trick.
1141
- Parenthetical: [
1142
- o('( Body )', function () {
1143
- return new Parens($2);
1144
- }),
1145
- o('( INDENT Body OUTDENT )', function () {
1146
- return new Parens($3);
1147
- }),
1148
- ],
1149
- // The condition portion of a while loop.
1150
- WhileLineSource: [
1151
- o('WHILE ExpressionLine', function () {
1152
- return new While($2);
1153
- }),
1154
- o('WHILE ExpressionLine WHEN ExpressionLine', function () {
1155
- return new While($2, {
1156
- guard: $4,
1157
- });
1158
- }),
1159
- o('UNTIL ExpressionLine', function () {
1160
- return new While($2, {
1161
- invert: true,
1162
- });
1163
- }),
1164
- o('UNTIL ExpressionLine WHEN ExpressionLine', function () {
1165
- return new While($2, {
1166
- invert: true,
1167
- guard: $4,
1168
- });
1169
- }),
1170
- ],
1171
- WhileSource: [
1172
- o('WHILE Expression', function () {
1173
- return new While($2);
1174
- }),
1175
- o('WHILE Expression WHEN Expression', function () {
1176
- return new While($2, {
1177
- guard: $4,
1178
- });
1179
- }),
1180
- o('WHILE ExpressionLine WHEN Expression', function () {
1181
- return new While($2, {
1182
- guard: $4,
1183
- });
1184
- }),
1185
- o('UNTIL Expression', function () {
1186
- return new While($2, {
1187
- invert: true,
1188
- });
1189
- }),
1190
- o('UNTIL Expression WHEN Expression', function () {
1191
- return new While($2, {
1192
- invert: true,
1193
- guard: $4,
1194
- });
1195
- }),
1196
- o('UNTIL ExpressionLine WHEN Expression', function () {
1197
- return new While($2, {
1198
- invert: true,
1199
- guard: $4,
1200
- });
1201
- }),
1202
- ],
1203
- // The while loop can either be normal, with a block of expressions to execute,
1204
- // or postfix, with a single expression. There is no do..while.
1205
- While: [
1206
- o('WhileSource Block', function () {
1207
- return $1.addBody($2);
1208
- }),
1209
- o('WhileLineSource Block', function () {
1210
- return $1.addBody($2);
1211
- }),
1212
- o('Statement WhileSource', function () {
1213
- return Object.assign($2, {
1214
- postfix: true,
1215
- }).addBody(LOC(1)(Block.wrap([$1])));
1216
- }),
1217
- o('Expression WhileSource', function () {
1218
- return Object.assign($2, {
1219
- postfix: true,
1220
- }).addBody(LOC(1)(Block.wrap([$1])));
1221
- }),
1222
- o('Loop', function () {
1223
- return $1;
1224
- }),
1225
- ],
1226
- Loop: [
1227
- o('LOOP Block', function () {
1228
- return new While(LOC(1)(new BooleanLiteral('true')), {
1229
- isLoop: true,
1230
- }).addBody($2);
1231
- }),
1232
- o('LOOP Expression', function () {
1233
- return new While(LOC(1)(new BooleanLiteral('true')), {
1234
- isLoop: true,
1235
- }).addBody(LOC(2)(Block.wrap([$2])));
1236
- }),
1237
- ],
1238
- // Array, object, and range comprehensions, at the most generic level.
1239
- // Comprehensions can either be normal, with a block of expressions to execute,
1240
- // or postfix, with a single expression.
1241
- For: [
1242
- o('Statement ForBody', function () {
1243
- $2.postfix = true;
1244
- return $2.addBody($1);
1245
- }),
1246
- o('Expression ForBody', function () {
1247
- $2.postfix = true;
1248
- return $2.addBody($1);
1249
- }),
1250
- o('ForBody Block', function () {
1251
- return $1.addBody($2);
1252
- }),
1253
- o('ForLineBody Block', function () {
1254
- return $1.addBody($2);
1255
- }),
1256
- ],
1257
- ForBody: [
1258
- o('FOR Range', function () {
1259
- return new For([], {
1260
- source: LOC(2)(new Value($2)),
1261
- });
1262
- }),
1263
- o('FOR Range BY Expression', function () {
1264
- return new For([], {
1265
- source: LOC(2)(new Value($2)),
1266
- step: $4,
1267
- });
1268
- }),
1269
- o('ForStart ForSource', function () {
1270
- return $1.addSource($2);
1271
- }),
1272
- ],
1273
- ForLineBody: [
1274
- o('FOR Range BY ExpressionLine', function () {
1275
- return new For([], {
1276
- source: LOC(2)(new Value($2)),
1277
- step: $4,
1278
- });
1279
- }),
1280
- o('ForStart ForLineSource', function () {
1281
- return $1.addSource($2);
1282
- }),
1283
- ],
1284
- ForStart: [
1285
- o('FOR ForVariables', function () {
1286
- return new For([], {
1287
- name: $2[0],
1288
- index: $2[1],
1289
- });
1290
- }),
1291
- o('FOR AWAIT ForVariables', function () {
1292
- var index, name;
1293
- [name, index] = $3;
1294
- return new For([], {
1295
- name,
1296
- index,
1297
- await: true,
1298
- awaitTag: LOC(2)(new Literal($2)),
1299
- });
1300
- }),
1301
- o('FOR OWN ForVariables', function () {
1302
- var index, name;
1303
- [name, index] = $3;
1304
- return new For([], {
1305
- name,
1306
- index,
1307
- own: true,
1308
- ownTag: LOC(2)(new Literal($2)),
1309
- });
1310
- }),
1311
- ],
1312
- // An array of all accepted values for a variable inside the loop.
1313
- // This enables support for pattern matching.
1314
- ForValue: [
1315
- o('Identifier'),
1316
- o('ThisProperty'),
1317
- o('Array', function () {
1318
- return new Value($1);
1319
- }),
1320
- o('Object', function () {
1321
- return new Value($1);
1322
- }),
1323
- ],
1324
- // An array or range comprehension has variables for the current element
1325
- // and (optional) reference to the current index. Or, *key, value*, in the case
1326
- // of object comprehensions.
1327
- ForVariables: [
1328
- o('ForValue', function () {
1329
- return [$1];
1330
- }),
1331
- o('ForValue , ForValue', function () {
1332
- return [$1, $3];
1333
- }),
1334
- ],
1335
- // The source of a comprehension is an array or object with an optional guard
1336
- // clause. If it’s an array comprehension, you can also choose to step through
1337
- // in fixed-size increments.
1338
- ForSource: [
1339
- o('FORIN Expression', function () {
1340
- return {
1341
- source: $2,
1342
- };
1343
- }),
1344
- o('FOROF Expression', function () {
1345
- return {
1346
- source: $2,
1347
- object: true,
1348
- };
1349
- }),
1350
- o('FORIN Expression WHEN Expression', function () {
1351
- return {
1352
- source: $2,
1353
- guard: $4,
1354
- };
1355
- }),
1356
- o('FORIN ExpressionLine WHEN Expression', function () {
1357
- return {
1358
- source: $2,
1359
- guard: $4,
1360
- };
1361
- }),
1362
- o('FOROF Expression WHEN Expression', function () {
1363
- return {
1364
- source: $2,
1365
- guard: $4,
1366
- object: true,
1367
- };
1368
- }),
1369
- o('FOROF ExpressionLine WHEN Expression', function () {
1370
- return {
1371
- source: $2,
1372
- guard: $4,
1373
- object: true,
1374
- };
1375
- }),
1376
- o('FORIN Expression BY Expression', function () {
1377
- return {
1378
- source: $2,
1379
- step: $4,
1380
- };
1381
- }),
1382
- o('FORIN ExpressionLine BY Expression', function () {
1383
- return {
1384
- source: $2,
1385
- step: $4,
1386
- };
1387
- }),
1388
- o('FORIN Expression WHEN Expression BY Expression', function () {
1389
- return {
1390
- source: $2,
1391
- guard: $4,
1392
- step: $6,
1393
- };
1394
- }),
1395
- o('FORIN ExpressionLine WHEN Expression BY Expression', function () {
1396
- return {
1397
- source: $2,
1398
- guard: $4,
1399
- step: $6,
1400
- };
1401
- }),
1402
- o('FORIN Expression WHEN ExpressionLine BY Expression', function () {
1403
- return {
1404
- source: $2,
1405
- guard: $4,
1406
- step: $6,
1407
- };
1408
- }),
1409
- o('FORIN ExpressionLine WHEN ExpressionLine BY Expression', function () {
1410
- return {
1411
- source: $2,
1412
- guard: $4,
1413
- step: $6,
1414
- };
1415
- }),
1416
- o('FORIN Expression BY Expression WHEN Expression', function () {
1417
- return {
1418
- source: $2,
1419
- step: $4,
1420
- guard: $6,
1421
- };
1422
- }),
1423
- o('FORIN ExpressionLine BY Expression WHEN Expression', function () {
1424
- return {
1425
- source: $2,
1426
- step: $4,
1427
- guard: $6,
1428
- };
1429
- }),
1430
- o('FORIN Expression BY ExpressionLine WHEN Expression', function () {
1431
- return {
1432
- source: $2,
1433
- step: $4,
1434
- guard: $6,
1435
- };
1436
- }),
1437
- o('FORIN ExpressionLine BY ExpressionLine WHEN Expression', function () {
1438
- return {
1439
- source: $2,
1440
- step: $4,
1441
- guard: $6,
1442
- };
1443
- }),
1444
- o('FORFROM Expression', function () {
1445
- return {
1446
- source: $2,
1447
- from: true,
1448
- };
1449
- }),
1450
- o('FORFROM Expression WHEN Expression', function () {
1451
- return {
1452
- source: $2,
1453
- guard: $4,
1454
- from: true,
1455
- };
1456
- }),
1457
- o('FORFROM ExpressionLine WHEN Expression', function () {
1458
- return {
1459
- source: $2,
1460
- guard: $4,
1461
- from: true,
1462
- };
1463
- }),
1464
- ],
1465
- ForLineSource: [
1466
- o('FORIN ExpressionLine', function () {
1467
- return {
1468
- source: $2,
1469
- };
1470
- }),
1471
- o('FOROF ExpressionLine', function () {
1472
- return {
1473
- source: $2,
1474
- object: true,
1475
- };
1476
- }),
1477
- o('FORIN Expression WHEN ExpressionLine', function () {
1478
- return {
1479
- source: $2,
1480
- guard: $4,
1481
- };
1482
- }),
1483
- o('FORIN ExpressionLine WHEN ExpressionLine', function () {
1484
- return {
1485
- source: $2,
1486
- guard: $4,
1487
- };
1488
- }),
1489
- o('FOROF Expression WHEN ExpressionLine', function () {
1490
- return {
1491
- source: $2,
1492
- guard: $4,
1493
- object: true,
1494
- };
1495
- }),
1496
- o('FOROF ExpressionLine WHEN ExpressionLine', function () {
1497
- return {
1498
- source: $2,
1499
- guard: $4,
1500
- object: true,
1501
- };
1502
- }),
1503
- o('FORIN Expression BY ExpressionLine', function () {
1504
- return {
1505
- source: $2,
1506
- step: $4,
1507
- };
1508
- }),
1509
- o('FORIN ExpressionLine BY ExpressionLine', function () {
1510
- return {
1511
- source: $2,
1512
- step: $4,
1513
- };
1514
- }),
1515
- o('FORIN Expression WHEN Expression BY ExpressionLine', function () {
1516
- return {
1517
- source: $2,
1518
- guard: $4,
1519
- step: $6,
1520
- };
1521
- }),
1522
- o('FORIN ExpressionLine WHEN Expression BY ExpressionLine', function () {
1523
- return {
1524
- source: $2,
1525
- guard: $4,
1526
- step: $6,
1527
- };
1528
- }),
1529
- o('FORIN Expression WHEN ExpressionLine BY ExpressionLine', function () {
1530
- return {
1531
- source: $2,
1532
- guard: $4,
1533
- step: $6,
1534
- };
1535
- }),
1536
- o('FORIN ExpressionLine WHEN ExpressionLine BY ExpressionLine', function () {
1537
- return {
1538
- source: $2,
1539
- guard: $4,
1540
- step: $6,
1541
- };
1542
- }),
1543
- o('FORIN Expression BY Expression WHEN ExpressionLine', function () {
1544
- return {
1545
- source: $2,
1546
- step: $4,
1547
- guard: $6,
1548
- };
1549
- }),
1550
- o('FORIN ExpressionLine BY Expression WHEN ExpressionLine', function () {
1551
- return {
1552
- source: $2,
1553
- step: $4,
1554
- guard: $6,
1555
- };
1556
- }),
1557
- o('FORIN Expression BY ExpressionLine WHEN ExpressionLine', function () {
1558
- return {
1559
- source: $2,
1560
- step: $4,
1561
- guard: $6,
1562
- };
1563
- }),
1564
- o('FORIN ExpressionLine BY ExpressionLine WHEN ExpressionLine', function () {
1565
- return {
1566
- source: $2,
1567
- step: $4,
1568
- guard: $6,
1569
- };
1570
- }),
1571
- o('FORFROM ExpressionLine', function () {
1572
- return {
1573
- source: $2,
1574
- from: true,
1575
- };
1576
- }),
1577
- o('FORFROM Expression WHEN ExpressionLine', function () {
1578
- return {
1579
- source: $2,
1580
- guard: $4,
1581
- from: true,
1582
- };
1583
- }),
1584
- o('FORFROM ExpressionLine WHEN ExpressionLine', function () {
1585
- return {
1586
- source: $2,
1587
- guard: $4,
1588
- from: true,
1589
- };
1590
- }),
1591
- ],
1592
- Switch: [
1593
- o('SWITCH Expression INDENT Whens OUTDENT', function () {
1594
- return new Switch($2, $4);
1595
- }),
1596
- o('SWITCH ExpressionLine INDENT Whens OUTDENT', function () {
1597
- return new Switch($2, $4);
1598
- }),
1599
- o('SWITCH Expression INDENT Whens ELSE Block OUTDENT', function () {
1600
- return new Switch($2, $4, LOC(5, 6)($6));
1601
- }),
1602
- o('SWITCH ExpressionLine INDENT Whens ELSE Block OUTDENT', function () {
1603
- return new Switch($2, $4, LOC(5, 6)($6));
1604
- }),
1605
- o('SWITCH INDENT Whens OUTDENT', function () {
1606
- return new Switch(null, $3);
1607
- }),
1608
- o('SWITCH INDENT Whens ELSE Block OUTDENT', function () {
1609
- return new Switch(null, $3, LOC(4, 5)($5));
1610
- }),
1611
- ],
1612
- Whens: [
1613
- o('When', function () {
1614
- return [$1];
1615
- }),
1616
- o('Whens When', function () {
1617
- return $1.concat($2);
1618
- }),
1619
- ],
1620
- // An individual **When** clause, with action.
1621
- When: [
1622
- o('LEADING_WHEN SimpleArgs Block', function () {
1623
- return new SwitchWhen($2, $3);
1624
- }),
1625
- o('LEADING_WHEN SimpleArgs Block TERMINATOR', function () {
1626
- return LOC(1, 3)(new SwitchWhen($2, $3));
1627
- }),
1628
- ],
1629
- // The most basic form of *if* is a condition and an action. The following
1630
- // if-related rules are broken up along these lines in order to avoid
1631
- // ambiguity.
1632
- IfBlock: [
1633
- o('IF Expression Block', function () {
1634
- return new If($2, $3, {
1635
- type: $1,
1636
- });
1637
- }),
1638
- o('IfBlock ELSE IF Expression Block', function () {
1639
- return $1.addElse(
1640
- LOC(
1641
- 3,
1642
- 5,
1643
- )(
1644
- new If($4, $5, {
1645
- type: $3,
1646
- }),
1647
- ),
1648
- );
1649
- }),
1650
- ],
1651
- // The full complement of *if* expressions, including postfix one-liner
1652
- // *if* and *unless*.
1653
- If: [
1654
- o('IfBlock'),
1655
- o('IfBlock ELSE Block', function () {
1656
- return $1.addElse($3);
1657
- }),
1658
- o('Statement POST_IF Expression', function () {
1659
- return new If($3, LOC(1)(Block.wrap([$1])), {
1660
- type: $2,
1661
- postfix: true,
1662
- });
1663
- }),
1664
- o('Expression POST_IF Expression', function () {
1665
- return new If($3, LOC(1)(Block.wrap([$1])), {
1666
- type: $2,
1667
- postfix: true,
1668
- });
1669
- }),
1670
- ],
1671
- IfBlockLine: [
1672
- o('IF ExpressionLine Block', function () {
1673
- return new If($2, $3, {
1674
- type: $1,
1675
- });
1676
- }),
1677
- o('IfBlockLine ELSE IF ExpressionLine Block', function () {
1678
- return $1.addElse(
1679
- LOC(
1680
- 3,
1681
- 5,
1682
- )(
1683
- new If($4, $5, {
1684
- type: $3,
1685
- }),
1686
- ),
1687
- );
1688
- }),
1689
- ],
1690
- IfLine: [
1691
- o('IfBlockLine'),
1692
- o('IfBlockLine ELSE Block', function () {
1693
- return $1.addElse($3);
1694
- }),
1695
- o('Statement POST_IF ExpressionLine', function () {
1696
- return new If($3, LOC(1)(Block.wrap([$1])), {
1697
- type: $2,
1698
- postfix: true,
1699
- });
1700
- }),
1701
- o('Expression POST_IF ExpressionLine', function () {
1702
- return new If($3, LOC(1)(Block.wrap([$1])), {
1703
- type: $2,
1704
- postfix: true,
1705
- });
1706
- }),
1707
- ],
1708
- // Arithmetic and logical operators, working on one or more operands.
1709
- // Here they are grouped by order of precedence. The actual precedence rules
1710
- // are defined at the bottom of the page. It would be shorter if we could
1711
- // combine most of these rules into a single generic *Operand OpSymbol Operand*
1712
- // -type rule, but in order to make the precedence binding possible, separate
1713
- // rules are necessary.
1714
- OperationLine: [
1715
- o('UNARY ExpressionLine', function () {
1716
- return new Op($1, $2);
1717
- }),
1718
- o('DO ExpressionLine', function () {
1719
- return new Op($1, $2);
1720
- }),
1721
- o('DO_IIFE CodeLine', function () {
1722
- return new Op($1, $2);
1723
- }),
1724
- ],
1725
- Operation: [
1726
- o('UNARY Expression', function () {
1727
- return new Op($1.toString(), $2, void 0, void 0, {
1728
- originalOperator: $1.original,
1729
- });
1730
- }),
1731
- o('DO Expression', function () {
1732
- return new Op($1, $2);
1733
- }),
1734
- o('UNARY_MATH Expression', function () {
1735
- return new Op($1, $2);
1736
- }),
1737
- o(
1738
- '- Expression',
1739
- function () {
1740
- return new Op('-', $2);
1741
- },
1742
- {
1743
- prec: 'UNARY_MATH',
1744
- },
1745
- ),
1746
- o(
1747
- '+ Expression',
1748
- function () {
1749
- return new Op('+', $2);
1750
- },
1751
- {
1752
- prec: 'UNARY_MATH',
1753
- },
1754
- ),
1755
- o('AWAIT Expression', function () {
1756
- return new Op($1, $2);
1757
- }),
1758
- o('AWAIT INDENT Object OUTDENT', function () {
1759
- return new Op($1, $3);
1760
- }),
1761
- o('-- SimpleAssignable', function () {
1762
- return new Op('--', $2);
1763
- }),
1764
- o('++ SimpleAssignable', function () {
1765
- return new Op('++', $2);
1766
- }),
1767
- o('SimpleAssignable --', function () {
1768
- return new Op('--', $1, null, true);
1769
- }),
1770
- o('SimpleAssignable ++', function () {
1771
- return new Op('++', $1, null, true);
1772
- }),
1773
- // [The existential operator](https://coffeescript.org/#existential-operator).
1774
- o('Expression ?', function () {
1775
- return new Existence($1);
1776
- }),
1777
- o('Expression + Expression', function () {
1778
- return new Op('+', $1, $3);
1779
- }),
1780
- o('Expression - Expression', function () {
1781
- return new Op('-', $1, $3);
1782
- }),
1783
- o('Expression MATH Expression', function () {
1784
- return new Op($2, $1, $3);
1785
- }),
1786
- o('Expression ** Expression', function () {
1787
- return new Op($2, $1, $3);
1788
- }),
1789
- o('Expression SHIFT Expression', function () {
1790
- return new Op($2, $1, $3);
1791
- }),
1792
- o('Expression COMPARE Expression', function () {
1793
- return new Op($2.toString(), $1, $3, void 0, {
1794
- originalOperator: $2.original,
1795
- });
1796
- }),
1797
- o('Expression & Expression', function () {
1798
- return new Op($2, $1, $3);
1799
- }),
1800
- o('Expression ^ Expression', function () {
1801
- return new Op($2, $1, $3);
1802
- }),
1803
- o('Expression | Expression', function () {
1804
- return new Op($2, $1, $3);
1805
- }),
1806
- o('Expression && Expression', function () {
1807
- return new Op($2.toString(), $1, $3, void 0, {
1808
- originalOperator: $2.original,
1809
- });
1810
- }),
1811
- o('Expression || Expression', function () {
1812
- return new Op($2.toString(), $1, $3, void 0, {
1813
- originalOperator: $2.original,
1814
- });
1815
- }),
1816
- o('Expression BIN? Expression', function () {
1817
- return new Op($2, $1, $3);
1818
- }),
1819
- o('Expression RELATION Expression', function () {
1820
- var ref, ref1;
1821
- return new Op($2.toString(), $1, $3, void 0, {
1822
- invertOperator: (ref = (ref1 = $2.invert) != null ? ref1.original : void 0) != null ? ref : $2.invert,
1823
- });
1824
- }),
1825
- o('SimpleAssignable COMPOUND_ASSIGN Expression', function () {
1826
- return new Assign($1, $3, $2.toString(), {
1827
- originalContext: $2.original,
1828
- });
1829
- }),
1830
- o('SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT', function () {
1831
- return new Assign($1, $4, $2.toString(), {
1832
- originalContext: $2.original,
1833
- });
1834
- }),
1835
- o('SimpleAssignable COMPOUND_ASSIGN TERMINATOR Expression', function () {
1836
- return new Assign($1, $4, $2.toString(), {
1837
- originalContext: $2.original,
1838
- });
1839
- }),
1840
- ],
1841
- DoIife: [
1842
- o('DO_IIFE Code', function () {
1843
- return new Op($1, $2);
1844
- }),
1845
- ],
1846
- };
1847
-
1848
- // Precedence
1849
- // ----------
1850
-
1851
- // Operators at the top of this list have higher precedence than the ones lower
1852
- // down. Following these rules is what makes `2 + 3 * 4` parse as:
1853
-
1854
- // 2 + (3 * 4)
1855
-
1856
- // And not:
1857
-
1858
- // (2 + 3) * 4
1859
- operators = [
1860
- ['right', 'DO_IIFE'],
1861
- ['left', '.', '?.', '::', '?::'],
1862
- ['left', 'CALL_START', 'CALL_END'],
1863
- ['nonassoc', '++', '--'],
1864
- ['left', '?'],
1865
- ['right', 'UNARY', 'DO'],
1866
- ['right', 'AWAIT'],
1867
- ['right', '**'],
1868
- ['right', 'UNARY_MATH'],
1869
- ['left', 'MATH'],
1870
- ['left', '+', '-'],
1871
- ['left', 'SHIFT'],
1872
- ['left', 'RELATION'],
1873
- ['left', 'COMPARE'],
1874
- ['left', '&'],
1875
- ['left', '^'],
1876
- ['left', '|'],
1877
- ['left', '&&'],
1878
- ['left', '||'],
1879
- ['left', 'BIN?'],
1880
- ['nonassoc', 'INDENT', 'OUTDENT'],
1881
- ['right', 'YIELD'],
1882
- ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS'],
1883
- ['right', 'FORIN', 'FOROF', 'FORFROM', 'BY', 'WHEN'],
1884
- ['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'IMPORT', 'EXPORT', 'DYNAMIC_IMPORT'],
1885
- ['left', 'POST_IF'],
1886
- ];
1887
-
1888
- // Wrapping Up
1889
- // -----------
1890
-
1891
- // Finally, now that we have our **grammar** and our **operators**, we can create
1892
- // our **Jison.Parser**. We do this by processing all of our rules, recording all
1893
- // terminals (every symbol which does not appear as the name of a rule above)
1894
- // as "tokens".
1895
- tokens = [];
1896
-
1897
- for (name in grammar) {
1898
- alternatives = grammar[name];
1899
- grammar[name] = (function () {
1900
- var i, j, len, len1, ref, results;
1901
- results = [];
1902
- for (i = 0, len = alternatives.length; i < len; i++) {
1903
- alt = alternatives[i];
1904
- ref = alt[0].split(' ');
1905
- for (j = 0, len1 = ref.length; j < len1; j++) {
1906
- token = ref[j];
1907
- if (!grammar[token]) {
1908
- tokens.push(token);
1909
- }
1910
- }
1911
- if (name === 'Root') {
1912
- alt[1] = `return ${alt[1]}`;
1913
- }
1914
- results.push(alt);
1915
- }
1916
- return results;
1917
- })();
1918
- }
1919
-
1920
- // Initialize the **Parser** with our list of terminal **tokens**, our **grammar**
1921
- // rules, and the name of the root. Reverse the operators because Jison orders
1922
- // precedence from low to high, and we have it high to low
1923
- // (as in [Yacc](http://dinosaur.compilertools.net/yacc/index.html)).
1924
- exports.parser = new Parser({
1925
- tokens: tokens.join(' '),
1926
- bnf: grammar,
1927
- operators: operators.reverse(),
1928
- startSymbol: 'Root',
1929
- });
1930
- }).call(this);