Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50663 views
1
// Generated by CoffeeScript 1.12.6
2
(function() {
3
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
4
5
Parser = require('jison').Parser;
6
7
unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
8
9
o = function(patternString, action, options) {
10
var addLocationDataFn, match, patternCount;
11
patternString = patternString.replace(/\s{2,}/g, ' ');
12
patternCount = patternString.split(' ').length;
13
if (!action) {
14
return [patternString, '$$ = $1;', options];
15
}
16
action = (match = unwrap.exec(action)) ? match[1] : "(" + action + "())";
17
action = action.replace(/\bnew /g, '$&yy.');
18
action = action.replace(/\b(?:Block\.wrap|extend)\b/g, 'yy.$&');
19
addLocationDataFn = function(first, last) {
20
if (!last) {
21
return "yy.addLocationDataFn(@" + first + ")";
22
} else {
23
return "yy.addLocationDataFn(@" + first + ", @" + last + ")";
24
}
25
};
26
action = action.replace(/LOC\(([0-9]*)\)/g, addLocationDataFn('$1'));
27
action = action.replace(/LOC\(([0-9]*),\s*([0-9]*)\)/g, addLocationDataFn('$1', '$2'));
28
return [patternString, "$$ = " + (addLocationDataFn(1, patternCount)) + "(" + action + ");", options];
29
};
30
31
grammar = {
32
Root: [
33
o('', function() {
34
return new Block;
35
}), o('Body')
36
],
37
Body: [
38
o('Line', function() {
39
return Block.wrap([$1]);
40
}), o('Body TERMINATOR Line', function() {
41
return $1.push($3);
42
}), o('Body TERMINATOR')
43
],
44
Line: [o('Expression'), o('Statement'), o('YieldReturn')],
45
Statement: [
46
o('Return'), o('Comment'), o('STATEMENT', function() {
47
return new StatementLiteral($1);
48
}), o('Import'), o('Export')
49
],
50
Expression: [o('Value'), o('Invocation'), o('Code'), o('Operation'), o('Assign'), o('If'), o('Try'), o('While'), o('For'), o('Switch'), o('Class'), o('Throw'), o('Yield')],
51
Yield: [
52
o('YIELD', function() {
53
return new Op($1, new Value(new Literal('')));
54
}), o('YIELD Expression', function() {
55
return new Op($1, $2);
56
}), o('YIELD FROM Expression', function() {
57
return new Op($1.concat($2), $3);
58
})
59
],
60
Block: [
61
o('INDENT OUTDENT', function() {
62
return new Block;
63
}), o('INDENT Body OUTDENT', function() {
64
return $2;
65
})
66
],
67
Identifier: [
68
o('IDENTIFIER', function() {
69
return new IdentifierLiteral($1);
70
})
71
],
72
Property: [
73
o('PROPERTY', function() {
74
return new PropertyName($1);
75
})
76
],
77
AlphaNumeric: [
78
o('NUMBER', function() {
79
return new NumberLiteral($1);
80
}), o('String')
81
],
82
String: [
83
o('STRING', function() {
84
return new StringLiteral($1);
85
}), o('STRING_START Body STRING_END', function() {
86
return new StringWithInterpolations($2);
87
})
88
],
89
Regex: [
90
o('REGEX', function() {
91
return new RegexLiteral($1);
92
}), o('REGEX_START Invocation REGEX_END', function() {
93
return new RegexWithInterpolations($2.args);
94
})
95
],
96
Literal: [
97
o('AlphaNumeric'), o('JS', function() {
98
return new PassthroughLiteral($1);
99
}), o('Regex'), o('UNDEFINED', function() {
100
return new UndefinedLiteral;
101
}), o('NULL', function() {
102
return new NullLiteral;
103
}), o('BOOL', function() {
104
return new BooleanLiteral($1);
105
}), o('INFINITY', function() {
106
return new InfinityLiteral($1);
107
}), o('NAN', function() {
108
return new NaNLiteral;
109
})
110
],
111
Assign: [
112
o('Assignable = Expression', function() {
113
return new Assign($1, $3);
114
}), o('Assignable = TERMINATOR Expression', function() {
115
return new Assign($1, $4);
116
}), o('Assignable = INDENT Expression OUTDENT', function() {
117
return new Assign($1, $4);
118
})
119
],
120
AssignObj: [
121
o('ObjAssignable', function() {
122
return new Value($1);
123
}), o('ObjAssignable : Expression', function() {
124
return new Assign(LOC(1)(new Value($1)), $3, 'object', {
125
operatorToken: LOC(2)(new Literal($2))
126
});
127
}), o('ObjAssignable : INDENT Expression OUTDENT', function() {
128
return new Assign(LOC(1)(new Value($1)), $4, 'object', {
129
operatorToken: LOC(2)(new Literal($2))
130
});
131
}), o('SimpleObjAssignable = Expression', function() {
132
return new Assign(LOC(1)(new Value($1)), $3, null, {
133
operatorToken: LOC(2)(new Literal($2))
134
});
135
}), o('SimpleObjAssignable = INDENT Expression OUTDENT', function() {
136
return new Assign(LOC(1)(new Value($1)), $4, null, {
137
operatorToken: LOC(2)(new Literal($2))
138
});
139
}), o('Comment')
140
],
141
SimpleObjAssignable: [o('Identifier'), o('Property'), o('ThisProperty')],
142
ObjAssignable: [o('SimpleObjAssignable'), o('AlphaNumeric')],
143
Return: [
144
o('RETURN Expression', function() {
145
return new Return($2);
146
}), o('RETURN', function() {
147
return new Return;
148
})
149
],
150
YieldReturn: [
151
o('YIELD RETURN Expression', function() {
152
return new YieldReturn($3);
153
}), o('YIELD RETURN', function() {
154
return new YieldReturn;
155
})
156
],
157
Comment: [
158
o('HERECOMMENT', function() {
159
return new Comment($1);
160
})
161
],
162
Code: [
163
o('PARAM_START ParamList PARAM_END FuncGlyph Block', function() {
164
return new Code($2, $5, $4);
165
}), o('FuncGlyph Block', function() {
166
return new Code([], $2, $1);
167
})
168
],
169
FuncGlyph: [
170
o('->', function() {
171
return 'func';
172
}), o('=>', function() {
173
return 'boundfunc';
174
})
175
],
176
OptComma: [o(''), o(',')],
177
ParamList: [
178
o('', function() {
179
return [];
180
}), o('Param', function() {
181
return [$1];
182
}), o('ParamList , Param', function() {
183
return $1.concat($3);
184
}), o('ParamList OptComma TERMINATOR Param', function() {
185
return $1.concat($4);
186
}), o('ParamList OptComma INDENT ParamList OptComma OUTDENT', function() {
187
return $1.concat($4);
188
})
189
],
190
Param: [
191
o('ParamVar', function() {
192
return new Param($1);
193
}), o('ParamVar ...', function() {
194
return new Param($1, null, true);
195
}), o('ParamVar = Expression', function() {
196
return new Param($1, $3);
197
}), o('...', function() {
198
return new Expansion;
199
})
200
],
201
ParamVar: [o('Identifier'), o('ThisProperty'), o('Array'), o('Object')],
202
Splat: [
203
o('Expression ...', function() {
204
return new Splat($1);
205
})
206
],
207
SimpleAssignable: [
208
o('Identifier', function() {
209
return new Value($1);
210
}), o('Value Accessor', function() {
211
return $1.add($2);
212
}), o('Invocation Accessor', function() {
213
return new Value($1, [].concat($2));
214
}), o('ThisProperty')
215
],
216
Assignable: [
217
o('SimpleAssignable'), o('Array', function() {
218
return new Value($1);
219
}), o('Object', function() {
220
return new Value($1);
221
})
222
],
223
Value: [
224
o('Assignable'), o('Literal', function() {
225
return new Value($1);
226
}), o('Parenthetical', function() {
227
return new Value($1);
228
}), o('Range', function() {
229
return new Value($1);
230
}), o('This')
231
],
232
Accessor: [
233
o('. Property', function() {
234
return new Access($2);
235
}), o('?. Property', function() {
236
return new Access($2, 'soak');
237
}), o(':: Property', function() {
238
return [LOC(1)(new Access(new PropertyName('prototype'))), LOC(2)(new Access($2))];
239
}), o('?:: Property', function() {
240
return [LOC(1)(new Access(new PropertyName('prototype'), 'soak')), LOC(2)(new Access($2))];
241
}), o('::', function() {
242
return new Access(new PropertyName('prototype'));
243
}), o('Index')
244
],
245
Index: [
246
o('INDEX_START IndexValue INDEX_END', function() {
247
return $2;
248
}), o('INDEX_SOAK Index', function() {
249
return extend($2, {
250
soak: true
251
});
252
})
253
],
254
IndexValue: [
255
o('Expression', function() {
256
return new Index($1);
257
}), o('Slice', function() {
258
return new Slice($1);
259
})
260
],
261
Object: [
262
o('{ AssignList OptComma }', function() {
263
return new Obj($2, $1.generated);
264
})
265
],
266
AssignList: [
267
o('', function() {
268
return [];
269
}), o('AssignObj', function() {
270
return [$1];
271
}), o('AssignList , AssignObj', function() {
272
return $1.concat($3);
273
}), o('AssignList OptComma TERMINATOR AssignObj', function() {
274
return $1.concat($4);
275
}), o('AssignList OptComma INDENT AssignList OptComma OUTDENT', function() {
276
return $1.concat($4);
277
})
278
],
279
Class: [
280
o('CLASS', function() {
281
return new Class;
282
}), o('CLASS Block', function() {
283
return new Class(null, null, $2);
284
}), o('CLASS EXTENDS Expression', function() {
285
return new Class(null, $3);
286
}), o('CLASS EXTENDS Expression Block', function() {
287
return new Class(null, $3, $4);
288
}), o('CLASS SimpleAssignable', function() {
289
return new Class($2);
290
}), o('CLASS SimpleAssignable Block', function() {
291
return new Class($2, null, $3);
292
}), o('CLASS SimpleAssignable EXTENDS Expression', function() {
293
return new Class($2, $4);
294
}), o('CLASS SimpleAssignable EXTENDS Expression Block', function() {
295
return new Class($2, $4, $5);
296
})
297
],
298
Import: [
299
o('IMPORT String', function() {
300
return new ImportDeclaration(null, $2);
301
}), o('IMPORT ImportDefaultSpecifier FROM String', function() {
302
return new ImportDeclaration(new ImportClause($2, null), $4);
303
}), o('IMPORT ImportNamespaceSpecifier FROM String', function() {
304
return new ImportDeclaration(new ImportClause(null, $2), $4);
305
}), o('IMPORT { } FROM String', function() {
306
return new ImportDeclaration(new ImportClause(null, new ImportSpecifierList([])), $5);
307
}), o('IMPORT { ImportSpecifierList OptComma } FROM String', function() {
308
return new ImportDeclaration(new ImportClause(null, new ImportSpecifierList($3)), $7);
309
}), o('IMPORT ImportDefaultSpecifier , ImportNamespaceSpecifier FROM String', function() {
310
return new ImportDeclaration(new ImportClause($2, $4), $6);
311
}), o('IMPORT ImportDefaultSpecifier , { ImportSpecifierList OptComma } FROM String', function() {
312
return new ImportDeclaration(new ImportClause($2, new ImportSpecifierList($5)), $9);
313
})
314
],
315
ImportSpecifierList: [
316
o('ImportSpecifier', function() {
317
return [$1];
318
}), o('ImportSpecifierList , ImportSpecifier', function() {
319
return $1.concat($3);
320
}), o('ImportSpecifierList OptComma TERMINATOR ImportSpecifier', function() {
321
return $1.concat($4);
322
}), o('INDENT ImportSpecifierList OptComma OUTDENT', function() {
323
return $2;
324
}), o('ImportSpecifierList OptComma INDENT ImportSpecifierList OptComma OUTDENT', function() {
325
return $1.concat($4);
326
})
327
],
328
ImportSpecifier: [
329
o('Identifier', function() {
330
return new ImportSpecifier($1);
331
}), o('Identifier AS Identifier', function() {
332
return new ImportSpecifier($1, $3);
333
}), o('DEFAULT', function() {
334
return new ImportSpecifier(new Literal($1));
335
}), o('DEFAULT AS Identifier', function() {
336
return new ImportSpecifier(new Literal($1), $3);
337
})
338
],
339
ImportDefaultSpecifier: [
340
o('Identifier', function() {
341
return new ImportDefaultSpecifier($1);
342
})
343
],
344
ImportNamespaceSpecifier: [
345
o('IMPORT_ALL AS Identifier', function() {
346
return new ImportNamespaceSpecifier(new Literal($1), $3);
347
})
348
],
349
Export: [
350
o('EXPORT { }', function() {
351
return new ExportNamedDeclaration(new ExportSpecifierList([]));
352
}), o('EXPORT { ExportSpecifierList OptComma }', function() {
353
return new ExportNamedDeclaration(new ExportSpecifierList($3));
354
}), o('EXPORT Class', function() {
355
return new ExportNamedDeclaration($2);
356
}), o('EXPORT Identifier = Expression', function() {
357
return new ExportNamedDeclaration(new Assign($2, $4, null, {
358
moduleDeclaration: 'export'
359
}));
360
}), o('EXPORT Identifier = TERMINATOR Expression', function() {
361
return new ExportNamedDeclaration(new Assign($2, $5, null, {
362
moduleDeclaration: 'export'
363
}));
364
}), o('EXPORT Identifier = INDENT Expression OUTDENT', function() {
365
return new ExportNamedDeclaration(new Assign($2, $5, null, {
366
moduleDeclaration: 'export'
367
}));
368
}), o('EXPORT DEFAULT Expression', function() {
369
return new ExportDefaultDeclaration($3);
370
}), o('EXPORT EXPORT_ALL FROM String', function() {
371
return new ExportAllDeclaration(new Literal($2), $4);
372
}), o('EXPORT { ExportSpecifierList OptComma } FROM String', function() {
373
return new ExportNamedDeclaration(new ExportSpecifierList($3), $7);
374
})
375
],
376
ExportSpecifierList: [
377
o('ExportSpecifier', function() {
378
return [$1];
379
}), o('ExportSpecifierList , ExportSpecifier', function() {
380
return $1.concat($3);
381
}), o('ExportSpecifierList OptComma TERMINATOR ExportSpecifier', function() {
382
return $1.concat($4);
383
}), o('INDENT ExportSpecifierList OptComma OUTDENT', function() {
384
return $2;
385
}), o('ExportSpecifierList OptComma INDENT ExportSpecifierList OptComma OUTDENT', function() {
386
return $1.concat($4);
387
})
388
],
389
ExportSpecifier: [
390
o('Identifier', function() {
391
return new ExportSpecifier($1);
392
}), o('Identifier AS Identifier', function() {
393
return new ExportSpecifier($1, $3);
394
}), o('Identifier AS DEFAULT', function() {
395
return new ExportSpecifier($1, new Literal($3));
396
}), o('DEFAULT', function() {
397
return new ExportSpecifier(new Literal($1));
398
}), o('DEFAULT AS Identifier', function() {
399
return new ExportSpecifier(new Literal($1), $3);
400
})
401
],
402
Invocation: [
403
o('Value OptFuncExist String', function() {
404
return new TaggedTemplateCall($1, $3, $2);
405
}), o('Value OptFuncExist Arguments', function() {
406
return new Call($1, $3, $2);
407
}), o('Invocation OptFuncExist Arguments', function() {
408
return new Call($1, $3, $2);
409
}), o('Super')
410
],
411
Super: [
412
o('SUPER', function() {
413
return new SuperCall;
414
}), o('SUPER Arguments', function() {
415
return new SuperCall($2);
416
})
417
],
418
OptFuncExist: [
419
o('', function() {
420
return false;
421
}), o('FUNC_EXIST', function() {
422
return true;
423
})
424
],
425
Arguments: [
426
o('CALL_START CALL_END', function() {
427
return [];
428
}), o('CALL_START ArgList OptComma CALL_END', function() {
429
return $2;
430
})
431
],
432
This: [
433
o('THIS', function() {
434
return new Value(new ThisLiteral);
435
}), o('@', function() {
436
return new Value(new ThisLiteral);
437
})
438
],
439
ThisProperty: [
440
o('@ Property', function() {
441
return new Value(LOC(1)(new ThisLiteral), [LOC(2)(new Access($2))], 'this');
442
})
443
],
444
Array: [
445
o('[ ]', function() {
446
return new Arr([]);
447
}), o('[ ArgList OptComma ]', function() {
448
return new Arr($2);
449
})
450
],
451
RangeDots: [
452
o('..', function() {
453
return 'inclusive';
454
}), o('...', function() {
455
return 'exclusive';
456
})
457
],
458
Range: [
459
o('[ Expression RangeDots Expression ]', function() {
460
return new Range($2, $4, $3);
461
})
462
],
463
Slice: [
464
o('Expression RangeDots Expression', function() {
465
return new Range($1, $3, $2);
466
}), o('Expression RangeDots', function() {
467
return new Range($1, null, $2);
468
}), o('RangeDots Expression', function() {
469
return new Range(null, $2, $1);
470
}), o('RangeDots', function() {
471
return new Range(null, null, $1);
472
})
473
],
474
ArgList: [
475
o('Arg', function() {
476
return [$1];
477
}), o('ArgList , Arg', function() {
478
return $1.concat($3);
479
}), o('ArgList OptComma TERMINATOR Arg', function() {
480
return $1.concat($4);
481
}), o('INDENT ArgList OptComma OUTDENT', function() {
482
return $2;
483
}), o('ArgList OptComma INDENT ArgList OptComma OUTDENT', function() {
484
return $1.concat($4);
485
})
486
],
487
Arg: [
488
o('Expression'), o('Splat'), o('...', function() {
489
return new Expansion;
490
})
491
],
492
SimpleArgs: [
493
o('Expression'), o('SimpleArgs , Expression', function() {
494
return [].concat($1, $3);
495
})
496
],
497
Try: [
498
o('TRY Block', function() {
499
return new Try($2);
500
}), o('TRY Block Catch', function() {
501
return new Try($2, $3[0], $3[1]);
502
}), o('TRY Block FINALLY Block', function() {
503
return new Try($2, null, null, $4);
504
}), o('TRY Block Catch FINALLY Block', function() {
505
return new Try($2, $3[0], $3[1], $5);
506
})
507
],
508
Catch: [
509
o('CATCH Identifier Block', function() {
510
return [$2, $3];
511
}), o('CATCH Object Block', function() {
512
return [LOC(2)(new Value($2)), $3];
513
}), o('CATCH Block', function() {
514
return [null, $2];
515
})
516
],
517
Throw: [
518
o('THROW Expression', function() {
519
return new Throw($2);
520
})
521
],
522
Parenthetical: [
523
o('( Body )', function() {
524
return new Parens($2);
525
}), o('( INDENT Body OUTDENT )', function() {
526
return new Parens($3);
527
})
528
],
529
WhileSource: [
530
o('WHILE Expression', function() {
531
return new While($2);
532
}), o('WHILE Expression WHEN Expression', function() {
533
return new While($2, {
534
guard: $4
535
});
536
}), o('UNTIL Expression', function() {
537
return new While($2, {
538
invert: true
539
});
540
}), o('UNTIL Expression WHEN Expression', function() {
541
return new While($2, {
542
invert: true,
543
guard: $4
544
});
545
})
546
],
547
While: [
548
o('WhileSource Block', function() {
549
return $1.addBody($2);
550
}), o('Statement WhileSource', function() {
551
return $2.addBody(LOC(1)(Block.wrap([$1])));
552
}), o('Expression WhileSource', function() {
553
return $2.addBody(LOC(1)(Block.wrap([$1])));
554
}), o('Loop', function() {
555
return $1;
556
})
557
],
558
Loop: [
559
o('LOOP Block', function() {
560
return new While(LOC(1)(new BooleanLiteral('true'))).addBody($2);
561
}), o('LOOP Expression', function() {
562
return new While(LOC(1)(new BooleanLiteral('true'))).addBody(LOC(2)(Block.wrap([$2])));
563
})
564
],
565
For: [
566
o('Statement ForBody', function() {
567
return new For($1, $2);
568
}), o('Expression ForBody', function() {
569
return new For($1, $2);
570
}), o('ForBody Block', function() {
571
return new For($2, $1);
572
})
573
],
574
ForBody: [
575
o('FOR Range', function() {
576
return {
577
source: LOC(2)(new Value($2))
578
};
579
}), o('FOR Range BY Expression', function() {
580
return {
581
source: LOC(2)(new Value($2)),
582
step: $4
583
};
584
}), o('ForStart ForSource', function() {
585
$2.own = $1.own;
586
$2.ownTag = $1.ownTag;
587
$2.name = $1[0];
588
$2.index = $1[1];
589
return $2;
590
})
591
],
592
ForStart: [
593
o('FOR ForVariables', function() {
594
return $2;
595
}), o('FOR OWN ForVariables', function() {
596
$3.own = true;
597
$3.ownTag = LOC(2)(new Literal($2));
598
return $3;
599
})
600
],
601
ForValue: [
602
o('Identifier'), o('ThisProperty'), o('Array', function() {
603
return new Value($1);
604
}), o('Object', function() {
605
return new Value($1);
606
})
607
],
608
ForVariables: [
609
o('ForValue', function() {
610
return [$1];
611
}), o('ForValue , ForValue', function() {
612
return [$1, $3];
613
})
614
],
615
ForSource: [
616
o('FORIN Expression', function() {
617
return {
618
source: $2
619
};
620
}), o('FOROF Expression', function() {
621
return {
622
source: $2,
623
object: true
624
};
625
}), o('FORIN Expression WHEN Expression', function() {
626
return {
627
source: $2,
628
guard: $4
629
};
630
}), o('FOROF Expression WHEN Expression', function() {
631
return {
632
source: $2,
633
guard: $4,
634
object: true
635
};
636
}), o('FORIN Expression BY Expression', function() {
637
return {
638
source: $2,
639
step: $4
640
};
641
}), o('FORIN Expression WHEN Expression BY Expression', function() {
642
return {
643
source: $2,
644
guard: $4,
645
step: $6
646
};
647
}), o('FORIN Expression BY Expression WHEN Expression', function() {
648
return {
649
source: $2,
650
step: $4,
651
guard: $6
652
};
653
}), o('FORFROM Expression', function() {
654
return {
655
source: $2,
656
from: true
657
};
658
}), o('FORFROM Expression WHEN Expression', function() {
659
return {
660
source: $2,
661
guard: $4,
662
from: true
663
};
664
})
665
],
666
Switch: [
667
o('SWITCH Expression INDENT Whens OUTDENT', function() {
668
return new Switch($2, $4);
669
}), o('SWITCH Expression INDENT Whens ELSE Block OUTDENT', function() {
670
return new Switch($2, $4, $6);
671
}), o('SWITCH INDENT Whens OUTDENT', function() {
672
return new Switch(null, $3);
673
}), o('SWITCH INDENT Whens ELSE Block OUTDENT', function() {
674
return new Switch(null, $3, $5);
675
})
676
],
677
Whens: [
678
o('When'), o('Whens When', function() {
679
return $1.concat($2);
680
})
681
],
682
When: [
683
o('LEADING_WHEN SimpleArgs Block', function() {
684
return [[$2, $3]];
685
}), o('LEADING_WHEN SimpleArgs Block TERMINATOR', function() {
686
return [[$2, $3]];
687
})
688
],
689
IfBlock: [
690
o('IF Expression Block', function() {
691
return new If($2, $3, {
692
type: $1
693
});
694
}), o('IfBlock ELSE IF Expression Block', function() {
695
return $1.addElse(LOC(3, 5)(new If($4, $5, {
696
type: $3
697
})));
698
})
699
],
700
If: [
701
o('IfBlock'), o('IfBlock ELSE Block', function() {
702
return $1.addElse($3);
703
}), o('Statement POST_IF Expression', function() {
704
return new If($3, LOC(1)(Block.wrap([$1])), {
705
type: $2,
706
statement: true
707
});
708
}), o('Expression POST_IF Expression', function() {
709
return new If($3, LOC(1)(Block.wrap([$1])), {
710
type: $2,
711
statement: true
712
});
713
})
714
],
715
Operation: [
716
o('UNARY Expression', function() {
717
return new Op($1, $2);
718
}), o('UNARY_MATH Expression', function() {
719
return new Op($1, $2);
720
}), o('- Expression', (function() {
721
return new Op('-', $2);
722
}), {
723
prec: 'UNARY_MATH'
724
}), o('+ Expression', (function() {
725
return new Op('+', $2);
726
}), {
727
prec: 'UNARY_MATH'
728
}), o('-- SimpleAssignable', function() {
729
return new Op('--', $2);
730
}), o('++ SimpleAssignable', function() {
731
return new Op('++', $2);
732
}), o('SimpleAssignable --', function() {
733
return new Op('--', $1, null, true);
734
}), o('SimpleAssignable ++', function() {
735
return new Op('++', $1, null, true);
736
}), o('Expression ?', function() {
737
return new Existence($1);
738
}), o('Expression + Expression', function() {
739
return new Op('+', $1, $3);
740
}), o('Expression - Expression', function() {
741
return new Op('-', $1, $3);
742
}), o('Expression MATH Expression', function() {
743
return new Op($2, $1, $3);
744
}), o('Expression ** Expression', function() {
745
return new Op($2, $1, $3);
746
}), o('Expression SHIFT Expression', function() {
747
return new Op($2, $1, $3);
748
}), o('Expression COMPARE Expression', function() {
749
return new Op($2, $1, $3);
750
}), o('Expression & Expression', function() {
751
return new Op($2, $1, $3);
752
}), o('Expression ^ Expression', function() {
753
return new Op($2, $1, $3);
754
}), o('Expression | Expression', function() {
755
return new Op($2, $1, $3);
756
}), o('Expression && Expression', function() {
757
return new Op($2, $1, $3);
758
}), o('Expression || Expression', function() {
759
return new Op($2, $1, $3);
760
}), o('Expression BIN? Expression', function() {
761
return new Op($2, $1, $3);
762
}), o('Expression RELATION Expression', function() {
763
if ($2.charAt(0) === '!') {
764
return new Op($2.slice(1), $1, $3).invert();
765
} else {
766
return new Op($2, $1, $3);
767
}
768
}), o('SimpleAssignable COMPOUND_ASSIGN Expression', function() {
769
return new Assign($1, $3, $2);
770
}), o('SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT', function() {
771
return new Assign($1, $4, $2);
772
}), o('SimpleAssignable COMPOUND_ASSIGN TERMINATOR Expression', function() {
773
return new Assign($1, $4, $2);
774
}), o('SimpleAssignable EXTENDS Expression', function() {
775
return new Extends($1, $3);
776
})
777
]
778
};
779
780
operators = [['left', '.', '?.', '::', '?::'], ['left', 'CALL_START', 'CALL_END'], ['nonassoc', '++', '--'], ['left', '?'], ['right', 'UNARY'], ['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'], ['left', 'POST_IF']];
781
782
tokens = [];
783
784
for (name in grammar) {
785
alternatives = grammar[name];
786
grammar[name] = (function() {
787
var i, j, len, len1, ref, results;
788
results = [];
789
for (i = 0, len = alternatives.length; i < len; i++) {
790
alt = alternatives[i];
791
ref = alt[0].split(' ');
792
for (j = 0, len1 = ref.length; j < len1; j++) {
793
token = ref[j];
794
if (!grammar[token]) {
795
tokens.push(token);
796
}
797
}
798
if (name === 'Root') {
799
alt[1] = "return " + alt[1];
800
}
801
results.push(alt);
802
}
803
return results;
804
})();
805
}
806
807
exports.parser = new Parser({
808
tokens: tokens.join(' '),
809
bnf: grammar,
810
operators: operators.reverse(),
811
startSymbol: 'Root'
812
});
813
814
}).call(this);
815
816