@bablr/language-en-es6 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/grammar.js +288 -96
- package/lib/mixins/class.js +53 -56
- package/lib/mixins/function.js +150 -96
- package/lib/mixins/import.js +68 -70
- package/lib/mixins/string.js +120 -0
- package/lib/regex.js +1 -1
- package/package.json +14 -14
- package/lib/grammar.macro.js +0 -155
- package/lib/mixins/class.macro.js +0 -92
- package/lib/mixins/function.macro.js +0 -144
- package/lib/mixins/import.macro.js +0 -160
package/lib/grammar.js
CHANGED
|
@@ -1,139 +1,331 @@
|
|
|
1
|
-
/* @macrome
|
|
2
|
-
* @generatedby @bablr/macrome-generator-bablr
|
|
3
|
-
* @generatedfrom ./grammar.macro.js#6042f078b7b381cf1100801b2c61981b32f17fc0
|
|
4
|
-
* This file is autogenerated. Please do not edit it directly.
|
|
5
|
-
* When editing run `npx macrome watch` then change the file this is generated from.
|
|
6
|
-
*/
|
|
7
|
-
import _applyDecs from "@babel/runtime/helpers/applyDecs2305";
|
|
8
|
-
var _importMixin;
|
|
9
|
-
let _initProto, _VariableDeclarationStatementDecs, _ForStatementDecs;
|
|
10
1
|
import { re, spam as m } from '@bablr/boot';
|
|
11
|
-
import {
|
|
12
|
-
|
|
2
|
+
import {
|
|
3
|
+
eat,
|
|
4
|
+
eatMatch,
|
|
5
|
+
shiftMatch,
|
|
6
|
+
match,
|
|
7
|
+
o,
|
|
8
|
+
r,
|
|
9
|
+
shift,
|
|
10
|
+
getInstrMatcher,
|
|
11
|
+
eatHeld,
|
|
12
|
+
} from '@bablr/helpers/grammar';
|
|
13
13
|
import { triviaEnhancer } from '@bablr/helpers/trivia';
|
|
14
|
-
import * as
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
|
|
14
|
+
import * as BTree from '@bablr/agast-helpers/btree';
|
|
15
|
+
import Space from '@bablr/language-en-blank-space';
|
|
16
|
+
import Comment from '@bablr/language-en-c-comments';
|
|
17
|
+
import {
|
|
18
|
+
default as es5,
|
|
19
|
+
reservedWords,
|
|
20
|
+
unaryPrefixOperatorAlternatives,
|
|
21
|
+
} from '@bablr/language-en-es5';
|
|
22
|
+
import classMixin from './mixins/class.js';
|
|
23
|
+
import importMixin from './mixins/import.js';
|
|
24
|
+
import functionMixin from './mixins/function.js';
|
|
25
|
+
import stringMixin from './mixins/string.js';
|
|
19
26
|
import { buildPattern } from '@bablr/helpers/builders';
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
27
|
+
import Regex from './regex.js';
|
|
28
|
+
import { getRoot, printSource } from '@bablr/agast-helpers/tree';
|
|
29
|
+
import { reifyMatcherReferenceName } from '@bablr/agast-vm-helpers';
|
|
30
|
+
import { Coroutine } from '@bablr/coroutine';
|
|
31
|
+
|
|
32
|
+
export const dependencies = { Comment, Space, Regex };
|
|
33
|
+
|
|
34
|
+
let runCo = (generator) => new Coroutine(generator).advance();
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
powerLevels,
|
|
38
|
+
reservedWords,
|
|
39
|
+
assignmentOperators,
|
|
40
|
+
assignmentOperatorAlternatives,
|
|
41
|
+
unaryPrefixOperators,
|
|
42
|
+
unaryPrefixOperatorAlternatives,
|
|
43
|
+
unaryPostfixOperators,
|
|
44
|
+
unaryPostfixOperatorAlternatives,
|
|
45
|
+
getBinaryOperatorAlternatives,
|
|
46
|
+
} from '@bablr/language-en-es5';
|
|
47
|
+
|
|
48
|
+
let reservedWords_ = new Set(reservedWords);
|
|
49
|
+
|
|
25
50
|
export const canonicalURL = 'https://bablr.org/languages/universe/es6';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
|
|
52
|
+
export const defaultMatcher = m`_+: <_Expression />`;
|
|
53
|
+
|
|
54
|
+
let unaryMatcher;
|
|
55
|
+
|
|
56
|
+
const atrivial = class ES6Grammar extends importMixin(
|
|
57
|
+
classMixin(functionMixin(stringMixin(es5.grammar.atrivial))),
|
|
58
|
+
) {
|
|
59
|
+
constructor() {
|
|
60
|
+
super();
|
|
61
|
+
this.emptyables = new Set([...(this.emptyables || []), 'Statement']);
|
|
33
62
|
}
|
|
34
|
-
|
|
63
|
+
|
|
64
|
+
*Expression(args) {
|
|
35
65
|
let {
|
|
36
|
-
props: {
|
|
37
|
-
|
|
38
|
-
noIn = false
|
|
39
|
-
},
|
|
40
|
-
s
|
|
66
|
+
props: { power = 34, noIn = false },
|
|
67
|
+
getState,
|
|
41
68
|
} = args;
|
|
69
|
+
let s = getState();
|
|
70
|
+
let yieldPower = 0; // TODO fixme
|
|
71
|
+
|
|
72
|
+
let sigil;
|
|
42
73
|
let res;
|
|
43
74
|
if (!s.holding) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
sigil = yield match(
|
|
76
|
+
re`/[\u0060({['"/\d]|(?:yield|function|class|super|new|this|true|false|null|Infinity|NaN)\b/`,
|
|
77
|
+
);
|
|
78
|
+
switch (printSource(sigil)) {
|
|
79
|
+
case '`':
|
|
80
|
+
res = yield eat(m`<TemplateString />`);
|
|
81
|
+
break;
|
|
82
|
+
case '/':
|
|
83
|
+
res = yield eat(m`:Regex: <Pattern />`);
|
|
84
|
+
break;
|
|
85
|
+
case '(':
|
|
86
|
+
if ((res = yield eatMatch(m`<ArrowFunctionExpression />`))) {
|
|
87
|
+
} else {
|
|
88
|
+
res = yield eat(m`<ParenthesisExpression />`);
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case 'yield':
|
|
92
|
+
if (power > yieldPower) {
|
|
93
|
+
res = yield eatMatch(m`<YieldExpression />`);
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
case 'function':
|
|
97
|
+
res = yield eat(m`<FunctionExpression />`);
|
|
98
|
+
break;
|
|
99
|
+
case 'class':
|
|
100
|
+
res = yield eat(m`<ClassExpression />`);
|
|
101
|
+
break;
|
|
102
|
+
case 'super':
|
|
103
|
+
res = yield eat(m`<SuperExpression />`);
|
|
104
|
+
break;
|
|
105
|
+
case 'true':
|
|
106
|
+
case 'false':
|
|
107
|
+
case 'null':
|
|
108
|
+
case 'Infinity':
|
|
109
|
+
case 'NaN':
|
|
110
|
+
case '[':
|
|
111
|
+
case '{':
|
|
112
|
+
case '"':
|
|
113
|
+
case "'":
|
|
114
|
+
case '0':
|
|
115
|
+
case '1':
|
|
116
|
+
case '2':
|
|
117
|
+
case '3':
|
|
118
|
+
case '4':
|
|
119
|
+
case '5':
|
|
120
|
+
case '6':
|
|
121
|
+
case '7':
|
|
122
|
+
case '8':
|
|
123
|
+
case '9':
|
|
124
|
+
res = yield eat(m`<_JSONExpression />`);
|
|
125
|
+
break;
|
|
126
|
+
|
|
127
|
+
case 'new':
|
|
128
|
+
if (power >= 4) {
|
|
129
|
+
res = yield eatMatch(m`<NewExpression />`, o({ power }));
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case 'this':
|
|
134
|
+
res = yield eatMatch(m`<ThisExpression />`, o({ power }));
|
|
135
|
+
break;
|
|
136
|
+
|
|
137
|
+
default: {
|
|
138
|
+
if (
|
|
139
|
+
power >= 4 &&
|
|
140
|
+
(res = yield eatMatch(
|
|
141
|
+
(unaryMatcher ??= m`<UnaryExpression ${buildPattern(
|
|
142
|
+
unaryPrefixOperatorAlternatives,
|
|
143
|
+
)} />`),
|
|
144
|
+
))
|
|
145
|
+
) {
|
|
146
|
+
} else {
|
|
147
|
+
res = yield eat(m`<Identifier />`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
53
150
|
}
|
|
151
|
+
} else if ((res = yield eatMatch(m`<TemplateString '\u0060' />`))) {
|
|
152
|
+
} else {
|
|
153
|
+
res = yield eat(m`<_LogicExpression />`, o({ power, noIn }));
|
|
54
154
|
}
|
|
55
155
|
if (res) {
|
|
56
|
-
return shiftMatch(m`<
|
|
57
|
-
power
|
|
58
|
-
}));
|
|
156
|
+
return r(shiftMatch(m`<_Expression />`, o({ power })));
|
|
59
157
|
}
|
|
60
158
|
}
|
|
159
|
+
|
|
61
160
|
*Statement(args) {
|
|
62
|
-
|
|
63
|
-
|
|
161
|
+
let res = yield match(re`/import|export|class|var|const|let/`);
|
|
162
|
+
switch (printSource(res)) {
|
|
163
|
+
case 'import':
|
|
164
|
+
yield eat(m`<ImportDeclaration />`);
|
|
165
|
+
break;
|
|
166
|
+
case 'export':
|
|
167
|
+
yield eat(m`<ExportDeclaration />`);
|
|
168
|
+
break;
|
|
169
|
+
case 'class':
|
|
170
|
+
yield eat(m`<ClassDeclaration />`);
|
|
171
|
+
break;
|
|
172
|
+
case 'var':
|
|
173
|
+
case 'const':
|
|
174
|
+
case 'let':
|
|
175
|
+
yield eat(m`<VariableDeclaration />`);
|
|
176
|
+
break;
|
|
177
|
+
default:
|
|
178
|
+
yield* super.Statement(args);
|
|
64
179
|
}
|
|
65
180
|
}
|
|
181
|
+
|
|
66
182
|
*JSONExpression(args) {
|
|
67
|
-
if (yield eatMatch(m`<ClassExpression 'class' />`)) {
|
|
183
|
+
if (yield eatMatch(m`<ClassExpression 'class' />`)) {
|
|
184
|
+
} else if (yield eatMatch(m`<ThisExpression 'this' />`)) {
|
|
185
|
+
} else if (yield eatMatch(m`<SuperExpression 'super' />`)) {
|
|
186
|
+
} else if (yield eatMatch(m`<ArrowFunctionExpression '(' />`)) {
|
|
187
|
+
} else {
|
|
68
188
|
yield* super.JSONExpression(args);
|
|
69
189
|
}
|
|
70
190
|
}
|
|
71
|
-
|
|
72
|
-
|
|
191
|
+
|
|
192
|
+
*VariableDeclaration() {
|
|
193
|
+
yield eat(m`sigilToken*: <*Keyword /var|const|let/ />`);
|
|
194
|
+
|
|
73
195
|
let sep = true;
|
|
74
196
|
while (sep) {
|
|
75
|
-
yield eatMatch(m`declarations[]
|
|
76
|
-
sep = yield eatMatch(m
|
|
197
|
+
yield eatMatch(m`declarations[]*: <VariableDeclarator />`);
|
|
198
|
+
sep = yield eatMatch(m`#separatorTokens: <* ',' />`);
|
|
77
199
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}));
|
|
200
|
+
|
|
201
|
+
yield eatMatch(m`endToken*: <* ';' />`);
|
|
81
202
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
yield eat(m`
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
yield eatMatch(m`init+$: <__Expression />`, o({
|
|
89
|
-
noIn: true
|
|
90
|
-
}));
|
|
203
|
+
|
|
204
|
+
*For() {
|
|
205
|
+
yield eat(m`sigilToken*: <*Keyword 'for' />`);
|
|
206
|
+
yield eat(m`openHeaderToken*: <* '(' />`);
|
|
207
|
+
if (!(yield eatMatch(m`init+$: <VariableDeclaration />`, o({ noSemi: true })))) {
|
|
208
|
+
yield eatMatch(m`init+$: <_Expression />`, o({ noIn: true }));
|
|
91
209
|
}
|
|
92
|
-
let source = yield eatMatch(m`inToken
|
|
93
|
-
bind: true
|
|
94
|
-
}));
|
|
210
|
+
let source = yield eatMatch(m`inToken*: <*Keyword /in|of/ />`);
|
|
95
211
|
if (source) {
|
|
96
|
-
yield eatMatch(m`source+$: <
|
|
212
|
+
yield eatMatch(m`source+$: <_Expression />`);
|
|
97
213
|
} else {
|
|
98
|
-
yield eat(m`testSeparatorToken
|
|
99
|
-
yield eatMatch(m`test+$: <
|
|
100
|
-
yield eat(m`updateSeparatorToken
|
|
101
|
-
yield eatMatch(m`update+$: <
|
|
214
|
+
yield eat(m`testSeparatorToken*: <* ';' />`);
|
|
215
|
+
yield eatMatch(m`test+$: <_Expression />`);
|
|
216
|
+
yield eat(m`updateSeparatorToken*: <* ';' />`);
|
|
217
|
+
yield eatMatch(m`update+$: <_Expression />`);
|
|
102
218
|
}
|
|
103
|
-
yield eat(m`closeHeaderToken
|
|
104
|
-
yield eat(m`body
|
|
219
|
+
yield eat(m`closeHeaderToken*: <* ')' />`);
|
|
220
|
+
yield eat(m`body*: <_Statement />`);
|
|
105
221
|
}
|
|
222
|
+
|
|
106
223
|
*VariableDeclarator() {
|
|
107
224
|
if (yield match('{')) {
|
|
108
|
-
yield eat(m`
|
|
225
|
+
yield eat(m`receiver*: <ObjectPattern />`);
|
|
109
226
|
} else {
|
|
110
|
-
yield eat(m`
|
|
227
|
+
yield eat(m`receiver*: <Identifier />`);
|
|
111
228
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
yield eat(m`
|
|
115
|
-
|
|
116
|
-
}));
|
|
229
|
+
|
|
230
|
+
if (yield match('=')) {
|
|
231
|
+
yield eat(m`assignmentToken*: <* '=' />`);
|
|
232
|
+
yield eat(m`value+$: <_Expression />`, o({ power: 32 }));
|
|
117
233
|
} else {
|
|
118
|
-
yield eat(m`assignmentOperator: null`);
|
|
119
234
|
yield eat(m`value+$: null`);
|
|
120
235
|
}
|
|
121
236
|
}
|
|
237
|
+
|
|
238
|
+
*ObjectKey() {
|
|
239
|
+
if (yield eatMatch(m`<String /['"]/ />`)) {
|
|
240
|
+
} else if (yield eatMatch(m`<UnsignedInteger /\d/ />`)) {
|
|
241
|
+
} else if (yield eatMatch(m`<ComputedObjectKey '[' />`)) {
|
|
242
|
+
} else {
|
|
243
|
+
yield eat(m`<Identifier />`, o({ scoped: false }));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
*ComputedObjectKey() {
|
|
248
|
+
yield eat(m`openToken*: <* '[' />`);
|
|
249
|
+
yield eat(m`name+$: <_Expression />`);
|
|
250
|
+
yield eat(m`closeToken*: <* ']' />`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
*Method(args) {
|
|
254
|
+
let asyncToken = yield match('async');
|
|
255
|
+
let isSyncMethod = yield match(m`isSyncMethod*: <All />`, [(m`<* 'async' />`, m`<* '(' />`)]);
|
|
256
|
+
|
|
257
|
+
if (!asyncToken || !isSyncMethod) {
|
|
258
|
+
yield* super.Method(args);
|
|
259
|
+
} else {
|
|
260
|
+
let co = runCo(super.Method(args));
|
|
261
|
+
while (!co.done) {
|
|
262
|
+
let instr = co.value;
|
|
263
|
+
let refName = reifyMatcherReferenceName(getInstrMatcher(instr));
|
|
264
|
+
if (refName === 'asyncToken') {
|
|
265
|
+
co.advance(null);
|
|
266
|
+
} else {
|
|
267
|
+
co.advance(yield instr);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
*ObjectElement({ s }) {
|
|
274
|
+
if (s().held) {
|
|
275
|
+
if (yield eatMatch(m`<Property ':' />`)) {
|
|
276
|
+
} else {
|
|
277
|
+
yield eatMatch(m`<Method '(' />`);
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
let asyncToken = yield match('async');
|
|
281
|
+
let isAsyncMethod =
|
|
282
|
+
asyncToken && !(yield match(m`<All />`, [(m`<* 'async' />`, m`<* /[(:]/ />`)]));
|
|
283
|
+
|
|
284
|
+
if (isAsyncMethod) {
|
|
285
|
+
yield eat(m`<Method />`);
|
|
286
|
+
} else {
|
|
287
|
+
yield eat(m`<_ObjectKey />`);
|
|
288
|
+
|
|
289
|
+
return r(shift(m`<_ObjectElement />`));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
122
294
|
*Property() {
|
|
123
|
-
yield
|
|
124
|
-
let
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
295
|
+
let key = yield eatHeld(m`key: <_ObjectKey />`);
|
|
296
|
+
let firstToken = printSource(BTree.getAt(-2, getRoot(key.node).value.bounds[0]).value.node);
|
|
297
|
+
let isIndex = /\d/.test(firstToken[0]);
|
|
298
|
+
let isComputed = firstToken === '[';
|
|
299
|
+
|
|
300
|
+
let cn =
|
|
301
|
+
isIndex || isComputed || reservedWords_.has(printSource(key.node))
|
|
302
|
+
? yield eat(m`mapOperator*: <* ':' />`)
|
|
303
|
+
: yield eatMatch(m`mapOperator*: <* ':' />`);
|
|
304
|
+
if (cn) {
|
|
305
|
+
yield eat(m`value+$: <_Expression />`, o({ power: 32 }));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
*Element() {
|
|
310
|
+
if (yield eatMatch(m`<SpreadElement '...' />`)) {
|
|
131
311
|
} else {
|
|
132
|
-
yield eat(m
|
|
312
|
+
let { value } = yield eat(m`<_Expression />`, o({ power: 32 }), o({ shift: false }));
|
|
313
|
+
return value;
|
|
133
314
|
}
|
|
134
315
|
}
|
|
316
|
+
|
|
317
|
+
*SpreadElement() {
|
|
318
|
+
yield eat(m`sigilToken*: <* '...' />`);
|
|
319
|
+
yield eat(m`value+$: <_Expression />`, o({ power: 32 }));
|
|
320
|
+
}
|
|
135
321
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
322
|
+
|
|
323
|
+
export const grammar = triviaEnhancer(
|
|
324
|
+
{
|
|
325
|
+
triviaIsAllowed: (s) => s.span === 'Bare',
|
|
326
|
+
triviaMatcher: m`#: <__Trivia /[ \n\r\t]|\/\/|\/\*/ />`,
|
|
327
|
+
},
|
|
328
|
+
atrivial,
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
export default { canonicalURL, dependencies, grammar, defaultMatcher };
|
package/lib/mixins/class.js
CHANGED
|
@@ -1,82 +1,79 @@
|
|
|
1
|
-
/* @macrome
|
|
2
|
-
* @generatedby @bablr/macrome-generator-bablr
|
|
3
|
-
* @generatedfrom ./class.macro.js#4e159ba9b4b2272a008a11039caf5d564355a414
|
|
4
|
-
* This file is autogenerated. Please do not edit it directly.
|
|
5
|
-
* When editing run `npx macrome watch` then change the file this is generated from.
|
|
6
|
-
*/
|
|
7
|
-
import _applyDecs from "@babel/runtime/helpers/applyDecs2305";
|
|
8
1
|
import { spam as m } from '@bablr/boot';
|
|
9
|
-
import { CoveredBy, Node } from '@bablr/helpers/decorators';
|
|
10
2
|
import { o, eat, eatMatch, fail } from '@bablr/helpers/grammar';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
super(...args);
|
|
19
|
-
_initProto(this);
|
|
20
|
-
}
|
|
21
|
-
*[(_ClassExpressionDecs = [CoveredBy('Expression'), Node], _ClassMethodDecs = [CoveredBy('ClassMember'), Node], _SuperExpressionDecs = [CoveredBy('Expression'), Node], _ThisExpressionDecs = [CoveredBy('Expression'), Node], "ClassDeclaration")]() {
|
|
22
|
-
yield eat(m`sigilToken: <*Keyword 'class' />`);
|
|
3
|
+
import { List } from '@bablr/helpers/productions';
|
|
4
|
+
|
|
5
|
+
const mixin = (Base) =>
|
|
6
|
+
class ES6ClassGrammar extends Base {
|
|
7
|
+
*ClassDeclaration() {
|
|
8
|
+
yield eat(m`sigilToken*: <*Keyword 'class' />`);
|
|
9
|
+
|
|
23
10
|
yield eat(m`name$: <Identifier />`);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
yield eat(m`superClass$: <__Expression>`);
|
|
11
|
+
|
|
12
|
+
if (yield eatMatch(m`extendsToken*: <*Keyword 'extends' />`)) {
|
|
13
|
+
yield eat(m`superClass+$: <_Expression />`);
|
|
28
14
|
} else {
|
|
29
|
-
yield eat(m`superClass
|
|
15
|
+
yield eat(m`superClass+$: null`);
|
|
30
16
|
}
|
|
31
|
-
|
|
17
|
+
|
|
18
|
+
yield eat(m`body$: <ClassBody />`);
|
|
32
19
|
}
|
|
20
|
+
|
|
33
21
|
*ClassExpression() {
|
|
34
|
-
yield eat(m`sigilToken
|
|
22
|
+
yield eat(m`sigilToken*: <*Keyword 'class' />`);
|
|
23
|
+
|
|
35
24
|
yield eatMatch(m`name$: <Identifier />`);
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
|
|
26
|
+
if (yield eatMatch(m`extendsToken*: <*Keyword 'extends' />`)) {
|
|
27
|
+
yield eat(m`superClass+$: <_Expression />`);
|
|
38
28
|
} else {
|
|
39
|
-
yield eat(m`superClass
|
|
29
|
+
yield eat(m`superClass+$: null`);
|
|
40
30
|
}
|
|
41
|
-
|
|
31
|
+
|
|
32
|
+
yield eat(m`body$: <ClassBody />`);
|
|
42
33
|
}
|
|
34
|
+
|
|
43
35
|
*ClassBody() {
|
|
44
|
-
yield eat(m`openToken
|
|
45
|
-
while (yield eatMatch(m`members[]
|
|
46
|
-
yield eat(m`closeToken
|
|
36
|
+
yield eat(m`openToken*: <* '{' />`);
|
|
37
|
+
while (yield eatMatch(m`members[]$: <_ClassMember />`)) {}
|
|
38
|
+
yield eat(m`closeToken*: <* '}' />`);
|
|
47
39
|
}
|
|
40
|
+
|
|
48
41
|
*ClassMember() {
|
|
49
42
|
yield eat(m`<ClassMethod />`);
|
|
50
43
|
}
|
|
44
|
+
|
|
51
45
|
*ClassMethod() {
|
|
52
|
-
yield eatMatch(m`staticToken
|
|
46
|
+
yield eatMatch(m`staticToken*: <*Keyword 'static' />`);
|
|
53
47
|
let acc, a, gen;
|
|
54
|
-
acc = yield eatMatch(m`kindToken
|
|
48
|
+
acc = yield eatMatch(m`kindToken*: <*Keyword /get|set/ />`);
|
|
49
|
+
|
|
55
50
|
if (!acc) {
|
|
56
|
-
a = yield eatMatch(m`asyncToken
|
|
57
|
-
gen = yield eatMatch(m`starToken
|
|
58
|
-
} else {
|
|
59
|
-
yield eatMatch(m`asyncToken: null`);
|
|
60
|
-
yield eatMatch(m`starToken: null`);
|
|
51
|
+
a = yield eatMatch(m`asyncToken*: <*Keyword 'async' />`);
|
|
52
|
+
gen = yield eatMatch(m`starToken*: <* '*' />`);
|
|
61
53
|
}
|
|
54
|
+
|
|
62
55
|
if (a && gen) yield fail();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
|
|
57
|
+
if (yield eatMatch(m`openNameToken*: <* '[' />`)) {
|
|
58
|
+
yield eat(m`name+$: <_Expression />`);
|
|
59
|
+
yield eat(m`closeNameToken*: <* ']' />`);
|
|
60
|
+
} else {
|
|
61
|
+
yield eatMatch(m`name+$: <Identifier />`, o({}), o({ bind: true }));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
yield eat(m`openParamsToken*: <* '(' />`);
|
|
65
|
+
yield* List({
|
|
66
|
+
element: m`params[]+$: <_CapturePattern />`,
|
|
69
67
|
allowTrailingSeparator: false,
|
|
70
|
-
separator: m
|
|
71
|
-
})
|
|
72
|
-
yield eat(m`closeParamsToken
|
|
73
|
-
yield eat(m`body
|
|
68
|
+
separator: m`#separatorTokens: <* ',' />`,
|
|
69
|
+
});
|
|
70
|
+
yield eat(m`closeParamsToken*: <* ')' />`);
|
|
71
|
+
yield eat(m`body$: <Block />`);
|
|
74
72
|
}
|
|
73
|
+
|
|
75
74
|
*SuperExpression() {
|
|
76
|
-
yield eat(m`sigilToken
|
|
77
|
-
}
|
|
78
|
-
*ThisExpression() {
|
|
79
|
-
yield eat(m`sigilToken: <*Keyword 'this' />`);
|
|
75
|
+
yield eat(m`sigilToken*: <*Keyword 'super' />`);
|
|
80
76
|
}
|
|
81
77
|
};
|
|
82
|
-
|
|
78
|
+
|
|
79
|
+
export default mixin;
|