@makano/rew 1.1.81 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/lib/coffeescript/browser.js +144 -139
  2. package/lib/coffeescript/cake.js +132 -133
  3. package/lib/coffeescript/coffeescript.js +437 -381
  4. package/lib/coffeescript/command.js +806 -724
  5. package/lib/coffeescript/grammar.js +1908 -2474
  6. package/lib/coffeescript/helpers.js +509 -473
  7. package/lib/coffeescript/index.js +228 -215
  8. package/lib/coffeescript/lexer.js +2282 -1909
  9. package/lib/coffeescript/nodes.js +9782 -9202
  10. package/lib/coffeescript/optparse.js +255 -227
  11. package/lib/coffeescript/parser.js +20305 -1265
  12. package/lib/coffeescript/register.js +107 -87
  13. package/lib/coffeescript/repl.js +307 -284
  14. package/lib/coffeescript/rewriter.js +1389 -1079
  15. package/lib/coffeescript/scope.js +176 -172
  16. package/lib/coffeescript/sourcemap.js +242 -227
  17. package/lib/rew/cli/cli.js +312 -239
  18. package/lib/rew/cli/log.js +27 -27
  19. package/lib/rew/cli/run.js +8 -8
  20. package/lib/rew/cli/utils.js +368 -199
  21. package/lib/rew/const/config_path.js +2 -2
  22. package/lib/rew/const/default.js +38 -53
  23. package/lib/rew/const/files.js +11 -14
  24. package/lib/rew/const/opt.js +6 -6
  25. package/lib/rew/css/theme.css +1 -1
  26. package/lib/rew/functions/core.js +55 -55
  27. package/lib/rew/functions/curl.js +23 -0
  28. package/lib/rew/functions/emitter.js +52 -55
  29. package/lib/rew/functions/exec.js +25 -25
  30. package/lib/rew/functions/export.js +17 -17
  31. package/lib/rew/functions/fs.js +57 -59
  32. package/lib/rew/functions/future.js +29 -21
  33. package/lib/rew/functions/id.js +8 -9
  34. package/lib/rew/functions/import.js +106 -122
  35. package/lib/rew/functions/map.js +10 -10
  36. package/lib/rew/functions/match.js +35 -42
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -36
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +18 -18
  41. package/lib/rew/functions/types.js +82 -106
  42. package/lib/rew/html/ui.html +12 -12
  43. package/lib/rew/html/ui.js +196 -201
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +13 -13
  47. package/lib/rew/misc/findAppPath.js +15 -15
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +8 -8
  50. package/lib/rew/models/enum.js +12 -12
  51. package/lib/rew/models/struct.js +30 -32
  52. package/lib/rew/modules/compiler.js +237 -209
  53. package/lib/rew/modules/fs.js +10 -10
  54. package/lib/rew/modules/runtime.js +17 -21
  55. package/lib/rew/modules/yaml.js +27 -30
  56. package/lib/rew/pkgs/conf.js +82 -92
  57. package/lib/rew/pkgs/data.js +10 -10
  58. package/lib/rew/pkgs/date.js +27 -27
  59. package/lib/rew/pkgs/env.js +5 -5
  60. package/lib/rew/pkgs/modules/data/bintree.js +51 -51
  61. package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
  62. package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
  63. package/lib/rew/pkgs/modules/data/queue.js +18 -18
  64. package/lib/rew/pkgs/modules/data/stack.js +18 -18
  65. package/lib/rew/pkgs/modules/threads/worker.js +36 -36
  66. package/lib/rew/pkgs/modules/ui/classes.js +181 -184
  67. package/lib/rew/pkgs/pkgs.js +9 -9
  68. package/lib/rew/pkgs/rune.js +373 -410
  69. package/lib/rew/pkgs/threads.js +62 -66
  70. package/lib/rew/pkgs/ui.js +148 -160
  71. package/lib/rew/qrew/compile.js +12 -0
  72. package/package.json +4 -3
@@ -1,2496 +1,1930 @@
1
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.
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
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`.
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
18
 
19
- // The only dependency is on the **Jison.Parser**.
20
- var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
19
+ // The only dependency is on the **Jison.Parser**.
20
+ var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
21
21
 
22
- ({Parser} = require('jison'));
22
+ ({ Parser } = require('jison'));
23
23
 
24
- // Jison DSL
25
- // ---------
24
+ // Jison DSL
25
+ // ---------
26
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*\}/;
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
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`.
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
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
- };
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
90
 
91
- // Grammatical Rules
92
- // -----------------
91
+ // Grammatical Rules
92
+ // -----------------
93
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:
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
98
 
99
- // 'Expression UNLESS Expression'
99
+ // 'Expression UNLESS Expression'
100
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
- };
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
+ };
2439
1847
 
2440
- // Precedence
2441
- // ----------
1848
+ // Precedence
1849
+ // ----------
2442
1850
 
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:
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:
2445
1853
 
2446
- // 2 + (3 * 4)
1854
+ // 2 + (3 * 4)
2447
1855
 
2448
- // And not:
1856
+ // And not:
2449
1857
 
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']];
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
+ ];
2452
1887
 
2453
- // Wrapping Up
2454
- // -----------
1888
+ // Wrapping Up
1889
+ // -----------
2455
1890
 
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 = [];
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 = [];
2461
1896
 
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
- });
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
+ }
2495
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
+ });
2496
1930
  }).call(this);